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.

358 lines
9.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <iostream>
#include <string>
#include <signal.h>
#include "deal.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "Read_Image.h"
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;
}
// delete UnderCarriageCoreLogic::GetInstance();
exit(0);
}
int _sysmkdir(const std::string &dir)
{
int ret = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
if (ret && errno == EEXIST)
{
printf("dir[%s] already exist.\n", dir.c_str());
}
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;
}
int redimg_16()
{
std::string strImgPath = "/home/aidlux/BOE_CELL_ET/Image/20250718/left/__DB__6LQR560030C6BBA/*.tif";
// std::cout << strImgPath << std::endl;
std::vector<cv::String> img_paths;
cv::glob(strImgPath, img_paths, true);
for (int i = 0; i < img_paths.size(); i++)
{
std::string filename = img_paths[i];
std::cout << filename << std::endl;
size_t pos1 = filename.find('^');
size_t pos2 = filename.rfind(".tif"); // 或 ".tif" 的起始位置
std::string result;
if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1)
{
result = filename.substr(pos1 + 1, pos2 - pos1 - 1);
std::cout << "提取的内容: " << result << std::endl;
}
else
{
std::cerr << "格式不匹配,无法提取" << std::endl;
}
cv::Mat img16 = cv::imread(filename, cv::IMREAD_UNCHANGED);
if (img16.empty())
{
std::cerr << "无法读取图像: " << filename << std::endl;
return -1;
}
cv::Mat img8;
if (img16.type() == CV_16U)
{
cv::normalize(img16, img8, 0, 255, cv::NORM_MINMAX);
img8.convertTo(img8, CV_8U);
}
else if (img16.type() == CV_8U)
{
img8 = img16;
}
else
{
std::cerr << "图像不是 16 / 8位灰度图type = " << img16.type() << std::endl;
continue;
}
std::cout << "读取成功: " << img16.cols << " x " << img16.rows << ",类型: CV_16U" << std::endl;
// 方式一线性映射缩放到0~255
// double minVal, maxVal;
// cv::minMaxLoc(img16, &minVal, &maxVal);
// std::cout << "图像值范围: [" << minVal << ", " << maxVal << "]" << std::endl;
// cv::Mat img8;
// img16.convertTo(img8, CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
// 方式二(如果你知道最大值就是 65535也可以直接缩放
// img16.convertTo(img8, CV_8U, 1.0 / 256.0); // 65536 -> 256 缩放
// 保存或显示结果
cv::imwrite(result + "o11utput_8bit_gray.png", img8);
}
getchar();
std::string filename = "/home/aidlux/BOE_CELL_ET/Image/20250718/left/__DB__6LQR560030C6BBA/6LQR560030C6BBA^L127.tif";
// 使用 IMREAD_UNCHANGED 保留原始位深
cv::Mat img16 = cv::imread(filename, cv::IMREAD_UNCHANGED);
if (img16.empty())
{
std::cerr << "无法读取图像: " << filename << std::endl;
return -1;
}
// 检查是否是 16 位灰度图
if (img16.type() != CV_16U)
{
std::cerr << "图像不是 16 位灰度图type = " << img16.type() << std::endl;
return -1;
}
std::cout << "读取成功: " << img16.cols << " x " << img16.rows << ",类型: CV_16U" << std::endl;
// 方式一线性映射缩放到0~255
double minVal, maxVal;
cv::minMaxLoc(img16, &minVal, &maxVal);
std::cout << "图像值范围: [" << minVal << ", " << maxVal << "]" << std::endl;
cv::Mat img8;
img16.convertTo(img8, CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
// 方式二(如果你知道最大值就是 65535也可以直接缩放
// img16.convertTo(img8, CV_8U, 1.0 / 256.0); // 65536 -> 256 缩放
// 保存或显示结果
cv::imwrite("output_8bit_gray.png", img8);
// cv::imshow("8-bit Gray", img8);
// cv::waitKey(0);
return 0;
}
int main(int argc, char *argv[])
{
std::cout << "CHECK_WORK: " << CHECK_WORK << std::endl;
deal test;
for (int i = 0; i < Check_Work_COUNT; i++)
{
if (CHECK_WORK == Check_Work_Name[i])
{
test.m_check_Work_Type = static_cast<Check_Work_Type>(i);
break;
}
}
if (test.m_check_Work_Type == Check_Work_NULL)
{
cout << "***********************work type Error *******************************" << endl;
return 0;
}
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;
}
// redimg_16();
// Read_Image dfe;
// dfe.Read_Image_List("../data/img/pre");
// //dfe.Read_Image_List("/home/aidlux/BD_AOI/Data/SmallImage/60HW");
// getchar();
printf("argc = %d\n", argc);
for (int i = 0; i < argc; i++)
{
printf("argv[%d]=%s\n", i, argv[i]);
}
test.m_nRunType = RUNTYPE_RUN_Pre_BigImg; // 大图
test.m_strCheckFilePath = "";
if (argc > 1 && string(argv[1]) != "-h")
{
{
if (string(argv[1]) == "-f") // 遍历检查武汉精测图片
{
test.m_nRunType = RUNTYPE_RUN_File_BigImg; // 大图
if (argc == 3)
{
test.m_strCheckFilePath = string(argv[2]);
}
else
{
cout << "参数错误 ------- " << endl;
return 0;
}
}
else if (string(argv[1]) == "-fai") // 遍历检查武汉精测图片
{
test.m_nRunType = RUNTYPE_RUN_File_BigImg; // 大图
test.m_nTestAI = 1;
if (argc == 3)
{
test.m_strCheckFilePath = string(argv[2]);
}
else
{
cout << "参数错误 ------- " << endl;
return 0;
}
}
else if (string(argv[1]) == "-fc2")
{
test.m_nRunType = RUNTYPE_RUN_Pre_BigImg_Cam2; //
if (argc == 3)
{
if (string(argv[1]) == "-s")
{
test.m_nSaveDetprocessImg = 1;
}
}
}
else if (string(argv[1]) == "-fmark")
{
test.m_nRunType = RUNTYPE_RUN_File_MarkLine_Test; //
if (argc == 3)
{
test.m_strCheckFilePath = string(argv[2]);
test.m_nTestNum == 9999999;
}
else
{
cout << "参数错误 ------- " << endl;
return 0;
}
}
else if (string(argv[1]) == "-fe")
{
test.m_nRunType = RUNTYPE_RUN_File_BigImg_WHJC_EDGE_TEST; //
if (argc == 3)
{
test.m_strCheckFilePath = string(argv[2]);
test.m_nTestNum == 9999999;
}
else
{
cout << "参数错误 ------- " << endl;
return 0;
}
}
else if (string(argv[1]) == "-fcell")
{
test.m_nRunType = RUNTYPE_RUN_File_CEEL_ET; //
if (argc == 3)
{
test.m_strCheckFilePath = string(argv[2]);
}
else
{
cout << "参数错误 ------- " << endl;
return 0;
}
}
else if (string(argv[1]) == "-feai")
{
test.m_nRunType = RUNTYPE_RUN_File_BigImg_WHJC_EDGE_AI_TEST; //
if (argc == 3)
{
test.m_strCheckFilePath = string(argv[2]);
test.m_nTestNum == 9999999;
}
else if (argc == 4)
{
test.m_strCheckFilePath = 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[1]) == "-s")
{
test.m_nSaveDetprocessImg = 1;
}
else
{
cout << "参数错误 ------- " << endl;
return 0;
}
}
}
}
for (int i = 0; i < argc; ++i)
{
std::cout << "Argument #" << i << ": " << argv[i] << std::endl;
}
printf("m_nRunType %d m_nSaveDetprocessImg %d path %s\n", test.m_nRunType, test.m_nSaveDetprocessImg, test.m_strCheckFilePath.c_str());
// getchar();
signal(SIGINT, handler);
test.start();
while (true)
{
usleep(10 * 1000);
}
return 0;
}