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.
280 lines
7.1 KiB
280 lines
7.1 KiB
#include "Read_Image.h"
|
|
#include <filesystem>
|
|
// 转小写
|
|
std::string toLower(const std::string &str)
|
|
{
|
|
std::string lower = str;
|
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
|
return lower;
|
|
}
|
|
|
|
int Extract_Name_Base::Read_Product_Image(std::string strPath)
|
|
{
|
|
|
|
return 0;
|
|
}
|
|
|
|
int Extract_Name_Base::Read_Camera_Product_Image(std::string strPath, int userflag, std::string strproduct, std::string strUseChannelName)
|
|
{
|
|
|
|
std::vector<cv::String> img_paths;
|
|
std::cout << strPath << std::endl;
|
|
cv::glob(strPath, img_paths, true);
|
|
for (int i = 0; i < img_paths.size(); i++)
|
|
{
|
|
string strImagePath = img_paths[i];
|
|
Extract_Info(strImagePath, strproduct, userflag, strUseChannelName);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int Extract_Name_Base::Read_Product_Camera_Image(std::string strPath)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
std::shared_ptr<Product_File_Info> Extract_Name_Base::GetProduct(std::string strProductID)
|
|
{
|
|
for (int i = 0; i < m_product_Camera_List.size(); i++)
|
|
{
|
|
if (m_product_Camera_List[i]->strProductID == strProductID)
|
|
{
|
|
return m_product_Camera_List[i];
|
|
}
|
|
}
|
|
return std::shared_ptr<Product_File_Info>();
|
|
}
|
|
|
|
std::shared_ptr<Camera_File_Info> Extract_Name_Base::GetCamera(std::string strProductID, std::string strCamName)
|
|
{
|
|
for (int i = 0; i < m_product_Camera_List.size(); i++)
|
|
{
|
|
if (m_product_Camera_List[i]->strProductID == strProductID)
|
|
{
|
|
for (int j = 0; j < m_product_Camera_List[i]->camera_list.size(); j++)
|
|
{
|
|
if (m_product_Camera_List[i]->camera_list[j]->strCamName == strCamName)
|
|
{
|
|
return m_product_Camera_List[i]->camera_list[j];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return std::shared_ptr<Camera_File_Info>();
|
|
}
|
|
|
|
std::shared_ptr<Camera_File_Info> Extract_Name_Base::GetCamera(std::shared_ptr<Product_File_Info> product, std::string strCamName)
|
|
{
|
|
for (int i = 0; i < product->camera_list.size(); i++)
|
|
{
|
|
if (product->camera_list[i]->strCamName == strCamName)
|
|
{
|
|
return product->camera_list[i];
|
|
}
|
|
}
|
|
return std::shared_ptr<Camera_File_Info>();
|
|
}
|
|
|
|
// 判断目录部分是否包含某些关键词(不区分大小写)
|
|
bool Extract_Name_Base::dirPathContains(const fs::path &fullPath, const std::string KeyName)
|
|
{
|
|
fs::path parentDir = fullPath.parent_path();
|
|
std::string lowKeyName = toLower(KeyName);
|
|
for (const auto &dir : parentDir)
|
|
{
|
|
std::string dirName = toLower(dir.string());
|
|
|
|
if (dirName == lowKeyName)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
Read_Image::Read_Image(/* args */)
|
|
{
|
|
}
|
|
|
|
Read_Image::~Read_Image()
|
|
{
|
|
}
|
|
|
|
int Read_Image::Read_Image_List(std::string strPath, std::string strproduct, std::string strUseChannelName)
|
|
{
|
|
m_extract.pimage_ReadChannel = pimage_ReadChannel;
|
|
m_extract.m_product_Camera_List.clear();
|
|
int re = m_extract.Read_Image_List(strPath, strproduct, strUseChannelName);
|
|
if (re != 0)
|
|
{
|
|
return re;
|
|
}
|
|
m_product_Camera_List.clear();
|
|
m_product_Camera_List.assign(m_extract.m_product_Camera_List.begin(), m_extract.m_product_Camera_List.end());
|
|
|
|
for (int i = 0; i < m_extract.m_product_Camera_List.size(); i++)
|
|
{
|
|
m_extract.m_product_Camera_List[i]->print();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int Extract_ALL::Extract_Info(std::string strPath, std::string strproduct, int userflag, std::string strUseChannelName)
|
|
{
|
|
std::cout << strPath << std::endl;
|
|
// 1、获取 产品名称
|
|
std::string strProductName = Extract_Product_Name(strPath, userflag);
|
|
if (strProductName.empty())
|
|
{
|
|
|
|
return -1;
|
|
}
|
|
|
|
std::shared_ptr<Product_File_Info> pProduct = GetProduct(strProductName);
|
|
if (strproduct != "" && strproduct != strProductName)
|
|
{
|
|
|
|
return -2;
|
|
}
|
|
|
|
if (pProduct.get() == nullptr)
|
|
{
|
|
printf("pProduct %s is NULL \n", strProductName.c_str());
|
|
pProduct = std::make_shared<Product_File_Info>();
|
|
pProduct->strProductID = strProductName;
|
|
m_product_Camera_List.push_back(pProduct);
|
|
}
|
|
// 2、获取 相机名称
|
|
std::string strCameraName = Extract_Camera_Name(strPath, userflag);
|
|
if (strCameraName.empty())
|
|
{
|
|
printf("strCameraName is error \n");
|
|
return -1;
|
|
}
|
|
std::shared_ptr<Camera_File_Info> pCamera = GetCamera(pProduct, strCameraName);
|
|
if (pCamera.get() == nullptr)
|
|
{
|
|
printf("pCamera %s is NULL \n", strCameraName.c_str());
|
|
pCamera = std::make_shared<Camera_File_Info>();
|
|
pCamera->strCamName = strCameraName;
|
|
pProduct->camera_list.push_back(pCamera);
|
|
}
|
|
|
|
// 3、获取 通道
|
|
std::string strChannelName = Extract_Channel_Name(strPath, userflag);
|
|
if (strChannelName.empty())
|
|
{
|
|
printf("strChannelName is NULL \n");
|
|
return -1;
|
|
}
|
|
if (strUseChannelName != "" && strChannelName != strUseChannelName)
|
|
{
|
|
return -2;
|
|
}
|
|
|
|
fs::path p = fs::path(strPath);
|
|
std::string filenameWithoutExt = p.stem().string();
|
|
// printf("filenameWithoutExt %s\n",filenameWithoutExt.c_str());
|
|
std::shared_ptr<Image_Info> pImage = std::make_shared<Image_Info>();
|
|
|
|
pImage->strProductID = strProductName;
|
|
pImage->strCamID = strCameraName;
|
|
pImage->strchannelName = strChannelName;
|
|
pImage->strName = filenameWithoutExt;
|
|
pImage->strPath = strPath;
|
|
pCamera->image_list.push_back(pImage);
|
|
|
|
return 0;
|
|
}
|
|
|
|
std::string Extract_ALL::Extract_Camera_Name(std::string strPath, int userflag)
|
|
{
|
|
if (strPath.find("right") != std::string::npos ||
|
|
strPath.find("Right") != std::string::npos ||
|
|
strPath.find("RIGHT") != std::string::npos)
|
|
{
|
|
return "right";
|
|
}
|
|
|
|
return "left";
|
|
}
|
|
bool is_valid_name(const std::string &name)
|
|
{
|
|
if (name.size() < 14 || name.size() > 18)
|
|
return false;
|
|
for (char c : name)
|
|
{
|
|
if (!std::isalnum(static_cast<unsigned char>(c)))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
std::string Extract_ALL::Extract_Product_Name(std::string strPath, int userflag)
|
|
{
|
|
|
|
// std::cout << strPath << std::endl;
|
|
fs::path p = fs::path(strPath);
|
|
fs::path dir = fs::is_directory(p) ? p : p.parent_path();
|
|
|
|
// std::cout << "目录: " << dir << "\n";
|
|
for (const auto &part : dir)
|
|
{
|
|
std::string folder = part.string();
|
|
if (folder.length() < 14)
|
|
{
|
|
continue;
|
|
}
|
|
std::string strproduct = "";
|
|
size_t pos = folder.rfind("__");
|
|
if (pos != std::string::npos)
|
|
{
|
|
// 提取 "__" 之后的内容
|
|
strproduct = folder.substr(pos + 2); // +2 跳过 "__" 的两个字符
|
|
}
|
|
else
|
|
{
|
|
strproduct = folder; // 如果没有找到 "__",返回原字符串
|
|
}
|
|
|
|
// std::cout << "folder: " << strproduct << "\n";
|
|
if (is_valid_name(strproduct))
|
|
{
|
|
return strproduct;
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
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();
|
|
std::cout << "filename " << filename << "\n";
|
|
|
|
size_t pos = filename.find('^');
|
|
if (pos != std::string::npos)
|
|
{
|
|
strchannelName = filename.substr(pos + 1);
|
|
}
|
|
|
|
// std::cout << "strchannelName " << strchannelName << "\n";
|
|
|
|
std::string strwebchannle = pimage_ReadChannel->strDetName(strchannelName);
|
|
|
|
std::cout << strchannelName << "-> " << strwebchannle << "\n";
|
|
return strwebchannle;
|
|
}
|
|
int Extract_ALL::Read_Image_List(std::string strPath, std::string strproduct, std::string strUseChannelName)
|
|
{
|
|
std::string strSearchImgPath = strPath + "/*.tif";
|
|
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct, strUseChannelName);
|
|
|
|
// strSearchImgPath = strPath + "/*.png";
|
|
// Read_Camera_Product_Image(strSearchImgPath, 1);
|
|
|
|
return 0;
|
|
} |