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.
308 lines
7.1 KiB
308 lines
7.1 KiB
/*
|
|
* @Author: your name
|
|
* @Date: 2022-04-20 15:50:00
|
|
* @LastEditTime: 2025-09-11 22:03:50
|
|
* @LastEditors: xiewenji 527774126@qq.com
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/src/CamDeal.cpp
|
|
*/
|
|
|
|
#include "ConfigManager.h"
|
|
#include <regex>
|
|
#include "ConfigBase.h"
|
|
#include "../../AlgorithmModule/include/ImgCheckConfig.h"
|
|
|
|
ConfigManager::ConfigManager()
|
|
{
|
|
m_strConfigRootPath = "";
|
|
}
|
|
|
|
ConfigManager::~ConfigManager()
|
|
{
|
|
}
|
|
|
|
std::vector <std::string> QX_Result_Names =
|
|
{
|
|
"OK",
|
|
"AD_YX",
|
|
"X_Line",
|
|
"Y_Line",
|
|
"fangge",
|
|
"Rubbing_Mura",
|
|
"Broken_line",
|
|
"ZARA",
|
|
"MTX",
|
|
"POL_Cell",
|
|
"Bright_Point",
|
|
"Dark_Point",
|
|
"BLack_Point",
|
|
"White_Point",
|
|
"Scratch",
|
|
"Weak_Bright_Mura",
|
|
"No_Label",
|
|
"Bright_Mura_Exe",
|
|
"Sweak_Line_Dark",
|
|
"STEAM_POCKET",
|
|
"Dirty",
|
|
"other",
|
|
"Cell_W",
|
|
"Cell_B",
|
|
"LackPol"};
|
|
std::vector <std::string> QX_Result_Code =
|
|
{
|
|
"P1153",
|
|
"P6873",
|
|
"P3351",
|
|
"P3452",
|
|
"P3453",
|
|
"P1550",
|
|
"P3379",
|
|
"P1153",
|
|
"P1164",
|
|
"P1101",
|
|
"P1112",
|
|
"P1111",
|
|
"P1104",
|
|
"P1103",
|
|
"P1557",
|
|
"P1654",
|
|
"P2833",
|
|
"P1549",
|
|
"P1204",
|
|
"P2534",
|
|
"P2534",
|
|
"P1101",
|
|
"P1103",
|
|
"P1104",
|
|
"P8001",
|
|
};
|
|
|
|
int ReadFlawCodeConfig(std::string json_path)
|
|
{
|
|
m_FlawCodeList.erase(m_FlawCodeList.begin(), m_FlawCodeList.end());
|
|
std::string strPath = json_path;
|
|
printf("ReadFlawCodeConfig 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 0;
|
|
}
|
|
if (!Json::parseFromStream(builder, ifs, &root, &err))
|
|
{
|
|
printf("error:parseFromStream\n");
|
|
return 0;
|
|
}
|
|
|
|
for (int i = 0; i < root.size(); i++)
|
|
{
|
|
// printf("Node idx %d /%d \n", i, root.size());
|
|
|
|
ReadFlawCode tem;
|
|
tem.flaw_name = root[i]["zh_name"].asString();
|
|
tem.flaw_code = root[i]["en_name"].asString();
|
|
string desc = root[i]["desc"].asString();
|
|
{
|
|
|
|
std::istringstream stream(desc);
|
|
std::string token;
|
|
|
|
// 使用 getline 按照分号分割
|
|
while (std::getline(stream, token, ';'))
|
|
{
|
|
tem.config_flaw_name.push_back(token);
|
|
}
|
|
}
|
|
m_FlawCodeList.push_back(tem);
|
|
}
|
|
for(int i = 0; i < m_FlawCodeList.size(); i++)
|
|
{
|
|
if(i >= QX_Result_Names.size()) {
|
|
QX_Result_Names.push_back(m_FlawCodeList.at(i).flaw_name);
|
|
QX_Result_Code.push_back(m_FlawCodeList.at(i).flaw_code);
|
|
}
|
|
else
|
|
{
|
|
QX_Result_Names.at(i) = m_FlawCodeList.at(i).flaw_name;
|
|
QX_Result_Code.at(i) = m_FlawCodeList.at(i).flaw_code;
|
|
}
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int ConfigManager::LoadParamConfig(std::shared_ptr<ConfigBase> &Config, std::string strConfigPath)
|
|
{
|
|
Json::Reader json_reader;
|
|
Json::Value json_value;
|
|
std::ifstream infile(strConfigPath, ios::binary);
|
|
printf("Analysis_Config_path========== %s \n", strConfigPath.c_str());
|
|
// getchar();
|
|
if (infile.is_open())
|
|
{
|
|
if (json_reader.parse(infile, json_value))
|
|
{
|
|
|
|
Config->UpdateJSONConfig((void *)&json_value, ConfigType_Analysisy_Common_XL);
|
|
|
|
printf("m_pConfig ConfigType_Analysisy_Common_XL %s\n", Config->GetErrorInfo().c_str());
|
|
}
|
|
else
|
|
{
|
|
printf("****%s fail \n", strConfigPath.c_str());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf("****%s fail \n", strConfigPath.c_str());
|
|
infile.close();
|
|
return 1;
|
|
}
|
|
infile.close();
|
|
|
|
return 0;
|
|
}
|
|
int ConfigManager::LoadAnalysisConfig(std::string strConfigPath)
|
|
{
|
|
m_strConfigRootPath = strConfigPath;
|
|
int re = UpdateConfig();
|
|
return re;
|
|
}
|
|
|
|
std::string ConfigManager::GetJsonPath()
|
|
{
|
|
return m_strConfigRootPath;
|
|
}
|
|
|
|
int ConfigManager::UpdateConfig()
|
|
{
|
|
string defect_list_file = GetJsonPath();
|
|
if (defect_list_file == "") {
|
|
defect_list_file = "/var/aidlux/efs/model/defect_list.json";
|
|
}
|
|
else{
|
|
defect_list_file += "/defect_list.json";
|
|
}
|
|
ReadFlawCodeConfig(defect_list_file);
|
|
std::vector<CameraParam> camera_list;
|
|
int re = ReadParamName(camera_list);
|
|
if (re != 0)
|
|
{
|
|
printf("ConfigManager::UpdateConfig() ReadParamName error re = %d\n", re);
|
|
return re;
|
|
/* code */
|
|
}
|
|
for (auto &camera : camera_list)
|
|
{
|
|
std::string strConfigPath = m_strConfigRootPath + "/param_" + camera.code + ".json";
|
|
std::shared_ptr<ConfigBase> temConfig = ConfigBase::GetInstance();
|
|
re = LoadParamConfig(temConfig, strConfigPath);
|
|
if (re != 0)
|
|
{
|
|
printf("ConfigManager::UpdateConfig() LoadParamConfig %s error re = %d\n", strConfigPath.c_str(), re);
|
|
continue;
|
|
}
|
|
AnalysisyConfigST p;
|
|
temConfig->GetConfig(ConfigType_Analysisy_Common_XL, &p);
|
|
printf("********* CamearName %s\n", p.commonCheckConfig.baseConfig.strCamearName.c_str());
|
|
if (p.commonCheckConfig.baseConfig.strCamearName == "")
|
|
{
|
|
printf("Error >>>> camear Name is empty \n");
|
|
continue;
|
|
}
|
|
Config_instances_[p.commonCheckConfig.baseConfig.strCamearName] = temConfig;
|
|
}
|
|
|
|
// getchar();
|
|
|
|
// std::regex pattern(R"(param_[0-9]\.json)");
|
|
// if (!fs::exists(m_strConfigRootPath))
|
|
// {
|
|
// std::cerr << "目录不存在: " << m_strConfigRootPath << std::endl;
|
|
// return 1;
|
|
// }
|
|
// Config_instances_.clear();
|
|
// for (const auto &entry : fs::directory_iterator(m_strConfigRootPath))
|
|
// {
|
|
// if (entry.is_regular_file())
|
|
// {
|
|
// std::string filename = entry.path().filename().string();
|
|
// if (std::regex_match(filename, pattern))
|
|
// {
|
|
// std::cout << "匹配文件: " << entry.path() << std::endl;
|
|
// std::shared_ptr<ConfigBase> temConfig = ConfigBase::GetInstance();
|
|
// int re = LoadParamConfig(temConfig, entry.path());
|
|
// if (re != 0)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// AnalysisyConfigST p;
|
|
// temConfig->GetConfig(ConfigType_Analysisy_Common_XL, &p);
|
|
// printf("********* CamearName %s\n", p.commonCheckConfig.baseConfig.strCamearName.c_str());
|
|
// if (p.commonCheckConfig.baseConfig.strCamearName == "")
|
|
// {
|
|
// printf("Error >>>> camear Name is empty \n");
|
|
// continue;
|
|
// }
|
|
// Config_instances_[p.commonCheckConfig.baseConfig.strCamearName] = temConfig;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// std::cerr << "config error 2: " << m_strConfigRootPath << std::endl;
|
|
// }
|
|
// }
|
|
return 0;
|
|
}
|
|
int ConfigManager::GetConfig(int nConfigType, void *pconfig)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int ConfigManager::ReadParamName(std::vector<CameraParam> &camera_list)
|
|
{
|
|
std::string file_path = m_strConfigRootPath + "/camera_list.json";
|
|
|
|
Json::Reader json_reader;
|
|
Json::Value json_value;
|
|
std::ifstream infile(file_path, ios::binary);
|
|
|
|
if (!infile.is_open())
|
|
{
|
|
printf("****%s open fail\n", file_path.c_str());
|
|
return 1;
|
|
}
|
|
|
|
if (!json_reader.parse(infile, json_value))
|
|
{
|
|
printf("****%s parse fail\n", file_path.c_str());
|
|
infile.close();
|
|
return 1;
|
|
}
|
|
|
|
infile.close();
|
|
|
|
camera_list.clear();
|
|
for (const auto &camera : json_value)
|
|
{
|
|
CameraParam param;
|
|
param.identity = camera["identity"].asString();
|
|
param.code = camera["code"].asString();
|
|
param.desc = camera["desc"].asString();
|
|
param.name = camera["name"].asString();
|
|
param.created_at = camera["created_at"].asInt64();
|
|
|
|
printf("Camera: identity=%s, code=%s, name=%s, desc=%s, created_at=%ld\n",
|
|
param.identity.c_str(), param.code.c_str(), param.name.c_str(), param.desc.c_str(), param.created_at);
|
|
|
|
camera_list.push_back(param);
|
|
}
|
|
|
|
return 0;
|
|
}
|