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.

183 lines
4.8 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;
// 图片信息
struct Image_Info
{
std::string strProductID; // 产品ID
std::string strCamID; // 相机名称
std::string strchannelName; // 通道名称
std::string strPath; // 完整路径
std::string strName; // 图片名称
cv::Mat img; // 图像数据
long readImg_start; // 读取开始时间
long readImg_end; // 读取结束时间
// 构造函数,调用 Init 初始化
Image_Info()
{
Init();
}
// 初始化函数,重置所有成员变量
void Init()
{
strProductID = "";
strCamID = "";
strchannelName = "";
strPath = "";
strName = "";
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 << "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 cam %ld\n", strProductID.c_str(),camera_list.size());
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, std::string strUseChannelName="") = 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, std::string strUseChannelName="") = 0;
int Read_Product_Image(std::string strPath);
int Read_Camera_Product_Image(std::string strPath,int userflag,std::string strproduct, std::string strUseChannelName="") ;
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 strUseChannelName="");
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, std::string strUseChannelName="");
};
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, std::string strUseChannelName="");
Extract_ALL m_extract;
Image_ReadChannel *pimage_ReadChannel;
private:
public:
vector<std::shared_ptr<Product_File_Info>> m_product_Camera_List; // 产品相机列表
};
#endif