From d9e2762b6823a597822e633f24ae40003b697b7a Mon Sep 17 00:00:00 2001 From: xiewenji <527774126@qq.com> Date: Mon, 8 Dec 2025 11:43:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=8A=B2=E5=88=A4=E6=96=AD=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=81=8F=E7=A7=BB=E8=BD=AC=E6=8D=A2=E4=B8=BA=E6=9C=BA?= =?UTF-8?q?=E6=A2=B0=E6=89=8B=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ALL_Det/example/test_example.cpp | 89 +++++++++++++----------- ALL_Det/src/ALL_Detect.cpp | 34 +++++++-- Down_Angle_Det/src/Down_Angle_Detect.cpp | 14 ++-- 3 files changed, 89 insertions(+), 48 deletions(-) diff --git a/ALL_Det/example/test_example.cpp b/ALL_Det/example/test_example.cpp index 455b1b9..e0e4cee 100644 --- a/ALL_Det/example/test_example.cpp +++ b/ALL_Det/example/test_example.cpp @@ -66,7 +66,7 @@ bool ReadSystemConfig(const std::string &strPath, std::shared_ptr 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 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); // CAMERA_POSITION cam_position = CAMERA_TOP_1;//相机位置 - ReadSystemConfig("../data/Top2_Det/System_Config.json", psystem_param); - CAMERA_POSITION cam_position = CAMERA_TOP_2;//相机位置 + // ReadSystemConfig("../data/Top2_Det/System_Config.json", psystem_param); + // CAMERA_POSITION cam_position = CAMERA_TOP_2; // 相机位置 // ReadSystemConfig("../data/Side1_Det/System_Config.json", psystem_param); // CAMERA_POSITION cam_position = CAMERA_SIDE_1;//相机位置 @@ -96,15 +96,15 @@ int main(int argc, char *argv[]) // CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置 //测旋转 - // ReadSystemConfig("../data/Down_Det/System_Config.json", psystem_param); - // CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置 - // detect_type = DETECT_TYPE_ANGLE; + ReadSystemConfig("../data/Down_Det/System_Config.json", psystem_param); + CAMERA_POSITION cam_position = CAMERA_DOWN_1;//相机位置 + detect_type = DETECT_TYPE_ANGLE; std::shared_ptr pImgCount = ImgCheckBase::GetInstance(); printf("%s %s \n", pImgCount->GetVersion().c_str(), pImgCount->GetErrorInfo().c_str()); 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()) { printf(" det img is empty >> exit \n"); @@ -142,43 +142,54 @@ int main(int argc, char *argv[]) cv::imwrite("resultImg.png", result->resultImg); } + // 文件夹测试 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; - std::vector img_paths; - bool bgo = true; - try - { - cv::glob(strImgPath, img_paths, true); - } - catch (const std::exception &e) - { - bgo = false; - std::cout << "Invalid or non-existent directory: " << strImgPath << std::endl; - } - if (bgo) + if (string(argv[1]) == "-f") // 测试文件夹 + test_folder_flag = true; + } + if (test_folder_flag) + { + if (strImgPath != "") { - SaveImageFile sv; - sv.SetSavePath(psystem_param->str_SaveImagesPath); - for (int i = 0; i < img_paths.size(); i++) + std::cout << strImgPath << std::endl; + std::vector img_paths; + bool bgo = true; + try + { + cv::glob(strImgPath, img_paths, true); + } + catch (const std::exception &e) { - std::cout << img_paths[i] << std::endl; - std::string str = img_paths[i]; - std::string strName = CheckUtil::splitFilePath(str); - cv::Mat img = cv::imread(str); - // - - std::shared_ptr tem = std::make_shared(); - tem->img = img; - std::shared_ptr 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); + bgo = false; + std::cout << "Invalid or non-existent directory: " << strImgPath << std::endl; + } + if (bgo) + { + SaveImageFile sv; + sv.SetSavePath(psystem_param->str_SaveImagesPath); + for (int i = 0; i < img_paths.size(); i++) + { + std::cout << img_paths[i] << std::endl; + std::string str = img_paths[i]; + std::string strName = CheckUtil::splitFilePath(str); + cv::Mat img = cv::imread(str); + // + + std::shared_ptr tem = std::make_shared(); + tem->img = img.clone(); + tem->cam_position = cam_position; + tem->detect_type = detect_type; + std::shared_ptr 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"); return 0; } \ No newline at end of file diff --git a/ALL_Det/src/ALL_Detect.cpp b/ALL_Det/src/ALL_Detect.cpp index 649e6ef..02c13ed 100644 --- a/ALL_Det/src/ALL_Detect.cpp +++ b/ALL_Det/src/ALL_Detect.cpp @@ -26,46 +26,70 @@ int ALL_Detect::RunStart(void *pconfig1) m_cam_param.copy(*(Cam_Param *)pconfig1); RunInfoST runconfig; 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) { case CAMERA_TOP_1: + { if (!m_checkBase) m_checkBase = std::make_shared(); 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"; break; + } case CAMERA_TOP_2: + { if (!m_checkBase) m_checkBase = std::make_shared(); 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"; break; + } case CAMERA_SIDE_1: + { if (!m_checkBase) m_checkBase = std::make_shared(); 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"; break; + } case CAMERA_SIDE_2: + { if (!m_checkBase) m_checkBase = std::make_shared(); 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"; break; + } case CAMERA_DOWN_1: + { if (!m_checkBase) m_checkBase = std::make_shared(); if (!m_down_angle_detect) m_down_angle_detect = std::make_shared(); runconfig.str_AIModelJson = m_cam_param.AIModel_param_path + "AIModel_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; + } default: break; } - this->m_checkBase->RunStart((void *)&runconfig); - return 0; + return this->m_checkBase->RunStart((void *)&runconfig); } int ALL_Detect::CheckImg(std::shared_ptr p, std::shared_ptr &pResult) @@ -85,7 +109,9 @@ int ALL_Detect::CheckImg(std::shared_ptr p, std::shared_ptrm_down_angle_detect->CheckImg(p, pResult); - } else { + } + else + { return this->m_checkBase->CheckImg(p, pResult); } } diff --git a/Down_Angle_Det/src/Down_Angle_Detect.cpp b/Down_Angle_Det/src/Down_Angle_Detect.cpp index 408275c..8032581 100644 --- a/Down_Angle_Det/src/Down_Angle_Detect.cpp +++ b/Down_Angle_Det/src/Down_Angle_Detect.cpp @@ -420,13 +420,17 @@ int Down_Angle_Detect::CheckRun() double x_coeff = pdetConfig->calibration_coeff_x; // 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; - std::cout << "OffsetXOut=" << CenterOffsetP.x << " resultMove" << m_CheckResult_shareP->CenterOffsetX << std::endl; - std::cout << "OffsetYOut=" << CenterOffsetP.y << " resultMove" << m_CheckResult_shareP->CenterOffsetY << std::endl; - std::cout << "Offsetangle=" << offsetAngle << std::endl; + std::cout << "OffsetXOut=" << CenterOffsetP.x << " resultMoveX=" << m_CheckResult_shareP->CenterOffsetX << std::endl; + std::cout << "OffsetYOut=" << CenterOffsetP.y << " resultMoveY=" << m_CheckResult_shareP->CenterOffsetY << std::endl; + std::cout << "LabelAngle=" << LabelAngle << " Offsetangle=" << offsetAngle << std::endl; t2 = CheckUtil::getcurTime(); m_CheckResult_shareP->UseTimeMS = t2 - t1;