GrabBag/Tools/CalibView/Inc/BatchVerifyDialog.h

177 lines
4.0 KiB
C++

#ifndef BATCHVERIFYDIALOG_H
#define BATCHVERIFYDIALOG_H
#include <QDialog>
#include <QTableWidget>
#include <QPushButton>
#include <QProgressBar>
#include <QLabel>
#include <QTextEdit>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QComboBox>
#include <vector>
#include <QString>
#include "IHandEyeCalib.h"
class IChessboardDetector;
class IHandEyeCalib;
/**
* @brief 批量验证数据项
*/
struct BatchVerifyItem
{
QString leftImagePath; // 左目图像路径
QString rightImagePath; // 右目图像路径
double robotX, robotY, robotZ; // 机械臂坐标
double robotRx, robotRy, robotRz; // 机械臂姿态(欧拉角,度)
double robotQw, robotQx, robotQy, robotQz; // 机械臂姿态(四元数)
// 检测结果
bool detected;
double camX, camY, camZ; // 相机检测到的坐标
double camRx, camRy, camRz; // 相机检测到的姿态
// 验证结果
double errorX, errorY, errorZ; // 误差
double errorTotal; // 总误差
BatchVerifyItem()
: robotX(0), robotY(0), robotZ(0)
, robotRx(0), robotRy(0), robotRz(0)
, robotQw(1), robotQx(0), robotQy(0), robotQz(0)
, detected(false)
, camX(0), camY(0), camZ(0)
, camRx(0), camRy(0), camRz(0)
, errorX(0), errorY(0), errorZ(0)
, errorTotal(0) {}
};
/**
* @brief 批量验证对话框
* 用于批量加载图像和机械臂坐标,进行标定验证
*/
class BatchVerifyDialog : public QDialog
{
Q_OBJECT
public:
explicit BatchVerifyDialog(IChessboardDetector* detector,
IHandEyeCalib* calib,
QWidget* parent = nullptr);
~BatchVerifyDialog() override;
/**
* @brief 获取验证数据列表
*/
const std::vector<BatchVerifyItem>& getVerifyItems() const { return m_items; }
private slots:
/**
* @brief 选择数据目录
*/
void onSelectDirectory();
/**
* @brief 开始批量验证
*/
void onStartVerify();
/**
* @brief 停止验证
*/
void onStopVerify();
/**
* @brief 导出结果
*/
void onExportResults();
private:
/**
* @brief 初始化界面
*/
void setupUI();
/**
* @brief 扫描目录加载数据
*/
bool scanDirectory(const QString& dirPath);
/**
* @brief 加载机械臂坐标文件
*/
bool loadRobotCoordinates(const QString& filePath);
/**
* @brief 检测单个图像对
*/
bool detectImagePair(BatchVerifyItem& item);
/**
* @brief 计算验证误差(直接比较模式)
*/
void calculateError(BatchVerifyItem& item);
/**
* @brief 执行 Eye-In-Hand 标定并计算一致性误差
*/
void calculateEyeInHandErrors();
/**
* @brief 四元数转旋转矩阵
*/
static void quatToRotationMatrix(double qw, double qx, double qy, double qz,
HECRotationMatrix& R);
/**
* @brief 更新表格显示
*/
void updateTable();
/**
* @brief 追加日志
*/
void appendLog(const QString& message);
// 检测器和标定实例
IChessboardDetector* m_detector;
IHandEyeCalib* m_calib;
// UI 控件
QLabel* m_lblDirectory;
QPushButton* m_btnSelectDir;
QPushButton* m_btnStartVerify;
QPushButton* m_btnStopVerify;
QPushButton* m_btnExport;
QProgressBar* m_progressBar;
QTableWidget* m_tableResults;
QTextEdit* m_logEdit;
// 标定板参数
QSpinBox* m_sbPatternWidth;
QSpinBox* m_sbPatternHeight;
QDoubleSpinBox* m_sbSquareSize;
// 相机内参
QDoubleSpinBox* m_sbFx;
QDoubleSpinBox* m_sbFy;
QDoubleSpinBox* m_sbCx;
QDoubleSpinBox* m_sbCy;
// 标定类型选择
QComboBox* m_cbCalibType;
// 标定结果
HECCalibResult m_calibResult;
bool m_calibSuccess;
// 数据
std::vector<BatchVerifyItem> m_items;
QString m_currentDirectory;
bool m_isVerifying;
};
#endif // BATCHVERIFYDIALOG_H