feat:通过三维转二维绘制到结果图像中
This commit is contained in:
parent
ed91554bdb
commit
3e6d0724dc
@ -13,6 +13,7 @@
|
||||
#include <string>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QImage>
|
||||
#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(); }
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
#include <QCoreApplication>
|
||||
#include <QPainter>
|
||||
#include <QPen>
|
||||
#include <QPolygon>
|
||||
#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<const void*>(points3D));
|
||||
return;
|
||||
}
|
||||
|
||||
const int deviceIndex = cameraIndex - 1;
|
||||
IVrEyeDevice* device = nullptr;
|
||||
if (deviceIndex >= 0 && deviceIndex < static_cast<int>(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<int>(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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user