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.

202 lines
6.0 KiB

#ifndef Read_Image_HPP_
#define Read_Image_HPP_
#include <map>
#include <iostream>
#include <string>
#include <string.h>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <filesystem>
#include <opencv2/opencv.hpp>
#include "Image_ReadAndChange.h"
namespace fs = std::filesystem;
using namespace std;
// ==================== 图片命名解析 ====================
// 相机代码: BCA / BTA / DCA / DTA
// 目前支持两种图片命名方式:
// 1) {前缀}{相机}{A|B} 例: BCAA.jpg / A_BCAB.jpg / M_DTAB.jpg
// 末位 A = 左半, B = 右半
// 2) {前缀}_{相机}_{0|1}_{后缀} 例: 3ABD670013A8BG1_BCA_0_src.jpg
// 0 = 左半, 1 = 右半
// 两种命名的对应关系: BCA_0 等价于 BCAA, BCA_1 等价于 BCAB; BTA/DCA/DTA 同理。
//
// strStem : 去掉目录与扩展名的文件名
// strHalf : 输出半幅信息, "A"=左半, "B"=右半, 无法判定时为空
// 返回值 : 相机代码, 未识别到相机时返回空字符串
std::string Extract_Camera_And_Half(const std::string &strStem, std::string &strHalf);
// 图片信息
struct Image_Info
{
std::string strProductID; // 产品ID
std::string strCamID; // 相机名称
std::string strchannelName; // 通道名称
std::string strPath; // 完整路径
std::string strName; // 图片名称
std::string strHalf; // 半幅: "A"=左半(BCAA/…_0_), "B"=右半(BCAB/…_1_)
cv::Mat img; // 图像数据
long readImg_start; // 读取开始时间
long readImg_end; // 读取结束时间
// 构造函数,调用 Init 初始化
Image_Info()
{
Init();
}
// 初始化函数,重置所有成员变量
void Init()
{
strProductID = "";
strCamID = "";
strchannelName = "";
strPath = "";
strName = "";
strHalf = "";
img.release(); // 释放图像内存
readImg_start = 0;
readImg_end = 0;
}
void print()
{
std::cout << "Product ID: " << strProductID << std::endl;
std::cout << "Camera ID: " << strCamID << std::endl;
std::cout << "Channel Name: " << strchannelName << std::endl;
std::cout << "Image Path: " << strPath << std::endl;
std::cout << "Image Name: " << strName << std::endl;
std::cout << "Image Half: " << strHalf << std::endl;
std::cout << "Read Start Time: " << readImg_start << std::endl;
std::cout << "Read End Time: " << readImg_end << std::endl;
}
};
// 相机信息
struct Camera_File_Info
{
std::string strCamName; // 相机名称
std::string strCamPath; // 相机路径
vector<std::shared_ptr<Image_Info>> image_list; // 图片信息列表
Camera_File_Info()
{
Init();
}
void Init()
{
strCamName = "";
strCamPath = "";
}
int getImgNum()
{
int num = 0;
for (auto item : image_list)
{
num++;
}
return num;
}
void print()
{
printf("************CamName: %s img num %ld\n", strCamName.c_str(), image_list.size());
// for (auto &item : image_list)
// {
// // item->print();
// }
}
};
// 产品信息
struct Product_File_Info
{
std::string strProductID; // 产品ID
std::string strProductPath; // 产品路径
vector<std::shared_ptr<Camera_File_Info>> camera_list; // 相机信息列表
Product_File_Info()
{
Init();
}
void Init()
{
strProductID = "";
strProductPath = "";
}
int getImgNum()
{
int num = 0;
for (auto item : camera_list)
{
num += item->getImgNum();
}
return num;
}
void print()
{
printf("***strProductID: %s\n", strProductID.c_str());
for (auto &item : camera_list)
{
item->print();
}
}
};
class Extract_Name_Base
{
public:
virtual int Extract_Info(std::string strPath, std::string strproduct, int userflag) = 0;
virtual std::string Extract_Camera_Name(std::string strPath, int userflag = 0) = 0;
virtual std::string Extract_Product_Name(std::string strPath, int userflag = 0) = 0;
virtual std::string Extract_Channel_Name(std::string strPath, int userflag = 0) = 0;
virtual int Read_Image_List(std::string strPath, std::string strproduct) = 0;
virtual int Read_Image_List(std::string strPath_left, std::string strPath_right, std::string strproduct) = 0;
int Read_Product_Image(std::string strPath);
int Read_Camera_Product_Image(std::string strPath, int userflag, std::string strproduct);
int Read_Product_Camera_Image(std::string strPath);
std::shared_ptr<Product_File_Info> GetProduct(std::string strProductID);
std::shared_ptr<Camera_File_Info> GetCamera(std::string strProductID, std::string strCamName);
std::shared_ptr<Camera_File_Info> GetCamera(std::shared_ptr<Product_File_Info> product, std::string strCamName);
bool dirPathContains(const fs::path &fullPath, const std::string KeyName);
vector<std::shared_ptr<Product_File_Info>> m_product_Camera_List;
Image_ReadChannel *pimage_ReadChannel;
};
class Extract_ALL : public Extract_Name_Base
{
public:
int Extract_Info(std::string strPath, std::string strproduct, int userflag = 0);
std::string Extract_Camera_Name(std::string strPath, int userflag = 0);
std::string Extract_Product_Name(std::string strPath, int userflag = 0);
std::string Extract_Channel_Name(std::string strPath, int userflag = 0);
int Read_Image_List(std::string strPath, std::string strproduct);
int Read_Image_List(std::string strPath_left, std::string strPath_right, std::string strproduct);
};
class Read_Image
{
public:
// 图片文件的格式
enum Image_File_TYPE_
{
Image_File_Product_Image, // 产品-图片格式
Image_File_Camera_Product_Image, // 相机-产品-图片格式
Image_File_Product_Camera_Image, // 产品-相机-图片格式
};
public:
Read_Image(/* args */);
~Read_Image();
int Read_Image_List(std::string strPath, std::string strproduct);
int Read_Image_List(std::string strPath_left, std::string strPath_right, std::string strproduct);
Extract_ALL m_extract;
Image_ReadChannel *pimage_ReadChannel;
private:
public:
vector<std::shared_ptr<Product_File_Info>> m_product_Camera_List; // 产品相机列表
};
#endif