|
|
#include "Image_ReadAndChange.h"
|
|
|
#include "json/json.h"
|
|
|
#include <sys/time.h>
|
|
|
#include <sys/types.h>
|
|
|
#include <sys/stat.h>
|
|
|
#include <unistd.h>
|
|
|
#include <string>
|
|
|
#include <map>
|
|
|
#include <iostream>
|
|
|
#include <string>
|
|
|
#include <string.h>
|
|
|
#include <fstream>
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include <mutex>
|
|
|
#include <unistd.h>
|
|
|
Image_ReadChannel::Image_ReadChannel()
|
|
|
{
|
|
|
m_ChannelNameList.clear();
|
|
|
}
|
|
|
|
|
|
Image_ReadChannel::~Image_ReadChannel()
|
|
|
{
|
|
|
}
|
|
|
bool Image_ReadChannel::containsChinese(const std::string &str)
|
|
|
{
|
|
|
for (size_t i = 0; i < str.size(); ++i)
|
|
|
{
|
|
|
if ((unsigned char)str[i] >= 0x80)
|
|
|
{
|
|
|
return true; // 如果有非ASCII字符(可能是中文)
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
bool Image_ReadChannel::CompareIgnoreCase(const std::string &str1, const std::string &str2)
|
|
|
{
|
|
|
// 将 str1 和 str2 转换为小写后进行比较
|
|
|
std::string lower_str1 = str1;
|
|
|
std::string lower_str2 = str2;
|
|
|
|
|
|
// 使用 std::transform 将字符串转换为小写
|
|
|
std::transform(lower_str1.begin(), lower_str1.end(), lower_str1.begin(), ::tolower);
|
|
|
std::transform(lower_str2.begin(), lower_str2.end(), lower_str2.begin(), ::tolower);
|
|
|
|
|
|
// 比较两个转换后的字符串
|
|
|
return lower_str1 == lower_str2;
|
|
|
}
|
|
|
int Image_ReadChannel::ReadJsonConfig(std::string json_path)
|
|
|
{
|
|
|
m_ChannelNameList.erase(m_ChannelNameList.begin(), m_ChannelNameList.end());
|
|
|
std::string strPath = json_path;
|
|
|
printf("ReadJsonConfig path %s\n", strPath.c_str());
|
|
|
Json::CharReaderBuilder builder;
|
|
|
builder["collectComments"] = true;
|
|
|
Json::Value root;
|
|
|
std::string err;
|
|
|
std::ifstream ifs(strPath);
|
|
|
if (!ifs.is_open())
|
|
|
{
|
|
|
printf("error:file is open\n");
|
|
|
return false;
|
|
|
}
|
|
|
if (!Json::parseFromStream(builder, ifs, &root, &err))
|
|
|
{
|
|
|
printf("error:parseFromStream\n");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < root.size(); i++)
|
|
|
{
|
|
|
printf("Node idx %d /%d \n", i, root.size());
|
|
|
|
|
|
ReadImageName tem;
|
|
|
tem.strDetChannle = root[i]["code"].asString();
|
|
|
std::string strimgname = root[i]["image_name"].asString();
|
|
|
{
|
|
|
|
|
|
std::istringstream stream(strimgname);
|
|
|
std::string token;
|
|
|
|
|
|
// 使用 getline 按照分号分割
|
|
|
while (std::getline(stream, token, ';'))
|
|
|
{
|
|
|
tem.strImgNameList.push_back(token);
|
|
|
}
|
|
|
}
|
|
|
printf("det name %s img name Num %ld \n", tem.strDetChannle.c_str(), tem.strImgNameList.size());
|
|
|
// 输出分割后的结果
|
|
|
for (const auto &str : tem.strImgNameList)
|
|
|
{
|
|
|
std::cout << str << std::endl;
|
|
|
}
|
|
|
|
|
|
m_ChannelNameList.push_back(tem);
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
std::string Image_ReadChannel::strDetName(std::string strImageName)
|
|
|
{
|
|
|
std::string strDetName = "";
|
|
|
for (const auto name : m_ChannelNameList)
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < name.strImgNameList.size(); i++)
|
|
|
{
|
|
|
// printf("strImageName %s name.strImgNameList.at(i) %s\n",strImageName.c_str(), name.strImgNameList.at(i).c_str());
|
|
|
// 包含中文
|
|
|
if (containsChinese(strImageName))
|
|
|
{
|
|
|
|
|
|
if (strImageName == name.strImgNameList.at(i))
|
|
|
{
|
|
|
return name.strDetChannle;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (CompareIgnoreCase(strImageName, name.strImgNameList.at(i)))
|
|
|
{
|
|
|
return name.strDetChannle;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return strDetName;
|
|
|
}
|