update 修改离线送图流程

dev_lsy
xiewenji 20 hours ago
parent a43e9fb10d
commit 42bcdc81b4

@ -19,7 +19,7 @@ message(STATUS "oPENCV Library status:")
message(STATUS ">version:${OpenCV_VERSION}")
message(STATUS "Include:${OpenCV_INCLUDE_DIRS}")
set(CMAKE_BUILD_TYPE "release")
set(CMAKE_BUILD_TYPE "debug")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # C++17
set(CMAKE_CXX_EXTENSIONS OFF) # GNU

@ -214,12 +214,26 @@ int ExtractInstance::DecodeJpgImg(std::vector<JPGImgDataPtr> &ptrImgdataList, cv
int ExtractInstance::ReadCELLImg(std::string strimgPath, cv::Mat &outImg, bool bdecode)
{
int re = -1;
if(bdecode)
// 不解码模式:直接用 opencv 读取图片
if (!bdecode)
{
printf("ReadCELLImg========= %s \n", strimgPath.c_str());
int re = decode_Img(strimgPath, outImg);
outImg = cv::imread(strimgPath, cv::IMREAD_GRAYSCALE);
if (outImg.empty())
{
std::cerr << "错误:无法读取图片,请检查路径是否正确!" << std::endl;
return -1;
}
return 0;
}
else
// 解码模式: 处理 .ytimage 格式
// if(bdecode)
// {
// printf("ReadCELLImg========= %s \n", strimgPath.c_str());
// int re = decode_Img(strimgPath, outImg);
// }
// else
{
size_t lastSlashIndex = strimgPath.find_last_of("/");
std::string basePath;

@ -18,7 +18,7 @@ int Extract_Name_Base::Read_Camera_Product_Image(std::string strPath, int userfl
{
std::vector<cv::String> img_paths;
// std::cout << strPath << std::endl;
std::cout << strPath << std::endl;
cv::glob(strPath, img_paths, true);
for (int i = 0; i < img_paths.size(); i++)
{
@ -142,7 +142,7 @@ int Read_Image::Read_Image_List(std::string strPath_left, std::string strPath_ri
int Extract_ALL::Extract_Info(std::string strPath, std::string strproduct, int userflag)
{
// std::cout << strPath << std::endl;
std::cout << strPath << std::endl;
// 1、获取 产品名称
std::string strProductName = Extract_Product_Name(strPath, userflag);
if (strProductName.empty())
@ -206,17 +206,15 @@ std::string Extract_ALL::Extract_Camera_Name(std::string strPath, int userflag)
fs::path p = fs::path(strPath);
std::string filename = p.stem();
// 文件名包含 CA 或 TA 即判定对应相机
// 支持旧格式: CA_20250508074237.ytimage
// 支持新格式: A_CAA.png, M_CAB.png (A_/M_ 仅是打光方式同属一个camera)
if (filename.find("TA") != std::string::npos)
return "TA";
else if (filename.find("CA") != std::string::npos)
return "CA";
// std::cout << "完整路径: " << p << std::endl;
// std::cout << "文件名: " << p.filename() << std::endl;
// std::cout << "不带后缀的文件名: " << p.stem() << std::endl;
// std::cout << "后缀: " << p.extension() << std::endl;
// getchar();
return "";
}
@ -248,6 +246,21 @@ std::string Extract_ALL::Extract_Channel_Name(std::string strPath, int userflag)
std::string strchannelName = "";
fs::path p = fs::path(strPath);
std::string filename = p.stem();
// 新格式: {Prefix}_{Type}{AB}, 如 A_CAA, M_TAB
// 通道名 = 前缀 (A/M), 表示不同打光方式
size_t underscorePos = filename.find('_');
if (underscorePos != std::string::npos)
{
std::string prefix = filename.substr(0, underscorePos);
std::string rest = filename.substr(underscorePos + 1);
if (rest == "CAA" || rest == "CAB" || rest == "TAA" || rest == "TAB")
{
return prefix; // "A" or "M"
}
}
// 旧格式兼容: CA_xxx.ytimage, TA_xxx.ytimage
if (filename.find("TAA") != std::string::npos)
strchannelName = "TA";
else if (filename.find("TAB") != std::string::npos)
@ -264,20 +277,20 @@ std::string Extract_ALL::Extract_Channel_Name(std::string strPath, int userflag)
}
int Extract_ALL::Read_Image_List(std::string strPath, std::string strproduct)
{
std::string strSearchImgPath = strPath + "/*.ytimage";
std::string strSearchImgPath = strPath + "/*.png";
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
// strSearchImgPath = strPath + "/*.png";
// Read_Camera_Product_Image(strSearchImgPath, 1);
strSearchImgPath = strPath + "/*.ytimage";
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
return 0;
}
int Extract_ALL::Read_Image_List(std::string strPath_left, std::string strPath_right, std::string strproduct)
{
std::string strSearchImgPath = strPath_left + "/*.ytimage";
std::string strSearchImgPath = strPath_left + "/*.png";
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
strSearchImgPath = strPath_right + "/*.ytimage";
strSearchImgPath = strPath_right + "/*.png";
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
// strSearchImgPath = strPath + "/*.png";

@ -400,8 +400,7 @@ int deal::preCheck()
strRoot2 = read.strpath_2;
printf("strSearchImg strRoot %s\n", strRoot.c_str());
std::ifstream file123(strRoot);
bool bhave = file123.good();
bool bhave = fs::exists(strRoot);
if (!bhave)
{
printf("read img path error %d %s\n", bhave, strRoot.c_str());
@ -416,14 +415,8 @@ int deal::preCheck()
Read_Image dfe;
int re = 0;
dfe.pimage_ReadChannel = &m_image_ReadChannel;
if (strRoot2 != "")
{
re = dfe.Read_Image_List(strSearchImg, strRoot2, strProductID);
}
else
{
re = dfe.Read_Image_List(strSearchImg, strProductID);
}
// 所有图片在同一个文件夹下,直接读取
re = dfe.Read_Image_List(strSearchImg, strProductID);
if (re != 0)
{
@ -455,26 +448,24 @@ int deal::preCheck()
AllImgNum = 0;
for (const auto pcam : product->camera_list)
{
std::shared_ptr<JC_IMAGE_INFO_> tem = std::make_shared<JC_IMAGE_INFO_>();
tem->strCamID = pcam->strCamName;
for (const auto pimage : pcam->image_list)
{
tem->strchannelName = pimage->strchannelName;
tem->strName = pimage->strName;
tem->strProductID = pimage->strProductID;
if (tem->strPath == "")
{
tem->strPath = pimage->strPath;
}
else
auto& imgList = pcam->image_list;
// 同一camera内按配对处理每两张图一组 (CAA+CAB / TAA+TAB)
// cv::glob 返回字母序,确保 A_CAA 在 A_CAB 前M_CAA 在 M_CAB 前
for (size_t i = 0; i < imgList.size(); i += 2)
{
std::shared_ptr<JC_IMAGE_INFO_> tem = std::make_shared<JC_IMAGE_INFO_>();
tem->strCamID = pcam->strCamName;
tem->strchannelName = imgList[i]->strchannelName;
tem->strName = imgList[i]->strName;
tem->strProductID = imgList[i]->strProductID;
tem->strPath = imgList[i]->strPath;
if (i + 1 < imgList.size())
{
tem->strPath_B = pimage->strPath;
tem->strPath_B = imgList[i + 1]->strPath;
}
InsertReadImgInfo(tem);
AllImgNum++;
}
InsertReadImgInfo(tem);
AllImgNum++;
// break;
}
// AllImgNum = 1;
{
@ -568,8 +559,7 @@ int deal::Testsaveimg()
strProductID = read.strproduct;
printf("strSearchImg strRoot %s\n", strRoot.c_str());
std::ifstream file123(strRoot);
bool bhave = file123.good();
bool bhave = fs::exists(strRoot);
if (!bhave)
{
printf("read img path error %d %s\n", bhave, strRoot.c_str());
@ -1127,7 +1117,8 @@ int deal::GetDetImageInfo(std::string strProductID, std::string strSearchImg, st
std::string strs1 = strSearchImg + "/*.ytimage";
if(!runConfig.bdecode)
{
strs1 = strSearchImg + "/*.jpg";
strs1 = strSearchImg + "/*.png";
cv::glob(strs1, img_paths, true);
}
cv::glob(strs1, img_paths, true);
// printf("%ld \n", img_paths.size());
@ -2026,12 +2017,22 @@ void deal::Thread_ReadImg(int id)
return;
}
// pImageInfo->img = cv::imread(pImageInfo->strPath, 0);
m_pextractImg->ReadCELLImg(pImageInfo->strPath, pImageInfo->img, runConfig.bdecode);
// cv::imwrite(pImageInfo->strchannelName + "_A_ssssde.png", pImageInfo->img);
if (pImageInfo->strPath_B != "")
if (!runConfig.bdecode)
{
// 不解码模式:直接用 opencv 读取图片
pImageInfo->img = cv::imread(pImageInfo->strPath, cv::IMREAD_GRAYSCALE);
if (pImageInfo->strPath_B != "")
{
pImageInfo->img_B = cv::imread(pImageInfo->strPath_B, cv::IMREAD_GRAYSCALE);
}
}
else
{
m_pextractImg->ReadCELLImg(pImageInfo->strPath_B, pImageInfo->img_B, runConfig.bdecode);
// cv::imwrite(pImageInfo->strchannelName + "_B_sssde.png", pImageInfo->img_B);
m_pextractImg->ReadCELLImg(pImageInfo->strPath, pImageInfo->img, runConfig.bdecode);
if (pImageInfo->strPath_B != "")
{
m_pextractImg->ReadCELLImg(pImageInfo->strPath_B, pImageInfo->img_B, runConfig.bdecode);
}
}
m_ReadImgThread_Result[id] = pImageInfo;

@ -501,7 +501,7 @@ struct DealRunConfig
RUNTYPE_ det_Type = RUNTYPE_RUN_Pre; // 处理
std::string filePath = ""; // 处理文件路径 如果为空 处理当前的单张图片
bool bSaveProcessImg = false; // 是否中间图片图片
bool bdecode = true; // 读图是否解密
bool bdecode = false; // 读图是否解密
void print(std::string str)
{
printf(">>>>>>>>>>>>>>> %s <<<<<<<<<<<<\n", str.c_str());

@ -259,25 +259,37 @@ int main(int argc, char *argv[])
continue;
}
// 构造输出路径(保持相对目录结构)
fs::path relativePath = fs::relative(imgPath, inputDir);
fs::path outputPath = fs::path(outputDir) / relativePath;
outputPath.replace_extension(".png"); // 统一保存为 PNG
// 提取 Product ID文件路径往上两级目录
std::string productId = imgPath.parent_path().parent_path().filename().string();
// 确保输出子目录存在
std::string outDir = outputPath.parent_path().string();
_sysmkdirs(outDir);
// 文件名 stem去掉 .ytimage 后缀)
std::string stem = imgPath.stem().string(); // e.g. "CAA"
// 保存
if (cv::imwrite(outputPath.string(), decoded))
// 输出目录outputDir / ProductID
fs::path outSubDir = fs::path(outputDir) / productId;
_sysmkdirs(outSubDir.string());
// 保存两份M_ 前缀 + A_ 前缀
bool ok = true;
for (const auto &prefix : {"M_", "A_"})
{
fs::path outPath = outSubDir / (std::string(prefix) + stem + ".png");
if (!cv::imwrite(outPath.string(), decoded))
{
printf("保存失败: %s\n", outPath.filename().c_str());
ok = false;
}
}
if (ok)
{
printf("OK → %s [%dx%d] (%ld ms)\n",
outputPath.filename().c_str(), decoded.cols, decoded.rows, elapsed);
printf("OK → %s/M_%s.png + A_%s.png [%dx%d] (%ld ms)\n",
productId.c_str(), stem.c_str(), stem.c_str(),
decoded.cols, decoded.rows, elapsed);
successCount++;
}
else
{
printf("保存失败\n");
failCount++;
}
}

Loading…
Cancel
Save