From 3e6d0724dc5f634e97ac57cf13664d89916ac945 Mon Sep 17 00:00:00 2001 From: YangSn Date: Fri, 28 Aug 2026 09:30:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E9=80=9A=E8=BF=87=E4=B8=89=E7=BB=B4?= =?UTF-8?q?=E8=BD=AC=E4=BA=8C=E7=BB=B4=E7=BB=98=E5=88=B6=E5=88=B0=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=9B=BE=E5=83=8F=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppUtils/AppCommon/Inc/BasePresenter.h | 9 ++++ AppUtils/AppCommon/Src/BasePresenter.cpp | 65 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/AppUtils/AppCommon/Inc/BasePresenter.h b/AppUtils/AppCommon/Inc/BasePresenter.h index c3f6e9e9..38b3b9b8 100644 --- a/AppUtils/AppCommon/Inc/BasePresenter.h +++ b/AppUtils/AppCommon/Inc/BasePresenter.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "IVrEyeDevice.h" #include "VZNL_Types.h" #include "VrCommonConfig.h" // 包含公共配置结构体 @@ -636,6 +637,14 @@ private slots: void OnCameraReconnectTimer(); protected: + // Project four 3D vertices into a camera image and draw a closed contour + // in vertex order (0->1->2->3->0). + void DrawProjectedBin(QImage& image, + int cameraIndex, + const SVzNL3DPoint points3D[4], + int imageOriginX = 0, + int imageOriginY = 0) const; + // 派生析构可在释放自身回调资源前停止基类异步设施。 void StopCameraReconnectForDerivedTeardown() { StopCameraReconnectTimer(); } void StopBaseModbusServer() { StopModbusServer(); } diff --git a/AppUtils/AppCommon/Src/BasePresenter.cpp b/AppUtils/AppCommon/Src/BasePresenter.cpp index 12af9692..33fe9f80 100644 --- a/AppUtils/AppCommon/Src/BasePresenter.cpp +++ b/AppUtils/AppCommon/Src/BasePresenter.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "PathManager.h" #include "IYModbusTCPServer.h" @@ -32,6 +35,68 @@ QString EnsureDebugOutputPath(const VrDebugParam& debugParam) } // namespace +void BasePresenter::DrawProjectedBin(QImage& image, + int cameraIndex, + const SVzNL3DPoint points3D[4], + int imageOriginX, + int imageOriginY) const +{ + if (image.isNull() || !points3D) { + LOG_WARNING("[2D] skip bin drawing: imageNull=%d points=%p\n", + image.isNull() ? 1 : 0, + static_cast(points3D)); + return; + } + + const int deviceIndex = cameraIndex - 1; + IVrEyeDevice* device = nullptr; + if (deviceIndex >= 0 && deviceIndex < static_cast(m_vrEyeDeviceList.size())) { + device = m_vrEyeDeviceList[deviceIndex].second; + } + if (!device) { + LOG_WARNING("[2D] skip bin drawing: camera handle is unavailable for " + "the detection camera, cameraIndex=%d deviceIndex=%d deviceCount=%d\n", + cameraIndex, deviceIndex, + static_cast(m_vrEyeDeviceList.size())); + return; + } + + SVzNL2DPoint leftPoints[4] = {}; + SVzNL2DPoint rightPoints[4] = {}; + const int result = device->Project3DPointsToEyeImages( + points3D, leftPoints, rightPoints, 4); + if (result != SUCCESS) { + LOG_WARNING("Failed to project bin vertices to the left image: %d\n", result); + return; + } + + LOG_INFO("[2D] projected bin vertices: (%d,%d),(%d,%d),(%d,%d),(%d,%d), origin=(%d,%d)\n", + leftPoints[0].x, leftPoints[0].y, + leftPoints[1].x, leftPoints[1].y, + leftPoints[2].x, leftPoints[2].y, + leftPoints[3].x, leftPoints[3].y, + imageOriginX, imageOriginY); + + QPolygon polygon; + for (int index = 0; index < 4; ++index) { + polygon << QPoint(leftPoints[index].x - imageOriginX, + leftPoints[index].y - imageOriginY); + } + if (polygon.boundingRect().isEmpty()) { + LOG_WARNING("Projected bin polygon is degenerate; skip drawing\n"); + return; + } + + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing); + QPen pen(QColor(30, 110, 255)); + pen.setWidth(4); + painter.setPen(pen); + for (int index = 0; index < 4; ++index) { + painter.drawLine(polygon[index], polygon[(index + 1) % 4]); + } +} + BasePresenter::BasePresenter(QObject *parent) : QObject(parent) , m_currentCameraIndex(0)