2026-03-28 10:49:55 +08:00
|
|
|
|
#ifndef IVRCONFIG_H
|
|
|
|
|
|
#define IVRCONFIG_H
|
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
|
#include <cstdint>
|
2026-03-28 10:49:55 +08:00
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
2026-04-15 11:08:31 +08:00
|
|
|
|
|
2026-04-10 20:02:57 +08:00
|
|
|
|
#include <QString>
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
|
|
#include "VrCommonConfig.h"
|
2026-04-15 11:08:31 +08:00
|
|
|
|
#include "VrHandEyeCalibConfig.h"
|
2026-03-28 10:49:55 +08:00
|
|
|
|
|
|
|
|
|
|
struct VrScrewParam
|
|
|
|
|
|
{
|
2026-04-15 11:08:31 +08:00
|
|
|
|
double rodDiameter = 10.0;
|
|
|
|
|
|
bool isHorizonScan = true;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VrCornerParam
|
|
|
|
|
|
{
|
|
|
|
|
|
double minEndingGap = 20.0;
|
|
|
|
|
|
double minEndingGap_z = 5.0;
|
|
|
|
|
|
double scale = 2.5;
|
2026-05-17 00:38:31 +08:00
|
|
|
|
double cornerTh = 30.0;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
double jumpCornerTh_1 = 15.0;
|
|
|
|
|
|
double jumpCornerTh_2 = 60.0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VrOutlierFilterParam
|
|
|
|
|
|
{
|
2026-04-15 11:08:31 +08:00
|
|
|
|
double continuityTh = 20.0;
|
|
|
|
|
|
double outlierTh = 5.0;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VrTreeGrowParam
|
|
|
|
|
|
{
|
2026-05-17 00:38:31 +08:00
|
|
|
|
double yDeviation_max = 5.0;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
double zDeviation_max = 50.0;
|
|
|
|
|
|
int maxLineSkipNum = 10;
|
2026-05-17 00:38:31 +08:00
|
|
|
|
double maxSkipDistance = 30.0;
|
|
|
|
|
|
double minLTypeTreeLen = 50.0;
|
|
|
|
|
|
double minVTypeTreeLen = 50.0;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct VrAlgorithmParams
|
|
|
|
|
|
{
|
|
|
|
|
|
VrScrewParam screwParam;
|
|
|
|
|
|
VrCornerParam cornerParam;
|
|
|
|
|
|
VrOutlierFilterParam filterParam;
|
|
|
|
|
|
VrTreeGrowParam growParam;
|
2026-05-23 23:38:49 +08:00
|
|
|
|
// 多相机平面校准:在 ScrewPosition 中作为「相机级」共享配置,
|
|
|
|
|
|
// 不随检测对象切换,因此不属于 VrDetectionConfigSet。
|
2026-03-28 10:49:55 +08:00
|
|
|
|
VrPlaneCalibParam planeCalibParam;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-23 23:38:49 +08:00
|
|
|
|
// 检测对象类型:螺杆 / 工具盘
|
|
|
|
|
|
enum DetectionType {
|
|
|
|
|
|
DETECTION_TYPE_SCREW = 1,
|
|
|
|
|
|
DETECTION_TYPE_TOOL_DISK = 2
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 单个 (相机, 检测对象) 组合的完整配置
|
|
|
|
|
|
*
|
|
|
|
|
|
* 每台相机对每种检测对象都有独立的手眼矩阵与算法参数。
|
|
|
|
|
|
* 双相机 × 两种对象 = 4 个 set。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 注意:handEyeMatrix.cameraIndex 应与外层 cameraIndex 保持一致;
|
|
|
|
|
|
* algorithmParams.planeCalibParam 在本结构中不使用——平面校准是相机级共享配置,
|
|
|
|
|
|
* 统一存放在 ConfigResult::algorithmParams.planeCalibParam 中。
|
|
|
|
|
|
*/
|
|
|
|
|
|
struct VrDetectionConfigSet
|
|
|
|
|
|
{
|
|
|
|
|
|
int cameraIndex = 1;
|
|
|
|
|
|
DetectionType detectionType = DETECTION_TYPE_SCREW;
|
|
|
|
|
|
VrHandEyeCalibMatrix handEyeMatrix;
|
|
|
|
|
|
VrAlgorithmParams algorithmParams;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-28 10:49:55 +08:00
|
|
|
|
struct ConfigResult
|
|
|
|
|
|
{
|
2026-04-15 11:08:31 +08:00
|
|
|
|
std::vector<DeviceInfo> cameraList;
|
|
|
|
|
|
VrDebugParam debugParam;
|
|
|
|
|
|
SerialConfig serialConfig;
|
|
|
|
|
|
uint16_t tcpPort = 7800;
|
2026-04-17 10:18:03 +08:00
|
|
|
|
int poseOutputOrder = 0;
|
2026-04-15 11:08:31 +08:00
|
|
|
|
int byteOrder = 0;
|
2026-05-23 23:38:49 +08:00
|
|
|
|
|
|
|
|
|
|
// 共享算法参数:仅 planeCalibParam 字段在此结构中被使用,
|
|
|
|
|
|
// 其余 (screw/corner/filter/grow) 字段保留以兼容 BaseConfigManager 头文件中的
|
|
|
|
|
|
// GetAlgorithmParams()/UpdateAlgorithmParams() 接口,对 ScrewPosition 实际无效。
|
2026-04-15 11:08:31 +08:00
|
|
|
|
VrAlgorithmParams algorithmParams;
|
|
|
|
|
|
|
2026-05-23 23:38:49 +08:00
|
|
|
|
// 4 套 (相机, 对象) 配置——本应用检测时使用的真实数据源
|
|
|
|
|
|
std::vector<VrDetectionConfigSet> detectionConfigList;
|
|
|
|
|
|
|
|
|
|
|
|
// —— 辅助查询 ——
|
|
|
|
|
|
const VrDetectionConfigSet* FindDetectionConfig(int cameraIndex, DetectionType type) const
|
|
|
|
|
|
{
|
|
|
|
|
|
for (const auto& item : detectionConfigList) {
|
|
|
|
|
|
if (item.cameraIndex == cameraIndex && item.detectionType == type) {
|
|
|
|
|
|
return &item;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VrDetectionConfigSet* FindDetectionConfig(int cameraIndex, DetectionType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto& item : detectionConfigList) {
|
|
|
|
|
|
if (item.cameraIndex == cameraIndex && item.detectionType == type) {
|
|
|
|
|
|
return &item;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 确保存在某 (camera, type) 槽位,不存在则插入默认值
|
|
|
|
|
|
VrDetectionConfigSet& EnsureDetectionConfig(int cameraIndex, DetectionType type)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (auto* p = FindDetectionConfig(cameraIndex, type)) {
|
|
|
|
|
|
return *p;
|
|
|
|
|
|
}
|
|
|
|
|
|
VrDetectionConfigSet item;
|
|
|
|
|
|
item.cameraIndex = cameraIndex;
|
|
|
|
|
|
item.detectionType = type;
|
|
|
|
|
|
item.handEyeMatrix.cameraIndex = cameraIndex;
|
|
|
|
|
|
detectionConfigList.push_back(item);
|
|
|
|
|
|
return detectionConfigList.back();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-15 11:08:31 +08:00
|
|
|
|
ConfigResult& operator=(const ConfigResult& other)
|
|
|
|
|
|
{
|
2026-03-28 10:49:55 +08:00
|
|
|
|
if (this != &other) {
|
|
|
|
|
|
cameraList = other.cameraList;
|
|
|
|
|
|
debugParam = other.debugParam;
|
|
|
|
|
|
serialConfig = other.serialConfig;
|
|
|
|
|
|
tcpPort = other.tcpPort;
|
2026-04-17 10:18:03 +08:00
|
|
|
|
poseOutputOrder = other.poseOutputOrder;
|
2026-04-15 11:08:31 +08:00
|
|
|
|
byteOrder = other.byteOrder;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
algorithmParams = other.algorithmParams;
|
2026-05-23 23:38:49 +08:00
|
|
|
|
detectionConfigList = other.detectionConfigList;
|
2026-03-28 10:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConfigResult(const ConfigResult& other)
|
|
|
|
|
|
: cameraList(other.cameraList)
|
|
|
|
|
|
, debugParam(other.debugParam)
|
|
|
|
|
|
, serialConfig(other.serialConfig)
|
|
|
|
|
|
, tcpPort(other.tcpPort)
|
2026-04-17 10:18:03 +08:00
|
|
|
|
, poseOutputOrder(other.poseOutputOrder)
|
2026-04-15 11:08:31 +08:00
|
|
|
|
, byteOrder(other.byteOrder)
|
|
|
|
|
|
, algorithmParams(other.algorithmParams)
|
2026-05-23 23:38:49 +08:00
|
|
|
|
, detectionConfigList(other.detectionConfigList)
|
2026-04-15 11:08:31 +08:00
|
|
|
|
{
|
2026-03-28 10:49:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConfigResult() = default;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum LoadConfigErrorCode
|
|
|
|
|
|
{
|
2026-04-15 11:08:31 +08:00
|
|
|
|
LOAD_CONFIG_SUCCESS = 0,
|
|
|
|
|
|
LOAD_CONFIG_FILE_NOT_FOUND = -1,
|
|
|
|
|
|
LOAD_CONFIG_PARSE_ERROR = -2,
|
|
|
|
|
|
LOAD_CONFIG_INVALID_FORMAT = -3,
|
|
|
|
|
|
LOAD_CONFIG_UNKNOWN_ERROR = -99
|
2026-03-28 10:49:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IVrConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
virtual ~IVrConfig() {}
|
|
|
|
|
|
|
|
|
|
|
|
static bool CreateInstance(IVrConfig** ppVrConfig);
|
|
|
|
|
|
|
|
|
|
|
|
virtual int LoadConfig(const std::string& filePath, ConfigResult& configResult) = 0;
|
|
|
|
|
|
virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0;
|
|
|
|
|
|
virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-10 20:02:57 +08:00
|
|
|
|
struct ScrewDetectOutput {
|
2026-04-15 11:08:31 +08:00
|
|
|
|
double x = 0.0;
|
|
|
|
|
|
double y = 0.0;
|
|
|
|
|
|
double z = 0.0;
|
|
|
|
|
|
double roll = 0.0;
|
|
|
|
|
|
double pitch = 0.0;
|
|
|
|
|
|
double yaw = 0.0;
|
2026-04-10 20:02:57 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct ToolDiskDetectOutput {
|
2026-04-15 11:08:31 +08:00
|
|
|
|
double x = 0.0;
|
|
|
|
|
|
double y = 0.0;
|
|
|
|
|
|
double z = 0.0;
|
|
|
|
|
|
double roll = 0.0;
|
|
|
|
|
|
double pitch = 0.0;
|
|
|
|
|
|
double yaw = 0.0;
|
2026-04-10 20:02:57 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct ProtocolDetectionOutput {
|
2026-04-15 11:08:31 +08:00
|
|
|
|
DetectionType type = DETECTION_TYPE_SCREW;
|
|
|
|
|
|
bool success = true;
|
|
|
|
|
|
int errorCode = 0;
|
|
|
|
|
|
QString message;
|
|
|
|
|
|
int cameraIndex = 0;
|
|
|
|
|
|
qint64 timestamp = 0;
|
2026-04-10 20:02:57 +08:00
|
|
|
|
std::vector<ScrewDetectOutput> screwOutputs;
|
|
|
|
|
|
std::vector<ToolDiskDetectOutput> toolDiskOutputs;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-28 10:49:55 +08:00
|
|
|
|
#endif // IVRCONFIG_H
|