You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
249 lines
8.4 KiB
249 lines
8.4 KiB
#include <iostream>
|
|
#include <string>
|
|
#include "json/json.h"
|
|
#include "ImgCheckBase.h"
|
|
#include "ImgCheckConfig.h"
|
|
#include <opencv2/opencv.hpp>
|
|
#include "CheckUtil.hpp"
|
|
#include "SaveImageFile.h"
|
|
#include <unistd.h> //0924-dd
|
|
#include "Down_Angle_Detect.h"
|
|
|
|
struct SystemConfigParam
|
|
{
|
|
std::string str_CheckConfigJson; // 检测基础参数json文件
|
|
std::string str_AIModelJson; // AI 模型 json文件
|
|
std::string str_ProcessNodeJson; // 过程节点 json文件
|
|
std::string str_detImgPath; // 测试图片路径
|
|
std::string str_templeteImgPath; // 模板图片路径1107-add
|
|
|
|
std::string str_ImagesPath; // 批量测试
|
|
std::string str_SaveImagesPath; // 批量保存测试
|
|
SystemConfigParam()
|
|
{
|
|
str_AIModelJson = "";
|
|
str_ProcessNodeJson = "";
|
|
str_detImgPath = "";
|
|
str_ImagesPath = "";
|
|
str_SaveImagesPath = "";
|
|
str_templeteImgPath=""; //1107-add
|
|
}
|
|
bool valid()
|
|
{
|
|
if (str_AIModelJson.size() &&
|
|
str_ProcessNodeJson.size())
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
|
|
bool ReadSystemConfig(const std::string &strPath, std::shared_ptr<SystemConfigParam> &pConfig)
|
|
{
|
|
printf("Reading system config %s\n", strPath.c_str());
|
|
Json::CharReaderBuilder builder;
|
|
builder["collectComments"] = true;
|
|
Json::Value root;
|
|
std::string err;
|
|
std::ifstream ifs(strPath);
|
|
if (!ifs.is_open())
|
|
{
|
|
printf("error:file is open\n");
|
|
return false;
|
|
}
|
|
if (!Json::parseFromStream(builder, ifs, &root, &err))
|
|
{
|
|
printf("error:parseFromStream\n");
|
|
return false;
|
|
}
|
|
pConfig = std::make_shared<SystemConfigParam>();
|
|
// path
|
|
pConfig->str_detImgPath = root["detImgPath"].asString();
|
|
pConfig->str_templeteImgPath=root["TempleteImgPath"].asString(); //模板图像路径 1107-add
|
|
|
|
pConfig->str_ImagesPath = root["ImagesPath"].asString();
|
|
pConfig->str_SaveImagesPath = root["SaveImagesPath"].asString();
|
|
pConfig->str_CheckConfigJson = root["CheckConfigJson"].asString();
|
|
pConfig->str_AIModelJson = root["AIModelJson"].asString();
|
|
pConfig->str_ProcessNodeJson = root["ProcessNodeJson"].asString();
|
|
printf("str_AIModelJson %s ProcessNodeJson %s\n", pConfig->str_AIModelJson.c_str(), pConfig->str_ProcessNodeJson.c_str());
|
|
return pConfig->valid();
|
|
}
|
|
|
|
// int main()//xls-org
|
|
int main(int argc, char *argv[])
|
|
{
|
|
printf("test ImgMeasure Count >>>>>> start \n");
|
|
printf("argc = %d\n", argc);
|
|
for (int i = 0; i < argc; i++)
|
|
{
|
|
printf("argv[%d]=%s\n", i, argv[i]);
|
|
}
|
|
|
|
std::shared_ptr<SystemConfigParam> psystem_param;
|
|
ReadSystemConfig("../data/system_BOE_Pol.json", psystem_param);
|
|
auto pImgCheck = std::make_shared<ImgCheckAnalysisy>();
|
|
printf("%s %s \n", pImgCheck->GetVersion().c_str(), pImgCheck->GetErrorInfo().c_str());
|
|
|
|
|
|
printf("img path %s \n", psystem_param->str_detImgPath.c_str());
|
|
cv::Mat img = cv::imread(psystem_param->str_detImgPath);
|
|
if (img.empty())
|
|
{
|
|
printf(" det img is empty >> exit \n");
|
|
return 1;
|
|
/* code */
|
|
}
|
|
printf("%d %d \n", img.cols, img.rows);
|
|
std::cout<<"psystem_param->str_TempleteImgPath="<<psystem_param->str_templeteImgPath<<std::endl; //模板图像路径
|
|
|
|
RunInfoST runconfig;
|
|
runconfig.str_AIModelJson = psystem_param->str_AIModelJson;
|
|
runconfig.str_RunJson = psystem_param->str_CheckConfigJson;
|
|
runconfig.str_0=psystem_param->str_templeteImgPath; //将模板图像路径传进来-1107
|
|
|
|
int re;
|
|
re = pImgCheck->LoadImgCheckParam((void *)&runconfig);
|
|
if (re != 0)
|
|
{
|
|
printf("ImgMeasure Init Fail >>>>>>> \n");
|
|
|
|
return 1;
|
|
}
|
|
|
|
std::shared_ptr<shareImage> image = std::make_shared<shareImage>();
|
|
image->img = img;
|
|
|
|
std::shared_ptr<CheckResult> result = std::make_shared<CheckResult>();
|
|
std::shared_ptr<CheckResult> result2retu = std::make_shared<CheckResult>();//1107-add
|
|
|
|
long t110, t220;
|
|
t110 = CheckUtil::getcurTime();
|
|
re = pImgCheck->CheckImg(image, result);
|
|
t220 = CheckUtil::getcurTime();
|
|
std::cout << "999 pImgCheck->CheckImg---time cost -----------" << t220 - t110 << "ms" << std::endl;
|
|
//getchar();
|
|
int re2 = pImgCheck->CheckRotateTemplete2Img2(image, result, result2retu);
|
|
|
|
if(!result->LabelPolygonRectImg.empty())
|
|
{
|
|
cv::imwrite("121retu-chipROI.png",result->LabelPolygonRectImg);
|
|
}
|
|
else{
|
|
std::cout<<"result->LabelPolygonRectImg.empty()"<<std::endl;
|
|
std::cout<<"33333333333333333"<<std::endl;
|
|
}
|
|
|
|
if(!result2retu->LabelPolygonRectImg.empty())
|
|
{
|
|
cv::imwrite("121retu-chipROI22.png",result2retu->LabelPolygonRectImg);
|
|
}
|
|
else{
|
|
std::cout<<"result2retu->LabelPolygonRectImg.empty()"<<std::endl;
|
|
std::cout<<"555555555555555555555555555"<<std::endl;
|
|
}
|
|
//getchar();
|
|
|
|
if (re != 0)
|
|
{
|
|
}
|
|
if (!result->resultImg.empty())
|
|
{
|
|
cv::imwrite("resultImg.png", result->resultImg);
|
|
}
|
|
//getchar();
|
|
|
|
std::cout << "psystem_param->str_ImagesPath=" << psystem_param->str_ImagesPath << std::endl;
|
|
std::cout << "psystem_param->str_SaveImagesPath=" << psystem_param->str_SaveImagesPath << std::endl;
|
|
std::string strImgPath = psystem_param->str_ImagesPath;
|
|
std::cout << "strImgPath=" << strImgPath << std::endl;
|
|
|
|
bool test_folder_flag = false; // dyy-add
|
|
if (argc > 1 && string(argv[1]) != "-h")
|
|
{
|
|
if (string(argv[1]) == "-f") // 测试文件夹
|
|
test_folder_flag = true;
|
|
}
|
|
|
|
|
|
//cv::Rect cropROI = cv::Rect(1111, 645, 2031, 2120); // 1106-add
|
|
// std::string temImgPath="20251016templete.jpg"; //正的模板
|
|
//std::string temImgPath = "20251016181654939_xie_templete.jpg"; // 斜的的模板
|
|
//std::string temImgPath = "20251016182409741_templete1107.jpg"; // 向右的的模板
|
|
std::string temImgPath = psystem_param->str_templeteImgPath; // 通过配置文件读入
|
|
|
|
test_folder_flag = true;
|
|
|
|
if (test_folder_flag) // dyy-add
|
|
{
|
|
if (strImgPath != "")
|
|
{
|
|
std::cout << strImgPath << std::endl;
|
|
std::vector<cv::String> 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;
|
|
std::cout << "not right folder-------------" << std::endl;
|
|
return 1; // 0919-add
|
|
}
|
|
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);
|
|
// if (strName == "20251016181937242") {
|
|
// std::cout << "find the img-----------------" << std::endl;
|
|
// }
|
|
// else {
|
|
// continue;
|
|
// }
|
|
|
|
std::shared_ptr<shareImage> tem = std::make_shared<shareImage>();
|
|
tem->img = img;
|
|
std::shared_ptr<CheckResult> result = std::make_shared<CheckResult>();
|
|
|
|
std::shared_ptr<CheckResult> result2retu2 = std::make_shared<CheckResult>();
|
|
|
|
long t111, t222;
|
|
t111 = CheckUtil::getcurTime();
|
|
re = pImgCheck->CheckImg(tem, result);
|
|
t222 = CheckUtil::getcurTime();
|
|
std::cout << "999 pImgCheck->CheckImg---time cost -----------" << t222 - t111 << "ms" << std::endl;
|
|
|
|
printf("%d %d %s det time %f \n", img.cols, img.rows, strName.c_str(), result->UseTimeMS);
|
|
|
|
std::cout << "result-offsetX=" << result->CenterOffsetX << std::endl;
|
|
std::cout << "result-offsetY=" << result->CenterOffsetY << std::endl; // 1027-add
|
|
std::cout << "result-offsetAngle=" << result->OffsetAngle << std::endl;
|
|
|
|
int re2 = pImgCheck->CheckRotateTemplete2Img2(tem, result, result2retu2);
|
|
// getchar();
|
|
// sv.saveImg(img, result->resultImg, strName, result->nresult);
|
|
//sv.saveImg2(img, result->resultImg, result->rotatedROIimg, strName, result->nresult); // 1105-add
|
|
//sv.saveImg4(img, result->resultImg, result->rotatedROIimg, temROIimg, strName, result->nresult); // 1105-add 后两张是ROI大图
|
|
//sv.saveImg4(img, result->resultImg, result->chipRoiImg, temChipROIimg, strName, result->nresult); // 110-add 后两张改为更小的芯片区域小图
|
|
//sv.saveImg4(img, result->resultImg, result->chipRoiImg, result->LabelPolygonRectImg, strName, result->nresult); //第4幅模板ROI图像从结果图像中获取
|
|
//借用第二个中间结果来保存,如果不调这一步,会节约时间
|
|
//sv.saveImg4(img, result->resultImg, result2retu->chipRoiImg, result2retu->LabelPolygonRectImg, strName, result->nresult); // 第4幅模板ROI图像从结果图像中获取
|
|
sv.saveImg4(img, result->resultImg, result2retu2->chipRoiImg, result2retu2->LabelPolygonRectImg, strName, result->nresult); //1107换成批量的对应结果图
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
printf("test ImgMeasure Count >>>>>> End \n");
|
|
return 0;
|
|
} |