#include #include #include #include "deal.h" #include #include #include #include #include "LoadImage.hpp" void handler(int sig) { printf("Get handler sig"); string strcmd = "ps -ef | grep test_JBL_Check| awk '{print $2}' | xargs kill -9 "; const char *cmd = strcmd.c_str(); printf("delete test_JBL_Check success"); if (-1 == system(cmd)) { std::cout << "error" << std::endl; } exit(0); } int _sysmkdir(const std::string &dir) { int ret = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXG | S_IROTH | S_IXOTH); if (ret && errno == EEXIST) { } else if (ret) { printf("create dir[%s] error: %d %s\n", dir.c_str(), ret, strerror(errno)); return -1; } else { printf("create dir[%s] success.\n", dir.c_str()); } return 0; } std::string __getParentDir(const std::string &dir) { std::string pdir = dir; if (pdir.length() < 1 || (pdir[0] != '/')) { return ""; } while (pdir.length() > 1 && (pdir[pdir.length() - 1] == '/')) pdir = pdir.substr(0, pdir.length() - 1); pdir = pdir.substr(0, pdir.find_last_of('/')); return pdir; } int _sysmkdirs(const std::string &dir) { int ret = 0; if (dir.empty()) return -1; std::string pdir; if ((ret = _sysmkdir(dir)) == -1) { pdir = __getParentDir(dir); if ((ret = _sysmkdirs(pdir)) == 0) { ret = _sysmkdirs(dir); } } return ret; } /// @brief LoadImage 测试函数 void test_LoadImage() { printf("\n"); printf("╔═══════════════════════════════════════════════════════════\n"); printf("║ LoadImage 测试函数 \n"); printf("╚═══════════════════════════════════════════════════════════\n"); printf("\n"); std::string root_dir = "/home/aidlux/BOE_FOG/Image/20250718"; printf("测试目录:%s\n\n", root_dir.c_str()); LoadImage loader; LoadConfig config; config.Init(); printf("开始加载图片...\n\n"); std::vector products = loader.LoadALLImg(root_dir, config); if (products.empty()) { printf("未找到任何图片!\n"); printf("错误信息:%s\n", loader.getLastError().c_str()); return; } printf("加载完成!\n"); printf("产品数量:%zu\n", products.size()); printf("图片总数:%zu\n\n", loader.getTotalLoaded()); for (size_t i = 0; i < products.size(); i++) { products[i].print("产品" + std::to_string(i + 1)); } printf("\n"); printf("╔═══════════════════════════════════════════════════════════\n"); printf("║ 测试完成 \n"); printf("╚═══════════════════════════════════════════════════════════\n"); printf("\n"); } int main(int argc, char *argv[]) { // // LoadImage 测试 // test_LoadImage(); // getchar(); deal test; if (argc > 1 && string(argv[1]) == "-h") { cout << "******************************************************" << endl; cout << "*** 1 ./test_JBL_Check: 默认处理一套图 图片文件夹位于 ../data/img/t1,结果位于/home/aidlux/BOE/testresult" << endl; cout << "*** 2 ./test_JBL_Check -s: 1 的基础上增加 过程存图,包括 edge 和字符检测的中间结果存图,图片位于 当前文件夹。" << endl; cout << "*** 3 ./test_JBL_Check -fjc filepath: 处理精测套图大图 结果位于/home/aidlux/BOE/ResultImg" << endl; cout << "*** 4 ./test_JBL_Check -feai filepath num: 批量测试边缘检测算法,num 至多处理张数,结果:/home/aidlux/BOE/Edge" << endl; cout << "*** 5 ./test_JBL_Check -falign filepath num : 批量测试定位算法,num 至多处理张数,结果:/home/aidlux/BOE/Align" << endl; cout << "*** 6 ./test_JBL_Check -rjson filepath: 单张复测,filepath xx/xx/3A3K380001B1DK_20240408_152157_Main_0_2_L255" << endl; cout << "*** 6 ./test_JBL_Check -rjsonall filepath: 一套图复测,filepath xx/xx/" << endl; cout << "******************************************************" << endl; return 0; } printf("argc = %d\n", argc); for (int i = 0; i < argc; i++) { printf("argv[%d]=%s\n", i, argv[i]); } if (argc > 1 && string(argv[1]) != "-h") { for (int i = 1; i < argc; i++) { if (string(argv[i]) == "-rs") { test.runConfig.run_Type = Process_Run_SaveImg; } else if (string(argv[i]) == "-rd") { test.runConfig.run_Type = Process_Run_Detect; } else if (string(argv[i]) == "-rjson") { if (i + 1 >= argc) { printf("error Not Path \n"); return -1; } test.runConfig.run_Type = Process_Run_ReJson; test.runConfig.filePath = string(argv[i + 1]); } else if (string(argv[i]) == "-f" && i + 1 < argc) { test.runConfig.det_Type = RUNTYPE_RUN_File; test.runConfig.filePath = string(argv[i + 1]); } else if (string(argv[i]) == "-feai" && i + 1 < argc) { test.runConfig.det_Type = RUNTYPE_RUN_File_AI_TEST; if (argc == 3) { test.runConfig.filePath = string(argv[2]); test.runConfig.m_nTestNum == 9999999; } else if (argc == 4) { test.runConfig.filePath = string(argv[2]); std::string strnum = string(argv[3]); test.runConfig.m_nTestNum = atoi(strnum.c_str()); } else { cout << "参数错误 ------- " << endl; return 0; } } else if (string(argv[i]) == "-feqx" && i + 1 < argc) { test.runConfig.det_Type = RUNTYPE_RUN_File_Edge_Test_Save_Qx; if (argc == 3) { test.runConfig.filePath = string(argv[2]); test.m_nTestNum == 9999999; } else if (argc == 4) { test.runConfig.filePath = string(argv[2]); std::string strnum = string(argv[3]); test.m_nTestNum = atoi(strnum.c_str()); } else { cout << "参数错误 ------- " << endl; return 0; } } else if (string(argv[i]) == "-feallqx" && i + 1 < argc) { test.runConfig.det_Type = RUNTYPE_RUN_File_Edge_Test_Save_ALL; if (argc == 3) { test.runConfig.filePath = string(argv[2]); test.m_nTestNum == 9999999; } else if (argc == 4) { test.runConfig.filePath = string(argv[2]); std::string strnum = string(argv[3]); test.m_nTestNum = atoi(strnum.c_str()); } else { cout << "参数错误 ------- " << endl; return 0; } } if (string(argv[i]) == "-s") { test.runConfig.bDebugSaveImg = true; } if (string(argv[i]) == "-n" && i + 1 < argc) { std::string strnum = string(argv[i + 1]); test.m_nTestNum = atoi(strnum.c_str()); } } } test.runConfig.print("config"); signal(SIGINT, handler); test.start(); while (true) { usleep(10 * 1000); } return 0; }