357 lines
8.9 KiB
C++
357 lines
8.9 KiB
C++
#ifndef IVRCONFIG_H
|
||
#define IVRCONFIG_H
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <utility>
|
||
#include <algorithm>
|
||
|
||
// 包含公共配置结构体
|
||
#include "VrCommonConfig.h"
|
||
|
||
/**
|
||
* @brief 项目类型枚举
|
||
*/
|
||
enum class ProjectType
|
||
{
|
||
GrabBag = 0, // 抓包
|
||
DirectBag = 1, // 带方向的编织袋
|
||
};
|
||
|
||
/**
|
||
* @brief 项目类型字符串转换函数
|
||
*/
|
||
inline std::string ProjectTypeToString(ProjectType type)
|
||
{
|
||
switch (type) {
|
||
case ProjectType::GrabBag:
|
||
return "GrabBag";
|
||
case ProjectType::DirectBag:
|
||
return "DirectBag";
|
||
default:
|
||
return "Unknown";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief 字符串转项目类型函数
|
||
*/
|
||
inline ProjectType StringToProjectType(const std::string& str)
|
||
{
|
||
if (str == "GrabBag" || str == "0") {
|
||
return ProjectType::GrabBag;
|
||
} else if (str == "DirectBag" || str == "1") {
|
||
return ProjectType::DirectBag;
|
||
} else {
|
||
return ProjectType::GrabBag; // 默认返回抓包
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief TCP服务器配置信息
|
||
*/
|
||
struct TcpServerConfig
|
||
{
|
||
std::string ipAddress = "127.0.0.1"; // 服务器IP地址
|
||
int port = 6800; // 服务器端口
|
||
};
|
||
|
||
/**
|
||
* @brief 编织袋参数
|
||
*/
|
||
struct VrBagParam
|
||
{
|
||
double bagL = 650.0;
|
||
double bagW = 450.0;
|
||
double bagH = 160.0;
|
||
};
|
||
|
||
/**
|
||
* @brief 垛参数
|
||
*/
|
||
struct VrPileParam
|
||
{
|
||
double pileL = 1300.0;
|
||
double pileW = 900.0;
|
||
double pileH = 800.0;
|
||
};
|
||
|
||
/**
|
||
* @brief 离群点滤波参数
|
||
*/
|
||
struct VrOutlierFilterParam
|
||
{
|
||
double continuityTh = 20.0;
|
||
int outlierTh = 5;
|
||
};
|
||
|
||
/**
|
||
* @brief 角点参数
|
||
*/
|
||
struct VrCornerParam
|
||
{
|
||
double minEndingGap = 20.0;
|
||
double minEndingGap_z = 40.0;
|
||
double scale = 50.0;
|
||
double cornerTh = 45.0;
|
||
double jumpCornerTh_1 = 60.0;
|
||
double jumpCornerTh_2 = 15.0;
|
||
};
|
||
|
||
/**
|
||
* @brief 斜率参数
|
||
*/
|
||
struct VrSlopeParam
|
||
{
|
||
double LSlopeZWin = 10.0;
|
||
double validSlopeH = 10.0;
|
||
double minLJumpH = 20.0;
|
||
double minEndingGap = 20.0;
|
||
};
|
||
|
||
/**
|
||
* @brief V特征参数
|
||
*/
|
||
struct VrVFeatureParam
|
||
{
|
||
double valleyMinH = 10.0;
|
||
double valleyMaxW = 80.0;
|
||
};
|
||
|
||
/**
|
||
* @brief 树生长参数
|
||
*/
|
||
struct VrTreeGrowParam
|
||
{
|
||
double yDeviation_max = 20.0;
|
||
double zDeviation_max = 80.0;
|
||
int maxLineSkipNum = 5;
|
||
double maxSkipDistance = 20.0;
|
||
double minLTypeTreeLen = 50.0;
|
||
double minVTypeTreeLen = 50.0;
|
||
};
|
||
|
||
/**
|
||
* @brief HSV颜色比较参数
|
||
*/
|
||
struct VrHsvCmpParam
|
||
{
|
||
double hueTh = 15.0;
|
||
double saturateTh = 120.0;
|
||
double FBVldPtRatioTh = 0.075;
|
||
bool frontVldPtGreater = true;
|
||
bool front_upVldPtGreater = false;
|
||
bool back_upVldPtGreater = true;
|
||
};
|
||
|
||
/**
|
||
* @brief RGB颜色模式
|
||
*/
|
||
struct VrRgbColorPattern
|
||
{
|
||
int r = 36;
|
||
int g = 165;
|
||
int b = 208;
|
||
};
|
||
|
||
/**
|
||
* @brief 颜色模板参数
|
||
*/
|
||
#define RGN_HIST_SIZE 16
|
||
struct VrColorTemplateParam
|
||
{
|
||
double frontColorTemplate[RGN_HIST_SIZE] = {0.0}; // 正面颜色模板
|
||
double backColorTemplate[RGN_HIST_SIZE] = {0.0}; // 反面颜色模板
|
||
};
|
||
|
||
/**
|
||
* @brief 单个相机的手眼标定参数(4x4变换矩阵)
|
||
*/
|
||
struct VrHandEyeCalibParam
|
||
{
|
||
int cameraIndex = 1; // 相机索引(1-based)
|
||
std::string cameraName = ""; // 相机名称
|
||
double transformMatrix[16] = { // 4x4变换矩阵(默认单位矩阵)
|
||
1.0, 0.0, 0.0, 0.0,
|
||
0.0, 1.0, 0.0, 0.0,
|
||
0.0, 0.0, 1.0, 0.0,
|
||
0.0, 0.0, 0.0, 1.0
|
||
};
|
||
bool isCalibrated = false; // 是否已经校准
|
||
};
|
||
|
||
/**
|
||
* @brief 手眼标定参数集合(支持多相机)
|
||
*/
|
||
struct VrHandEyeCalibParams
|
||
{
|
||
std::vector<VrHandEyeCalibParam> cameraHandEyeParams;
|
||
|
||
VrHandEyeCalibParam* GetCameraHandEyeParam(int cameraIndex);
|
||
const VrHandEyeCalibParam* GetCameraHandEyeParam(int cameraIndex) const;
|
||
void SetCameraHandEyeParam(const VrHandEyeCalibParam& param);
|
||
void RemoveCameraHandEyeParam(int cameraIndex);
|
||
};
|
||
|
||
/**
|
||
* @brief 相机参数(用于工作点和包裹类型)
|
||
*/
|
||
struct VrCameraParams
|
||
{
|
||
int cameraIndex = 1; // 相机索引
|
||
double exposure = 100.0; // 曝光时间 (微秒)
|
||
double gain = 1.0; // 增益值
|
||
double frameRate = 500.0; // 帧率
|
||
double swingSpeed = 30.0; // 摆动速度
|
||
double swingStartAngle = 0.0; // 开始角度
|
||
double swingStopAngle = 76.0; // 结束角度
|
||
};
|
||
|
||
// 前向声明
|
||
struct PackageTypeConfig;
|
||
struct CameraConfig;
|
||
struct WorkPositionConfig;
|
||
|
||
/**
|
||
* @brief 相机配置(工作点下的相机)
|
||
*/
|
||
struct CameraConfig
|
||
{
|
||
std::string id;
|
||
std::string cameraName;
|
||
int cameraIndex = 1;
|
||
VrCameraPlaneCalibParam planeCalibParam;
|
||
VrHandEyeCalibParam handEyeCalibParam;
|
||
std::vector<PackageTypeConfig> packages;
|
||
std::string defaultPackageId;
|
||
|
||
PackageTypeConfig* GetPackage(const std::string& packageId);
|
||
const PackageTypeConfig* GetPackage(const std::string& packageId) const;
|
||
PackageTypeConfig* GetDefaultPackage();
|
||
const PackageTypeConfig* GetDefaultPackage() const;
|
||
};
|
||
|
||
/**
|
||
* @brief 工作点配置
|
||
*/
|
||
struct WorkPositionConfig
|
||
{
|
||
std::string id;
|
||
std::string name;
|
||
std::vector<CameraConfig> cameras;
|
||
std::string defaultCameraId;
|
||
|
||
CameraConfig* GetCamera(const std::string& cameraId);
|
||
const CameraConfig* GetCamera(const std::string& cameraId) const;
|
||
CameraConfig* GetCameraByIndex(int cameraIndex);
|
||
const CameraConfig* GetCameraByIndex(int cameraIndex) const;
|
||
CameraConfig* GetDefaultCamera();
|
||
const CameraConfig* GetDefaultCamera() const;
|
||
};
|
||
|
||
/**
|
||
* @brief 包裹类型配置
|
||
*/
|
||
struct PackageTypeConfig
|
||
{
|
||
std::string id;
|
||
std::string name;
|
||
VrBagParam bagParam;
|
||
VrPileParam pileParam;
|
||
std::vector<VrCameraParams> cameraParams;
|
||
|
||
VrCameraParams* GetCameraParam(int cameraIndex);
|
||
const VrCameraParams* GetCameraParam(int cameraIndex) const;
|
||
void SetCameraParam(const VrCameraParams& param);
|
||
};
|
||
|
||
// 成员函数声明在 VrConfig.cpp 中实现
|
||
|
||
/**
|
||
* @brief 算法参数配置结构
|
||
*/
|
||
struct VrAlgorithmParams
|
||
{
|
||
VrBagParam bagParam;
|
||
VrPileParam pileParam;
|
||
VrOutlierFilterParam filterParam;
|
||
VrCornerParam cornerParam;
|
||
VrSlopeParam slopeParam;
|
||
VrVFeatureParam valleyParam;
|
||
VrTreeGrowParam growParam;
|
||
VrPlaneCalibParam planeCalibParam;
|
||
VrHsvCmpParam hsvCmpParam;
|
||
VrRgbColorPattern rgbColorPattern;
|
||
VrColorTemplateParam colorTemplateParam;
|
||
int supportRotate = 1;
|
||
};
|
||
|
||
/**
|
||
* @brief 配置加载结果
|
||
*/
|
||
struct ConfigResult
|
||
{
|
||
std::vector<DeviceInfo> cameraList;
|
||
std::vector<DeviceInfo> deviceList;
|
||
VrAlgorithmParams algorithmParams;
|
||
VrDebugParam debugParam;
|
||
SerialConfig serialConfig;
|
||
TcpServerConfig tcpServerConfig;
|
||
ProjectType projectType = ProjectType::GrabBag;
|
||
std::vector<WorkPositionConfig> workPositions;
|
||
std::string defaultWorkPositionId;
|
||
std::string defaultCameraId;
|
||
std::string defaultPackageId;
|
||
|
||
CameraConfig* GetDefaultCamera();
|
||
const CameraConfig* GetDefaultCamera() const;
|
||
PackageTypeConfig* GetDefaultPackage();
|
||
const PackageTypeConfig* GetDefaultPackage() const;
|
||
VrCameraParams GetEffectiveCameraParam(int cameraIndex) const;
|
||
VrBagParam GetEffectiveBagParam() const;
|
||
VrPileParam GetEffectivePileParam() const;
|
||
const VrCameraPlaneCalibParam* GetEffectivePlaneCalibParam(int cameraIndex) const;
|
||
const VrHandEyeCalibParam* GetEffectiveHandEyeCalibParam(int cameraIndex) const;
|
||
};
|
||
|
||
/**
|
||
* @brief VrConfig接口类
|
||
*/
|
||
class IVrConfig
|
||
{
|
||
public:
|
||
/**
|
||
* @brief 虚析构函数
|
||
*/
|
||
virtual ~IVrConfig() {}
|
||
|
||
/**
|
||
* @brief 创建实例
|
||
* @return 实例
|
||
*/
|
||
static bool CreateInstance(IVrConfig** ppVrConfig);
|
||
|
||
/**
|
||
* @brief 加载配置文件
|
||
* @param filePath 配置文件路径
|
||
* @return 加载的配置结果
|
||
*/
|
||
virtual ConfigResult LoadConfig(const std::string& filePath) = 0;
|
||
|
||
/**
|
||
* @brief 保存配置文件
|
||
* @param filePath 配置文件路径
|
||
* @param configResult 配置结果
|
||
* @return 是否保存成功
|
||
*/
|
||
virtual bool SaveConfig(const std::string& filePath, ConfigResult& configResult) = 0;
|
||
|
||
/**
|
||
* @brief 设置配置改变通知回调
|
||
* @param notify 通知接口指针
|
||
*/
|
||
virtual void SetConfigChangeNotify(IVrConfigChangeNotify* notify) = 0;
|
||
};
|
||
|
||
#endif // IVRCONFIG_H
|