优化配置文件路劲判断,优化偏移转换为机械手移动

master
xiewenji 1 week ago
parent a50a2c1c6a
commit d9e2762b68

@ -66,7 +66,7 @@ bool ReadSystemConfig(const std::string &strPath, std::shared_ptr<SystemConfigPa
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
bool bsave = false; bool bsave = false;
if (argc > 1 && string(argv[1]) != "-h") if (argc > 1 && string(argv[1]) != "-h")
{ {
@ -76,15 +76,15 @@ int main(int argc, char *argv[])
} }
} }
printf("test ImgMeasure Count >>>>>> start bsave %d\n",bsave); printf("test ImgMeasure Count >>>>>> start bsave %d\n", bsave);
std::shared_ptr<SystemConfigParam> psystem_param; std::shared_ptr<SystemConfigParam> psystem_param;
DETECT_TYPE detect_type = DETECT_TYPE_QX; //检测类型 DETECT_TYPE detect_type = DETECT_TYPE_QX; // 检测类型
// ReadSystemConfig("../data/Top1_Det/System_Config.json", psystem_param); // ReadSystemConfig("../data/Top1_Det/System_Config.json", psystem_param);
// CAMERA_POSITION cam_position = CAMERA_TOP_1;//相机位置 // CAMERA_POSITION cam_position = CAMERA_TOP_1;//相机位置
ReadSystemConfig("../data/Top2_Det/System_Config.json", psystem_param); // ReadSystemConfig("../data/Top2_Det/System_Config.json", psystem_param);
CAMERA_POSITION cam_position = CAMERA_TOP_2;//相机位置 // CAMERA_POSITION cam_position = CAMERA_TOP_2; // 相机位置
// ReadSystemConfig("../data/Side1_Det/System_Config.json", psystem_param); // ReadSystemConfig("../data/Side1_Det/System_Config.json", psystem_param);
// CAMERA_POSITION cam_position = CAMERA_SIDE_1;//相机位置 // CAMERA_POSITION cam_position = CAMERA_SIDE_1;//相机位置
@ -96,15 +96,15 @@ int main(int argc, char *argv[])
// CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置 // CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置
//测旋转 //测旋转
// ReadSystemConfig("../data/Down_Det/System_Config.json", psystem_param); ReadSystemConfig("../data/Down_Det/System_Config.json", psystem_param);
// CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置 CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置
// detect_type = DETECT_TYPE_ANGLE; detect_type = DETECT_TYPE_ANGLE;
std::shared_ptr<ImgCheckBase> pImgCount = ImgCheckBase::GetInstance(); std::shared_ptr<ImgCheckBase> pImgCount = ImgCheckBase::GetInstance();
printf("%s %s \n", pImgCount->GetVersion().c_str(), pImgCount->GetErrorInfo().c_str()); printf("%s %s \n", pImgCount->GetVersion().c_str(), pImgCount->GetErrorInfo().c_str());
cv::Mat img = cv::imread(psystem_param->str_detImgPath); cv::Mat img = cv::imread(psystem_param->str_detImgPath);
printf("img path %s \n",psystem_param->str_detImgPath.c_str()); printf("img path %s \n", psystem_param->str_detImgPath.c_str());
if (img.empty()) if (img.empty())
{ {
printf(" det img is empty >> exit \n"); printf(" det img is empty >> exit \n");
@ -142,43 +142,54 @@ int main(int argc, char *argv[])
cv::imwrite("resultImg.png", result->resultImg); cv::imwrite("resultImg.png", result->resultImg);
} }
// 文件夹测试
std::string strImgPath = psystem_param->str_ImagesPath; std::string strImgPath = psystem_param->str_ImagesPath;
if (strImgPath != "") bool test_folder_flag = false; // dyy-add
if (argc > 1 && string(argv[1]) != "-h")
{ {
std::cout << strImgPath << std::endl; if (string(argv[1]) == "-f") // 测试文件夹
std::vector<cv::String> img_paths; test_folder_flag = true;
bool bgo = true; }
try if (test_folder_flag)
{ {
cv::glob(strImgPath, img_paths, true); if (strImgPath != "")
}
catch (const std::exception &e)
{
bgo = false;
std::cout << "Invalid or non-existent directory: " << strImgPath << std::endl;
}
if (bgo)
{ {
SaveImageFile sv; std::cout << strImgPath << std::endl;
sv.SetSavePath(psystem_param->str_SaveImagesPath); std::vector<cv::String> img_paths;
for (int i = 0; i < img_paths.size(); i++) bool bgo = true;
try
{
cv::glob(strImgPath, img_paths, true);
}
catch (const std::exception &e)
{ {
std::cout << img_paths[i] << std::endl; bgo = false;
std::string str = img_paths[i]; std::cout << "Invalid or non-existent directory: " << strImgPath << std::endl;
std::string strName = CheckUtil::splitFilePath(str); }
cv::Mat img = cv::imread(str); if (bgo)
// {
SaveImageFile sv;
std::shared_ptr<shareImage> tem = std::make_shared<shareImage>(); sv.SetSavePath(psystem_param->str_SaveImagesPath);
tem->img = img; for (int i = 0; i < img_paths.size(); i++)
std::shared_ptr<CheckResult> result; {
re = pImgCount->CheckImg(tem, result); std::cout << img_paths[i] << std::endl;
printf("%d %d %s det time %f \n", img.cols, img.rows, strName.c_str(), result->UseTimeMS); std::string str = img_paths[i];
sv.saveImg(img, result->resultImg, strName, result->nresult); std::string strName = CheckUtil::splitFilePath(str);
cv::Mat img = cv::imread(str);
//
std::shared_ptr<shareImage> tem = std::make_shared<shareImage>();
tem->img = img.clone();
tem->cam_position = cam_position;
tem->detect_type = detect_type;
std::shared_ptr<CheckResult> result;
re = pImgCount->CheckImg(tem, result);
printf("%d %d %s det time %f \n", img.cols, img.rows, strName.c_str(), result->UseTimeMS);
sv.saveImg(img, result->resultImg, strName, result->nresult);
}
} }
} }
} }
printf("test ImgMeasure Count >>>>>> End \n"); printf("test ImgMeasure Count >>>>>> End \n");
return 0; return 0;
} }

@ -26,46 +26,70 @@ int ALL_Detect::RunStart(void *pconfig1)
m_cam_param.copy(*(Cam_Param *)pconfig1); m_cam_param.copy(*(Cam_Param *)pconfig1);
RunInfoST runconfig; RunInfoST runconfig;
runconfig.flag0 = m_cam_param.cam_position; runconfig.flag0 = m_cam_param.cam_position;
if (m_cam_param.check_param_path.empty() || m_cam_param.AIModel_param_path.empty())
{
printf("check_param_path or AIModel_param_path is empty\n");
return -1;
}
if (m_cam_param.AIModel_param_path.back() != '/')
m_cam_param.AIModel_param_path += '/';
if (m_cam_param.check_param_path.back() != '/')
m_cam_param.check_param_path += '/';
switch (m_cam_param.cam_position) switch (m_cam_param.cam_position)
{ {
case CAMERA_TOP_1: case CAMERA_TOP_1:
{
if (!m_checkBase) if (!m_checkBase)
m_checkBase = std::make_shared<Top_Detect>(); m_checkBase = std::make_shared<Top_Detect>();
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Top.json"; runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Top.json";
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Top-1.json"; runconfig.str_RunJson = m_cam_param.check_param_path + "param_Top-1.json";
break; break;
}
case CAMERA_TOP_2: case CAMERA_TOP_2:
{
if (!m_checkBase) if (!m_checkBase)
m_checkBase = std::make_shared<Top_Detect>(); m_checkBase = std::make_shared<Top_Detect>();
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Top.json"; runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Top.json";
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Top-2.json"; runconfig.str_RunJson = m_cam_param.check_param_path + "param_Top-2.json";
break; break;
}
case CAMERA_SIDE_1: case CAMERA_SIDE_1:
{
if (!m_checkBase) if (!m_checkBase)
m_checkBase = std::make_shared<Side_Detect>(); m_checkBase = std::make_shared<Side_Detect>();
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Side.json"; runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Side.json";
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Side-1.json"; runconfig.str_RunJson = m_cam_param.check_param_path + "param_Side-1.json";
break; break;
}
case CAMERA_SIDE_2: case CAMERA_SIDE_2:
{
if (!m_checkBase) if (!m_checkBase)
m_checkBase = std::make_shared<Side_Detect>(); m_checkBase = std::make_shared<Side_Detect>();
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Side.json"; runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Side.json";
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Side-2.json"; runconfig.str_RunJson = m_cam_param.check_param_path + "param_Side-2.json";
break; break;
}
case CAMERA_DOWN_1: case CAMERA_DOWN_1:
{
if (!m_checkBase) if (!m_checkBase)
m_checkBase = std::make_shared<Down_Detect>(); m_checkBase = std::make_shared<Down_Detect>();
if (!m_down_angle_detect) if (!m_down_angle_detect)
m_down_angle_detect = std::make_shared<Down_Angle_Detect>(); m_down_angle_detect = std::make_shared<Down_Angle_Detect>();
runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Down.json"; runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_Down.json";
runconfig.str_RunJson = m_cam_param.check_param_path + "param_Down.json"; runconfig.str_RunJson = m_cam_param.check_param_path + "param_Down.json";
this->m_down_angle_detect->RunStart((void *)&runconfig); auto ret = this->m_down_angle_detect->RunStart((void *)&runconfig);
if (ret != 0)
{
std::cout << "Down_Angle_Detect RunStart failed, ret=" << ret << std::endl;
return ret;
}
break; break;
}
default: default:
break; break;
} }
this->m_checkBase->RunStart((void *)&runconfig); return this->m_checkBase->RunStart((void *)&runconfig);
return 0;
} }
int ALL_Detect::CheckImg(std::shared_ptr<shareImage> p, std::shared_ptr<CheckResult> &pResult) int ALL_Detect::CheckImg(std::shared_ptr<shareImage> p, std::shared_ptr<CheckResult> &pResult)
@ -85,7 +109,9 @@ int ALL_Detect::CheckImg(std::shared_ptr<shareImage> p, std::shared_ptr<CheckRes
return -2; return -2;
} }
return this->m_down_angle_detect->CheckImg(p, pResult); return this->m_down_angle_detect->CheckImg(p, pResult);
} else { }
else
{
return this->m_checkBase->CheckImg(p, pResult); return this->m_checkBase->CheckImg(p, pResult);
} }
} }

@ -420,13 +420,17 @@ int Down_Angle_Detect::CheckRun()
double x_coeff = pdetConfig->calibration_coeff_x; // 1107-add double x_coeff = pdetConfig->calibration_coeff_x; // 1107-add
double y_coeff = pdetConfig->calibration_coeff_y; // 1107-add double y_coeff = pdetConfig->calibration_coeff_y; // 1107-add
m_CheckResult_shareP->CenterOffsetX = CenterOffsetP.x * x_coeff; // 最终结果输出 //基于图像坐标偏移
m_CheckResult_shareP->CenterOffsetY = CenterOffsetP.y * y_coeff; // 最终结果输出 double x_pixel_offset = CenterOffsetP.x * x_coeff;
double y_pixel_offset = CenterOffsetP.y * y_coeff;
//换算到基于机械臂的世界坐标系
m_CheckResult_shareP->CenterOffsetX = y_pixel_offset; //机械手的x对应像素y偏移
m_CheckResult_shareP->CenterOffsetY = -x_pixel_offset; //机械手的y对应像素x偏移取负
m_CheckResult_shareP->OffsetAngle = offsetAngle; m_CheckResult_shareP->OffsetAngle = offsetAngle;
std::cout << "OffsetXOut=" << CenterOffsetP.x << " resultMove" << m_CheckResult_shareP->CenterOffsetX << std::endl; std::cout << "OffsetXOut=" << CenterOffsetP.x << " resultMoveX=" << m_CheckResult_shareP->CenterOffsetX << std::endl;
std::cout << "OffsetYOut=" << CenterOffsetP.y << " resultMove" << m_CheckResult_shareP->CenterOffsetY << std::endl; std::cout << "OffsetYOut=" << CenterOffsetP.y << " resultMoveY=" << m_CheckResult_shareP->CenterOffsetY << std::endl;
std::cout << "Offsetangle=" << offsetAngle << std::endl; std::cout << "LabelAngle=" << LabelAngle << " Offsetangle=" << offsetAngle << std::endl;
t2 = CheckUtil::getcurTime(); t2 = CheckUtil::getcurTime();
m_CheckResult_shareP->UseTimeMS = t2 - t1; m_CheckResult_shareP->UseTimeMS = t2 - t1;

Loading…
Cancel
Save