#ifndef VREYEVIEWWIDGET_H #define VREYEVIEWWIDGET_H #include #include #include #include #include #include #include #include #include #include #include #include "IVrEyeDevice.h" #include "IChessboardDetector.h" #include "VZNL_Common.h" /** * @brief 标定板检测回调数据 */ struct ChessboardDetectionData { bool detected; // 是否检测到 double x, y, z; // 标定板中心位置(相机坐标系,单位:mm) double nx, ny, nz; // 标定板法向量(单位向量) double rx, ry, rz; // 标定板姿态(欧拉角,度) }; /** * @brief VrEyeView 主窗口部件 * 用于显示相机图像并进行标定板检测 */ class VrEyeViewWidget : public QWidget { Q_OBJECT public: explicit VrEyeViewWidget(QWidget* parent = nullptr); ~VrEyeViewWidget() override; /** * @brief 设置检测回调函数 */ using DetectionCallback = std::function; void SetDetectionCallback(DetectionCallback callback); signals: /** * @brief 检测到标定板信号 */ void chessboardDetected(const ChessboardDetectionData& data); private slots: /** * @brief 连接相机 */ void onConnectCamera(); /** * @brief 断开相机 */ void onDisconnectCamera(); /** * @brief 开始采集 */ void onStartCapture(); /** * @brief 停止采集 */ void onStopCapture(); /** * @brief 检测标定板 */ void onDetectChessboard(); /** * @brief 加载左目图片 */ void onLoadLeftImage(); /** * @brief 加载右目图片 */ void onLoadRightImage(); /** * @brief 更新显示 */ void onUpdateDisplay(); private: /** * @brief 初始化界面 */ void setupUI(); /** * @brief 图像采集回调(SDK线程调用) */ static void OnImageCallback(SVzNLImageData* pLeftImage, SVzNLImageData* pRightImage, SVzNLImageData* pCenterImage, const SVzOutputFrameProps* pFrameProps, void* pUserData); /** * @brief 处理图像数据(SDK线程调用,需线程安全) */ void ProcessImageData(SVzNLImageData* pLeftImage, SVzNLImageData* pRightImage); /** * @brief 窗口大小变化事件,重新缩放图像 */ void resizeEvent(QResizeEvent* event) override; /** * @brief 更新左右目图像显示(保持比例,不拉伸) */ void UpdateImageDisplay(); /** * @brief 在图像上绘制角点 */ void DrawCorners(QImage& image, const std::vector& corners); // 相机设备 IVrEyeDevice* m_eyeDevice; // 标定板检测器 IChessboardDetector* m_detector; // UI 控件 - 左右目图像 QLabel* m_leftImageLabel; QLabel* m_rightImageLabel; QPushButton* m_btnConnect; QPushButton* m_btnDisconnect; QPushButton* m_btnStartCapture; QPushButton* m_btnStopCapture; QPushButton* m_btnDetect; // 相机参数控件 QLineEdit* m_editCameraIP; QSpinBox* m_sbExposure; QSpinBox* m_sbGain; // 标定板参数控件 QSpinBox* m_sbPatternWidth; QSpinBox* m_sbPatternHeight; QDoubleSpinBox* m_sbSquareSize; // 相机内参控件(3x3矩阵形式) // | fx 0 cx | // | 0 fy cy | // | 0 0 1 | QDoubleSpinBox* m_sbFx; // [0,0] QDoubleSpinBox* m_sbFy; // [1,1] QDoubleSpinBox* m_sbCx; // [0,2] QDoubleSpinBox* m_sbCy; // [1,2] // 检测选项 QCheckBox* m_cbAdaptiveThresh; QCheckBox* m_cbNormalizeImage; QCheckBox* m_cbAutoDetect; // 状态标签 QLabel* m_lblStatus; QLabel* m_lblDetectionResult; // 定时器 QTimer* m_displayTimer; // 状态 bool m_isConnected; bool m_isCapturing; // 左右目图像(加载或采集) QImage m_leftImage; QImage m_rightImage; // 实时采集图像缓存(SDK回调线程写,主线程读) std::mutex m_captureMutex; QImage m_captureLeft; QImage m_captureRight; bool m_hasNewImage; // 检测结果 ChessboardDetectionData m_lastDetection; std::vector m_lastLeftCorners; std::vector m_lastRightCorners; // 回调函数 DetectionCallback m_detectionCallback; }; #endif // VREYEVIEWWIDGET_H