重构手眼标定矩阵加载逻辑

This commit is contained in:
杰仔 2025-07-15 21:06:09 +08:00
parent ba586bf2ee
commit 64e403a11a
6 changed files with 57 additions and 20 deletions

View File

@ -296,16 +296,27 @@ int GrabBagPresenter::InitAlgorithmParams()
// 获取手眼标定文件路径并确保文件存在 // 获取手眼标定文件路径并确保文件存在
QString clibPath = PathManager::GetCalibrationFilePath(); QString clibPath = PathManager::GetCalibrationFilePath();
LOG_INFO("Loading hand-eye calibration matrix from: %s\n", clibPath.toStdString().c_str()); LOG_INFO("Loading hand-eye matrix : %s\n", clibPath.toStdString().c_str());
if(QFile::exists(clibPath)) if(QFile::exists(clibPath))
{ {
CVrConvert::LoadClibMatrix(clibPath.toStdString().c_str(), "clib", m_clibMatrix); CVrConvert::LoadClibMatrix(clibPath.toStdString().c_str(), "CalibMatrixInfo_0", "dCalibMatrix", m_clibMatrix);
}
// 输出手眼标定矩阵 m_clibMatrix 的内容
QString clibMatrixStr;
LOG_INFO("clibMatrixStr: \n");
for (int i = 0; i < 4; ++i) {
clibMatrixStr.clear();
for (int j = 0; j < 4; ++j) {
clibMatrixStr += QString::asprintf("%8.4f ", m_clibMatrix[i * 4 + j]);
}
LOG_INFO(" %s\n", clibMatrixStr.toStdString().c_str());
} }
// 获取配置文件路径 // 获取配置文件路径
QString configPath = PathManager::GetConfigFilePath(); QString configPath = PathManager::GetConfigFilePath();
LOG_INFO("Loading configuration from: %s\n", configPath.toStdString().c_str()); LOG_INFO("Loading config: %s\n", configPath.toStdString().c_str());
// 读取配置文件 // 读取配置文件
ConfigResult configResult = m_vrConfig->LoadConfig(configPath.toStdString()); ConfigResult configResult = m_vrConfig->LoadConfig(configPath.toStdString());

View File

@ -17,7 +17,7 @@ QString PathManager::GetCalibrationFilePath()
{ {
// 确保目标目录存在 // 确保目标目录存在
EnsureConfigDirectoryExists(); EnsureConfigDirectoryExists();
return GetAppConfigDirectory() + "/clib.ini"; return GetAppConfigDirectory() + "/EyeHandCalibMatrixInfo.ini";
} }
QString PathManager::GetAppConfigDirectory() QString PathManager::GetAppConfigDirectory()
@ -38,7 +38,6 @@ bool PathManager::EnsureConfigDirectoryExists()
QString configDir = GetAppConfigDirectory(); QString configDir = GetAppConfigDirectory();
if (QDir().exists(configDir)) { if (QDir().exists(configDir)) {
LOG_DEBUG("Configuration directory already exists: %s\n", configDir.toStdString().c_str());
return true; return true;
} }

View File

@ -3,8 +3,8 @@
#define GRABBAG_VERSION_STRING "1.0.1" #define GRABBAG_VERSION_STRING "1.0.1"
#define GRABBAG_BUILD_STRING "3" #define GRABBAG_BUILD_STRING "4"
#define GRABBAG_FULL_VERSION_STRING "V1.0.1_3" #define GRABBAG_FULL_VERSION_STRING "V1.0.1_4"
// 获取版本信息的便捷函数 // 获取版本信息的便捷函数
inline const char* GetGrabBagVersion() { inline const char* GetGrabBagVersion() {

View File

@ -0,0 +1,26 @@
[CommInfo]
nMaxMatrixNum=8
nExistMatrixNum=1
[CalibMatrixInfo_0]
nCalibPosIdx=0
eCalibType=0
eCalibMode=0
sCalibPosName=0
sCalibTime=2025-06-26-12-11-47
dCalibMatrix_0=-0.6465967149138568
dCalibMatrix_1=0.761458743338502
dCalibMatrix_2=0.04575227268627502
dCalibMatrix_3=759.0215603044383
dCalibMatrix_4=0.7621532947207551
dCalibMatrix_5=0.6473879189067671
dCalibMatrix_6=-0.0033522827841527825
dCalibMatrix_7=-403.08726353855
dCalibMatrix_8=-0.03217209363575841
dCalibMatrix_9=0.03270267033311197
dCalibMatrix_10=-0.9989471916693979
dCalibMatrix_11=801.5996530934686
dCalibMatrix_12=0
dCalibMatrix_13=0
dCalibMatrix_14=0
dCalibMatrix_15=1

View File

@ -8,10 +8,10 @@ std::ostream& operator<<(std::ostream& os, const SVzNL3DPoint& sPoint);
namespace CVrConvert namespace CVrConvert
{ {
// 加载矩阵 // 加载矩阵
bool LoadClibMatrix(const char* sFileName, const char* sIdent, double dMatrix[16]); bool LoadClibMatrix(const char* sFileName, const char* sIdent, const char* sKey, double dMatrix[16]);
// 存储矩阵 // 存储矩阵
bool SaveClibMatrix(const char* sFileName, const char* sIdent, double dMatrix[16]); bool SaveClibMatrix(const char* sFileName, const char* sIdent, const char* sKey, double dMatrix[16]);
// 手眼标定 // 手眼标定
bool CalibEyeToRobot(SVzNL3DPoint* pEye3DPoint, SVzNL3DPoint* pRobot3DPoint, const int nNum); bool CalibEyeToRobot(SVzNL3DPoint* pEye3DPoint, SVzNL3DPoint* pRobot3DPoint, const int nNum);

View File

@ -14,46 +14,47 @@ std::ostream& operator<<(std::ostream& os, const SVzNL3DPoint& sPoint)
return os; return os;
} }
bool CVrConvert::LoadClibMatrix(const char* sFileName, const char* sIdent, double dMatrix[16]) bool CVrConvert::LoadClibMatrix(const char* sFileName, const char* sIdent, const char* sKey, double dMatrix[16])
{ {
// 读取配置文件 // 读取配置文件
CSimpleIniA ini; CSimpleIniA ini;
// 加载文件并解析 // 加载文件并解析
SI_Error rc = ini.LoadFile(sFileName); SI_Error rc = ini.LoadFile(sFileName);
LOG_INFO("LoadClibMatrix: %s\n", sFileName);
if(SI_OK != rc) return false; if(SI_OK != rc) return false;
for(int i = 0 ; i < 16; i++) for(int i = 0 ; i < 16; i++)
{ {
char sKey[64] = {0}; char sTmpKey[64] = {0};
#ifdef _WIN32 #ifdef _WIN32
sprintf_s(sKey, "%s_%d", sIdent, i); sprintf_s(sTmpKey, "%s_%d", sKey, i);
#else #else
sprintf(sKey, "%s_%d", sIdent, i); sprintf(sTmpKey, "%s_%d", sKey, i);
#endif #endif
dMatrix[i] = ini.GetDoubleValue(sIdent, sKey, i % 5 == 0 ? 1 : 0); dMatrix[i] = ini.GetDoubleValue(sIdent, sTmpKey, i % 5 == 0 ? 1 : 0);
} }
return true; return true;
} }
// 存储矩阵 // 存储矩阵
bool CVrConvert::SaveClibMatrix(const char* sFileName, const char* sIdent, double dMatrix[16]) bool CVrConvert::SaveClibMatrix(const char* sFileName, const char* sIdent, const char* sKey, double dMatrix[16])
{ {
CSimpleIniA ini; CSimpleIniA ini;
SI_Error rc = ini.LoadFile(sFileName); SI_Error rc = ini.LoadFile(sFileName);
if (rc != SI_OK) return false; if (rc != SI_OK) return false;
for(int i = 0 ; i < 16; i++) for(int i = 0 ; i < 16; i++)
{ {
char sKey[64] = {0}; char sTmpKey[64] = {0};
#ifdef _WIN32 #ifdef _WIN32
sprintf_s(sKey, "%s_%d", sIdent, i); sprintf_s(sTmpKey, "%s_%s_%d", sIdent, sKey, i);
#else #else
sprintf(sKey, "%s_%d", sIdent, i); sprintf(sTmpKey, "%s_%s_%d", sIdent, sKey, i);
#endif #endif
ini.SetDoubleValue(sIdent, sKey, dMatrix[i]); ini.SetDoubleValue(sIdent, sTmpKey, dMatrix[i]);
} }
ini.SaveFile(sFileName); ini.SaveFile(sFileName);
return true; return true;