184 lines
4.1 KiB
C++
184 lines
4.1 KiB
C++
#ifndef VREYEVIEWWIDGET_H
|
||
#define VREYEVIEWWIDGET_H
|
||
|
||
#include <QWidget>
|
||
#include <QLabel>
|
||
#include <QPushButton>
|
||
#include <QSpinBox>
|
||
#include <QDoubleSpinBox>
|
||
#include <QCheckBox>
|
||
#include <QTimer>
|
||
#include <QImage>
|
||
#include <QLineEdit>
|
||
#include <mutex>
|
||
#include <memory>
|
||
|
||
#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(const ChessboardDetectionData&)>;
|
||
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 onLoadImage();
|
||
|
||
/**
|
||
* @brief 更新显示
|
||
*/
|
||
void onUpdateDisplay();
|
||
|
||
private:
|
||
/**
|
||
* @brief 初始化界面
|
||
*/
|
||
void setupUI();
|
||
|
||
/**
|
||
* @brief 相机数据回调
|
||
*/
|
||
static void OnLaserDataCallback(EVzResultDataType eDataType,
|
||
SVzLaserLineData* pLaserData,
|
||
void* pUserData);
|
||
|
||
/**
|
||
* @brief 处理激光数据
|
||
*/
|
||
void ProcessLaserData(EVzResultDataType eDataType, SVzLaserLineData* pLaserData);
|
||
|
||
/**
|
||
* @brief 更新左右目图像显示(保持比例,不拉伸)
|
||
*/
|
||
void UpdateImageDisplay();
|
||
|
||
/**
|
||
* @brief 在图像上绘制角点
|
||
*/
|
||
void DrawCorners(QImage& image, const std::vector<Point2D>& 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;
|
||
|
||
// 相机内参控件
|
||
QDoubleSpinBox* m_sbFx;
|
||
QDoubleSpinBox* m_sbFy;
|
||
QDoubleSpinBox* m_sbCx;
|
||
QDoubleSpinBox* m_sbCy;
|
||
|
||
// 检测选项
|
||
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;
|
||
std::vector<unsigned char> m_imageBuffer;
|
||
int m_imageWidth;
|
||
int m_imageHeight;
|
||
bool m_hasNewImage;
|
||
|
||
// 检测结果
|
||
ChessboardDetectionData m_lastDetection;
|
||
std::vector<Point2D> m_lastLeftCorners;
|
||
std::vector<Point2D> m_lastRightCorners;
|
||
|
||
// 回调函数
|
||
DetectionCallback m_detectionCallback;
|
||
};
|
||
|
||
#endif // VREYEVIEWWIDGET_H
|