|
|
|
|
@ -6,6 +6,12 @@
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "JpgDecoder.h"
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
void handler(int sig)
|
|
|
|
|
{
|
|
|
|
|
printf("Get handler sig");
|
|
|
|
|
@ -85,6 +91,7 @@ int main(int argc, char *argv[])
|
|
|
|
|
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 << "*** 7、./test_CellAOI -decode [dir]: 批量解码 .ytimage → .png 到 /home/aidlux/BOE/CELL_AOI/decode_img" << endl;
|
|
|
|
|
|
|
|
|
|
cout << "******************************************************" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
@ -96,12 +103,24 @@ int main(int argc, char *argv[])
|
|
|
|
|
printf("argv[%d]=%s\n", i, argv[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bDecodeMode = false;
|
|
|
|
|
std::string decodeInputDir;
|
|
|
|
|
|
|
|
|
|
if (argc > 1 && string(argv[1]) != "-h")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
|
{
|
|
|
|
|
if (string(argv[i]) == "-rs")
|
|
|
|
|
if (string(argv[i]) == "-decode")
|
|
|
|
|
{
|
|
|
|
|
bDecodeMode = true;
|
|
|
|
|
if (i + 1 < argc && argv[i + 1][0] != '-')
|
|
|
|
|
{
|
|
|
|
|
decodeInputDir = string(argv[i + 1]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (string(argv[i]) == "-rs")
|
|
|
|
|
{
|
|
|
|
|
test.runConfig.run_Type = Process_Run_SaveImg;
|
|
|
|
|
}
|
|
|
|
|
@ -156,6 +175,129 @@ int main(int argc, char *argv[])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ====== 批量解码模式 (-decode) ======
|
|
|
|
|
if (bDecodeMode)
|
|
|
|
|
{
|
|
|
|
|
std::string inputDir = decodeInputDir.empty()
|
|
|
|
|
? std::string("../data/img/t1")
|
|
|
|
|
: decodeInputDir;
|
|
|
|
|
std::string outputDir = "/home/aidlux/BOE/CELL_AOI/decode_img";
|
|
|
|
|
|
|
|
|
|
printf("\n========== 批量解码模式 ==========\n");
|
|
|
|
|
printf(" 输入目录: %s\n", inputDir.c_str());
|
|
|
|
|
printf(" 输出目录: %s\n", outputDir.c_str());
|
|
|
|
|
printf("===================================\n\n");
|
|
|
|
|
|
|
|
|
|
// 检查输入目录
|
|
|
|
|
if (!fs::exists(inputDir) || !fs::is_directory(inputDir))
|
|
|
|
|
{
|
|
|
|
|
printf("[decode] 输入目录不存在: %s\n", inputDir.c_str());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建输出目录
|
|
|
|
|
_sysmkdirs(outputDir);
|
|
|
|
|
|
|
|
|
|
// 只解码 .ytimage 原始多JPEG文件
|
|
|
|
|
auto isYtimageFile = [](const std::string &ext) -> bool {
|
|
|
|
|
std::string lower = ext;
|
|
|
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
|
|
|
return (lower == ".ytimage");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 扫描所有 .ytimage 文件
|
|
|
|
|
std::vector<fs::path> imageFiles;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
for (const auto &entry : fs::recursive_directory_iterator(inputDir))
|
|
|
|
|
{
|
|
|
|
|
if (entry.is_regular_file() && isYtimageFile(entry.path().extension().string()))
|
|
|
|
|
imageFiles.push_back(entry.path());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (const fs::filesystem_error &e)
|
|
|
|
|
{
|
|
|
|
|
printf("[decode] 扫描目录出错: %s\n", e.what());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (imageFiles.empty())
|
|
|
|
|
{
|
|
|
|
|
printf("[decode] 未找到 .ytimage 文件: %s\n", inputDir.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("[decode] 找到 %zu 个 .ytimage 文件,开始批量解码...\n", imageFiles.size());
|
|
|
|
|
|
|
|
|
|
// 逐个解码并保存
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
int failCount = 0;
|
|
|
|
|
struct timeval tvTotalStart, tvTotalEnd;
|
|
|
|
|
gettimeofday(&tvTotalStart, nullptr);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < imageFiles.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
const auto &imgPath = imageFiles[i];
|
|
|
|
|
std::string inputPath = imgPath.string();
|
|
|
|
|
|
|
|
|
|
printf("[%zu/%zu] %s ... ", i + 1, imageFiles.size(), imgPath.filename().c_str());
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
|
|
struct timeval tv1, tv2;
|
|
|
|
|
gettimeofday(&tv1, nullptr);
|
|
|
|
|
|
|
|
|
|
// ★ 调用 JpgDecoder 独立模块解码
|
|
|
|
|
cv::Mat decoded = decodeJpgImage(inputPath);
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tv2, nullptr);
|
|
|
|
|
long elapsed = (tv2.tv_sec - tv1.tv_sec) * 1000 + (tv2.tv_usec - tv1.tv_usec) / 1000;
|
|
|
|
|
|
|
|
|
|
if (decoded.empty())
|
|
|
|
|
{
|
|
|
|
|
printf("失败 (%ld ms)\n", elapsed);
|
|
|
|
|
failCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造输出路径(保持相对目录结构)
|
|
|
|
|
fs::path relativePath = fs::relative(imgPath, inputDir);
|
|
|
|
|
fs::path outputPath = fs::path(outputDir) / relativePath;
|
|
|
|
|
outputPath.replace_extension(".png"); // 统一保存为 PNG
|
|
|
|
|
|
|
|
|
|
// 确保输出子目录存在
|
|
|
|
|
std::string outDir = outputPath.parent_path().string();
|
|
|
|
|
_sysmkdirs(outDir);
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
|
if (cv::imwrite(outputPath.string(), decoded))
|
|
|
|
|
{
|
|
|
|
|
printf("OK → %s [%dx%d] (%ld ms)\n",
|
|
|
|
|
outputPath.filename().c_str(), decoded.cols, decoded.rows, elapsed);
|
|
|
|
|
successCount++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("保存失败\n");
|
|
|
|
|
failCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tvTotalEnd, nullptr);
|
|
|
|
|
long totalElapsed = (tvTotalEnd.tv_sec - tvTotalStart.tv_sec) * 1000 +
|
|
|
|
|
(tvTotalEnd.tv_usec - tvTotalStart.tv_usec) / 1000;
|
|
|
|
|
|
|
|
|
|
printf("\n========================================\n");
|
|
|
|
|
printf("[decode] 批量解码完成!\n");
|
|
|
|
|
printf(" 输入目录: %s\n", inputDir.c_str());
|
|
|
|
|
printf(" 输出目录: %s\n", outputDir.c_str());
|
|
|
|
|
printf(" 成功: %d 张\n", successCount);
|
|
|
|
|
printf(" 失败: %d 张\n", failCount);
|
|
|
|
|
printf(" 总耗时: %ld ms\n", totalElapsed);
|
|
|
|
|
printf("========================================\n");
|
|
|
|
|
|
|
|
|
|
return (successCount > 0) ? 0 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test.runConfig.print("config");
|
|
|
|
|
// getchar();
|
|
|
|
|
signal(SIGINT, handler);
|
|
|
|
|
|