commit
50e9883a79
@ -0,0 +1,6 @@
|
||||
/build
|
||||
/lib
|
||||
/include
|
||||
/data
|
||||
/SaveImg
|
||||
.vscode/launch.json
|
||||
@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/usr/local/include/opencv4"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"cctype": "cpp",
|
||||
"clocale": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstdarg": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"cwctype": "cpp",
|
||||
"array": "cpp",
|
||||
"atomic": "cpp",
|
||||
"bitset": "cpp",
|
||||
"chrono": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"complex": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"filesystem": "cpp",
|
||||
"functional": "cpp",
|
||||
"iterator": "cpp",
|
||||
"map": "cpp",
|
||||
"memory": "cpp",
|
||||
"memory_resource": "cpp",
|
||||
"numeric": "cpp",
|
||||
"optional": "cpp",
|
||||
"random": "cpp",
|
||||
"ratio": "cpp",
|
||||
"set": "cpp",
|
||||
"string": "cpp",
|
||||
"string_view": "cpp",
|
||||
"system_error": "cpp",
|
||||
"tuple": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"fstream": "cpp",
|
||||
"future": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"iomanip": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"iostream": "cpp",
|
||||
"istream": "cpp",
|
||||
"limits": "cpp",
|
||||
"mutex": "cpp",
|
||||
"new": "cpp",
|
||||
"ostream": "cpp",
|
||||
"sstream": "cpp",
|
||||
"stdexcept": "cpp",
|
||||
"streambuf": "cpp",
|
||||
"thread": "cpp",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"bit": "cpp",
|
||||
"regex": "cpp",
|
||||
"shared_mutex": "cpp",
|
||||
"__nullptr": "cpp",
|
||||
"__split_buffer": "cpp",
|
||||
"__locale": "cpp",
|
||||
"__atomic": "cpp",
|
||||
"__bit_reference": "cpp",
|
||||
"__functional_base": "cpp",
|
||||
"__node_handle": "cpp",
|
||||
"__memory": "cpp",
|
||||
"locale": "cpp",
|
||||
"ios": "cpp",
|
||||
"__hash_table": "cpp",
|
||||
"__tree": "cpp",
|
||||
"queue": "cpp",
|
||||
"stack": "cpp",
|
||||
"__mutex_base": "cpp"
|
||||
},
|
||||
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json"
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
find_package( OpenCV REQUIRED )
|
||||
|
||||
message(STATUS "oPENCV Library status:")
|
||||
message(STATUS ">version:${OpenCV_VERSION}")
|
||||
message(STATUS "Include:${OpenCV_INCLUDE_DIRS}")
|
||||
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations")
|
||||
|
||||
find_package(CUDA REQUIRED)
|
||||
message(STATUS "cuda version: " ${CUDA_VERSION_STRING})
|
||||
message(STATUS "cuda CUDA_INCLUDE_DIRS: " ${CUDA_INCLUDE_DIRS})
|
||||
include_directories(${CUDA_INCLUDE_DIRS})
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/AIEngineModule/include
|
||||
${PROJECT_SOURCE_DIR}/AIEngineModule/include_base
|
||||
)
|
||||
|
||||
link_directories(
|
||||
/usr/local/lib/
|
||||
)
|
||||
set(CMAKE_CUDA_ARCHITECTURES 86)
|
||||
set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc")
|
||||
enable_language(CUDA)
|
||||
file(GLOB SRC_LISTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/AIEngineModule/src/*.cpp
|
||||
${PROJECT_SOURCE_DIR}/AIEngineModule/src/*.c
|
||||
${PROJECT_SOURCE_DIR}/AIEngineModule/src/*.cu
|
||||
)
|
||||
|
||||
add_executable("ai_test" ${SRC_LISTS})
|
||||
|
||||
target_link_libraries("ai_test"
|
||||
pthread
|
||||
z
|
||||
nvinfer
|
||||
${CUDA_LIBRARIES}
|
||||
${OpenCV_LIBS}
|
||||
)
|
||||
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-07-04 16:18:48
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-07-04 16:23:28
|
||||
* @FilePath: /AI_SO_Test/AIEngineModule/example/deal.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "deal.h"
|
||||
@ -0,0 +1,5 @@
|
||||
|
||||
#ifndef _deal_HPP_
|
||||
#define _deal_HPP_
|
||||
|
||||
#endif //_CORELOGICFACTORY_HPP_
|
||||
@ -0,0 +1,304 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-07-04 16:18:48
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-06 22:37:59
|
||||
* @FilePath: /AI_SO_Test/AIEngineModule/example/test_example.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <signal.h>
|
||||
#include "deal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
#include "AI_Factory.h"
|
||||
#include <chrono>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <sys/time.h>
|
||||
#include <sys/statfs.h>
|
||||
long getcurTime()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return ((long)tv.tv_sec) * 1000 + ((long)tv.tv_usec) / 1000;
|
||||
}
|
||||
void handler(int sig)
|
||||
{
|
||||
printf("Get handler sig");
|
||||
std::string strcmd = "ps -ef | grep test_JBL_Check| awk '{print $2}' | xargs kill -9 ";
|
||||
const char *cmd = strcmd.c_str();
|
||||
printf("delete test_JBL_Check success");
|
||||
if (-1 == system(cmd))
|
||||
{
|
||||
std::cout << "error" << std::endl;
|
||||
}
|
||||
|
||||
// delete UnderCarriageCoreLogic::GetInstance();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int _sysmkdir(const std::string &dir)
|
||||
{
|
||||
int ret = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||
if (ret && errno == EEXIST)
|
||||
{
|
||||
// printf("dir[%s] already exist.\n", dir.c_str());
|
||||
}
|
||||
else if (ret)
|
||||
{
|
||||
printf("create dir[%s] error: %d %s\n", dir.c_str(), ret, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("create dir[%s] success.\n", dir.c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
std::string __getParentDir(const std::string &dir)
|
||||
{
|
||||
std::string pdir = dir;
|
||||
if (pdir.length() < 1 || (pdir[0] != '/'))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
while (pdir.length() > 1 && (pdir[pdir.length() - 1] == '/'))
|
||||
pdir = pdir.substr(0, pdir.length() - 1);
|
||||
|
||||
pdir = pdir.substr(0, pdir.find_last_of('/'));
|
||||
return pdir;
|
||||
}
|
||||
int _sysmkdirs(const std::string &dir)
|
||||
{
|
||||
int ret = 0;
|
||||
if (dir.empty())
|
||||
return -1;
|
||||
std::string pdir;
|
||||
if ((ret = _sysmkdir(dir)) == -1)
|
||||
{
|
||||
pdir = __getParentDir(dir);
|
||||
if ((ret = _sysmkdirs(pdir)) == 0)
|
||||
{
|
||||
ret = _sysmkdirs(dir);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
std::shared_ptr<AIFactory> AI_Factory;
|
||||
AI_Factory = AIFactory::GetInstance();
|
||||
|
||||
GPU_Config gpu;
|
||||
gpu.gpu_0 = true;
|
||||
gpu.gpu_1 = true;
|
||||
|
||||
AI_Factory->InitALLAIModle(gpu);
|
||||
std::shared_ptr<AIModel_Base> BOE_Edge_Detect = AI_Factory->BOE_Edge_Detect;
|
||||
BOE_Edge_Detect->input_0.print();
|
||||
BOE_Edge_Detect->input_1.print();
|
||||
BOE_Edge_Detect->output_0.print();
|
||||
BOE_Edge_Detect->output_1.print();
|
||||
BOE_Edge_Detect->output_2.print();
|
||||
std::shared_ptr<AIModel_Base> JBL_Detect = AI_Factory->JBL_Detect;
|
||||
JBL_Detect->input_0.print();
|
||||
JBL_Detect->input_1.print();
|
||||
JBL_Detect->output_0.print();
|
||||
JBL_Detect->output_1.print();
|
||||
JBL_Detect->output_2.print();
|
||||
|
||||
cv::Mat temimg = cv::imread("../data/20250319_192154_Main_0_2_L255_Org.tif", 0);
|
||||
cv::Mat dealImg;
|
||||
printf("src img %d %d \n", temimg.cols, temimg.rows);
|
||||
|
||||
cv::Size sz = cv::Size(BOE_Edge_Detect->input_0.width, BOE_Edge_Detect->input_0.height);
|
||||
|
||||
cv::resize(temimg, dealImg, cv::Size(BOE_Edge_Detect->input_0.width, BOE_Edge_Detect->input_0.height));
|
||||
cv::Mat outimg;
|
||||
|
||||
BOE_Edge_Detect->AIDet(dealImg, outimg);
|
||||
cv::imwrite("outimg.png", outimg);
|
||||
|
||||
{
|
||||
long t1 = getcurTime();
|
||||
cv::Mat output;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
{
|
||||
cv::resize(temimg, dealImg, sz);
|
||||
BOE_Edge_Detect->AIDet(dealImg, outimg);
|
||||
}
|
||||
|
||||
long t2 = getcurTime();
|
||||
|
||||
// std::cout << "== run 1000 : " << t2 - t1 << " 毫秒" << std::endl;
|
||||
// cv::imwrite(name + "_output.jpg", output);
|
||||
// std::cout << "[" << name << "] done\n";
|
||||
};
|
||||
printf("========================\n");
|
||||
{
|
||||
long t1 = getcurTime();
|
||||
|
||||
// Lambda 线程函数
|
||||
auto run_detection = [](std::shared_ptr<AIModel_Base> engine, const cv::Mat &input, const cv::Size sz, const std::string &name)
|
||||
{
|
||||
cv::Mat output;
|
||||
for (int i = 0; i < 250; ++i)
|
||||
{
|
||||
cv::Mat dealImg123;
|
||||
cv::resize(input, dealImg123, sz);
|
||||
// printf("%s ---- \n",name.c_str());
|
||||
engine->AIDet(dealImg123, output);
|
||||
// cv::imwrite(name + "_" + std::to_string(i) + "_output.jpg", output);
|
||||
}
|
||||
// cv::imwrite(name + "_output.jpg", output);
|
||||
// std::cout << "[" << name << "] done\n";
|
||||
};
|
||||
|
||||
// 启动两个线程
|
||||
std::thread thread1(run_detection, BOE_Edge_Detect, temimg, sz, "manager1");
|
||||
std::thread thread2(run_detection, BOE_Edge_Detect, temimg, sz, "manager2");
|
||||
std::thread thread3(run_detection, BOE_Edge_Detect, temimg, sz, "manager3");
|
||||
std::thread thread4(run_detection, BOE_Edge_Detect, temimg, sz, "manager4");
|
||||
// std::thread thread5(run_detection, BOE_Edge_Detect, dealImg, "manager1");
|
||||
// std::thread thread6(run_detection, BOE_Edge_Detect, dealImg, "manager2");
|
||||
// std::thread thread7(run_detection, BOE_Edge_Detect, dealImg, "manager3");
|
||||
// std::thread thread8(run_detection, BOE_Edge_Detect, dealImg, "manager4");
|
||||
// 等待线程结束
|
||||
thread1.join();
|
||||
thread2.join();
|
||||
thread3.join();
|
||||
thread4.join();
|
||||
// thread5.join();
|
||||
// thread6.join();
|
||||
// thread7.join();
|
||||
// thread8.join();
|
||||
|
||||
long t2 = getcurTime();
|
||||
// std::cout << "run 1000 = thread 4 * 250 耗时: " << t2 - t1 << " 毫秒" << std::endl;
|
||||
}
|
||||
|
||||
cv::Mat dealImg123;
|
||||
cv::resize(temimg, dealImg123, cv::Size(JBL_Detect->input_0.width, JBL_Detect->input_0.height));
|
||||
float fss = 0;
|
||||
int rclass = JBL_Detect->AIClass(dealImg123, &fss);
|
||||
printf("test ------------rclass %d score %f\n", rclass, fss);
|
||||
// printf("%d %d\n", manager_1->BOE_Edge_Detect->m_img_In_0.width, manager_1->BOE_Edge_Detect->m_img_In_0.height);
|
||||
|
||||
// std::string strModelPath = "/home/aidlux/BOE/UseModel/Edge_Big.engine";
|
||||
// std::string strModelPath_jbl = "/home/aidlux/BOE/UseModel/class_14.engine";
|
||||
// std::shared_ptr<AIManagerBase> manager_1 = AIManagerBase::GetInstance(0);
|
||||
// std::shared_ptr<AIManagerBase> manager_2 = AIManagerBase::GetInstance(1);
|
||||
// std::shared_ptr<AIManagerBase> manager_3 = AIManagerBase::GetInstance(0);
|
||||
|
||||
// std::cout << "manager_1 instance address: " << manager_1.get() << std::endl;
|
||||
// std::cout << "manager_2 instance address: " << manager_2.get() << std::endl;
|
||||
// std::cout << "manager_3 instance address: " << manager_3.get() << std::endl;
|
||||
|
||||
// std::cout << "manager_1->BOE_Edge_Detect instance address: " << manager_1->BOE_Edge_Detect.get() << std::endl;
|
||||
// std::cout << "manager_2->BOE_Edge_Detect instance address: " << manager_2->BOE_Edge_Detect.get() << std::endl;
|
||||
// std::cout << "manager_3->BOE_Edge_Detect instance address: " << manager_3->BOE_Edge_Detect.get() << std::endl;
|
||||
|
||||
// std::cout << "manager_1->JBL_Detect instance address: " << manager_1->JBL_Detect.get() << std::endl;
|
||||
// std::cout << "manager_2->JBL_Detect instance address: " << manager_2->JBL_Detect.get() << std::endl;
|
||||
// std::cout << "manager_3->JBL_Detect instance address: " << manager_3->JBL_Detect.get() << std::endl;
|
||||
|
||||
// manager_1->BOE_Edge_Detect->Init(strModelPath);
|
||||
// manager_2->BOE_Edge_Detect->Init(strModelPath);
|
||||
// manager_3->BOE_Edge_Detect->Init(strModelPath);
|
||||
|
||||
// manager_1->JBL_Detect->Init(strModelPath_jbl);
|
||||
|
||||
// manager_2->JBL_Detect->Init(strModelPath_jbl);
|
||||
|
||||
// manager_3->JBL_Detect->Init(strModelPath_jbl);
|
||||
|
||||
// cv::Mat temimg = cv::imread("/home/aidlux/xwj/AI_SO_Test/data/img/20250319_192154_Main_0_2_L255_Org.tif", 0);
|
||||
// cv::Mat dealImg;
|
||||
// printf("%d %d\n", manager_1->BOE_Edge_Detect->m_img_In_0.width, manager_1->BOE_Edge_Detect->m_img_In_0.height);
|
||||
|
||||
// if (manager_1->BOE_Edge_Detect)
|
||||
// {
|
||||
// cv::resize(temimg, dealImg, cv::Size(manager_1->BOE_Edge_Detect->m_img_In_0.width, manager_1->BOE_Edge_Detect->m_img_In_0.height));
|
||||
// cv::Mat outimg;
|
||||
|
||||
// manager_1->BOE_Edge_Detect->AIDet(dealImg, outimg);
|
||||
// manager_2->BOE_Edge_Detect->AIDet(dealImg, outimg);
|
||||
|
||||
// {
|
||||
// long t1 = getcurTime();
|
||||
// cv::Mat output;
|
||||
// for (int i = 0; i < 500; ++i)
|
||||
// {
|
||||
// manager_1->BOE_Edge_Detect->AIDet(dealImg, output);
|
||||
// }
|
||||
// for (int i = 0; i < 500; ++i)
|
||||
// {
|
||||
// manager_1->BOE_Edge_Detect->AIDet(dealImg, output);
|
||||
// }
|
||||
// long t2 = getcurTime();
|
||||
|
||||
// std::cout << "run 1000 : " << t2 - t1 << " 毫秒" << std::endl;
|
||||
// // cv::imwrite(name + "_output.jpg", output);
|
||||
// // std::cout << "[" << name << "] done\n";
|
||||
// };
|
||||
|
||||
// long t1 = getcurTime();
|
||||
|
||||
// // Lambda 线程函数
|
||||
// auto run_detection = [](std::shared_ptr<AIEngineBase> engine, const cv::Mat &input, const std::string &name)
|
||||
// {
|
||||
// cv::Mat output;
|
||||
// for (int i = 0; i < 500; ++i)
|
||||
// {
|
||||
// engine->AIDet(input, output);
|
||||
// }
|
||||
// // cv::imwrite(name + "_output.jpg", output);
|
||||
// // std::cout << "[" << name << "] done\n";
|
||||
// };
|
||||
|
||||
// // 启动两个线程
|
||||
// std::thread thread1(run_detection, manager_1->BOE_Edge_Detect, dealImg, "manager1");
|
||||
// std::thread thread2(run_detection, manager_1->BOE_Edge_Detect, dealImg, "manager3");
|
||||
|
||||
// // 等待线程结束
|
||||
// thread1.join();
|
||||
// thread2.join();
|
||||
|
||||
// // for (int i = 0; i < 1000; i++)
|
||||
// // {
|
||||
// // manager_1->BOE_Edge_Detect->AIDet(dealImg, outimg);
|
||||
// // // manager_3->BOE_Edge_Detect->AIDet(dealImg, outimg);
|
||||
// // }
|
||||
|
||||
// long t2 = getcurTime();
|
||||
|
||||
// std::cout << "run 1000 = thread 2 * 500 耗时: " << t2 - t1 << " 毫秒" << std::endl;
|
||||
|
||||
// cv::imwrite("dealImg.jpg", dealImg);
|
||||
// cv::imwrite("outimg.jpg", outimg);
|
||||
// }
|
||||
|
||||
// cv::Mat dealImg123;
|
||||
// cv::resize(temimg, dealImg123, cv::Size(manager_1->JBL_Detect->m_img_In_0.width, manager_1->JBL_Detect->m_img_In_0.height));
|
||||
// float fss = 0;
|
||||
// int rclass = manager_1->JBL_Detect->AIClass(dealImg, &fss);
|
||||
// long t11 = getcurTime();
|
||||
// rclass = manager_1->JBL_Detect->AIClass(dealImg, &fss);
|
||||
// long t12 = getcurTime();
|
||||
// printf("test ------------rclass %d score %f------- time %ld\n", rclass, fss, t12 - t11);
|
||||
|
||||
// printf("test ------------------- \n");
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,220 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-06 22:23:08
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef AIModel_Impl_H_
|
||||
#define AIModel_Impl_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include "NvInfer.h"
|
||||
#include "cuda_runtime_api.h"
|
||||
#include "AI_Factory.h"
|
||||
#include "Engine.h"
|
||||
|
||||
using namespace std;
|
||||
// 模型输入输出最大允许的 节点数
|
||||
#define MAX_MODEL_NODE_NUM 5
|
||||
|
||||
class AIModel_Impl : public AIModel_Base
|
||||
{
|
||||
public:
|
||||
enum AI_Buffer_Type
|
||||
{
|
||||
AI_Buffer_Type_INPUT,
|
||||
AI_Buffer_Type_OUTPUT,
|
||||
AI_Buffer_Type_Count,
|
||||
};
|
||||
// 模型节点参数 一个模型包括多个节点,输入 输出。
|
||||
struct Node_Config : public AI_Image
|
||||
{
|
||||
int type;
|
||||
|
||||
std::string name;
|
||||
int ucharsize;
|
||||
int floatsize;
|
||||
int datalength;
|
||||
|
||||
Node_Config()
|
||||
{
|
||||
channel = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
type = AI_Buffer_Type_INPUT;
|
||||
name = "";
|
||||
ucharsize = 0;
|
||||
floatsize = 0;
|
||||
datalength = 0;
|
||||
}
|
||||
|
||||
void copy(Node_Config tem)
|
||||
{
|
||||
this->type = tem.type;
|
||||
this->channel = tem.channel;
|
||||
this->width = tem.width;
|
||||
this->height = tem.height;
|
||||
this->name = tem.name;
|
||||
this->ucharsize = tem.ucharsize;
|
||||
this->floatsize = tem.floatsize;
|
||||
this->datalength = tem.datalength;
|
||||
}
|
||||
void CalDataSize()
|
||||
{
|
||||
ucharsize = channel * width * height * sizeof(unsigned char);
|
||||
floatsize = channel * width * height * sizeof(float);
|
||||
datalength = channel * width * height;
|
||||
}
|
||||
};
|
||||
|
||||
// 流上的 节点参数信息。
|
||||
struct Stream_Node_Config
|
||||
{
|
||||
Node_Config nodeConfig;
|
||||
void *gpu_buffers;
|
||||
void *gpu_ImgData; // uchar
|
||||
|
||||
float *cpu_floatData;
|
||||
|
||||
Stream_Node_Config()
|
||||
{
|
||||
|
||||
gpu_buffers = NULL;
|
||||
gpu_ImgData = NULL;
|
||||
cpu_floatData = NULL;
|
||||
}
|
||||
~Stream_Node_Config()
|
||||
{
|
||||
if (gpu_buffers != NULL)
|
||||
{
|
||||
cudaFree(gpu_buffers);
|
||||
gpu_buffers = NULL;
|
||||
}
|
||||
|
||||
if (gpu_ImgData != NULL)
|
||||
{
|
||||
cudaFree(gpu_ImgData);
|
||||
gpu_ImgData = NULL;
|
||||
}
|
||||
if (cpu_floatData != NULL)
|
||||
{
|
||||
delete cpu_floatData;
|
||||
cpu_floatData = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// cuda上 一个流 包括的所有参数
|
||||
struct Cuda_Stream_Config
|
||||
{
|
||||
int nstreamIdx;
|
||||
cudaStream_t stream;
|
||||
std::unique_ptr<nvinfer1::IExecutionContext> context;
|
||||
std::shared_ptr<Stream_Node_Config> pstreamNode_input_0;
|
||||
std::shared_ptr<Stream_Node_Config> pstreamNode_input_1;
|
||||
std::shared_ptr<Stream_Node_Config> pstreamNode_output_0;
|
||||
std::shared_ptr<Stream_Node_Config> pstreamNode_output_1;
|
||||
std::shared_ptr<Stream_Node_Config> pstreamNode_output_2;
|
||||
std::vector<std::shared_ptr<Stream_Node_Config>> streamConfigList;
|
||||
Cuda_Stream_Config()
|
||||
{
|
||||
nstreamIdx = 0;
|
||||
streamConfigList.clear();
|
||||
pstreamNode_input_0 = nullptr;
|
||||
pstreamNode_input_1 = nullptr;
|
||||
pstreamNode_output_0 = nullptr;
|
||||
pstreamNode_output_1 = nullptr;
|
||||
pstreamNode_output_2 = nullptr;
|
||||
}
|
||||
~Cuda_Stream_Config()
|
||||
{
|
||||
|
||||
cudaStreamDestroy(stream);
|
||||
}
|
||||
};
|
||||
|
||||
// GPU 上封装的参数信息
|
||||
struct GPU_Engine
|
||||
{
|
||||
bool bsucc; // 是否初始化成功
|
||||
int nGPUIdx; // GPU id号
|
||||
std::shared_ptr<Engine> engine; // AI 模型 引擎
|
||||
std::vector<std::shared_ptr<Cuda_Stream_Config>> cudaSteams; // 所有流
|
||||
GPU_Engine()
|
||||
{
|
||||
nGPUIdx = 0;
|
||||
cudaSteams.clear();
|
||||
bsucc = false;
|
||||
}
|
||||
};
|
||||
// AI 检测 顺序调用 gpu stream 流。
|
||||
struct Det_GPU_Stram
|
||||
{
|
||||
std::mutex AI_mutex;
|
||||
int nGPUIdx;
|
||||
std::shared_ptr<Engine> engine; // AI 模型 引擎
|
||||
|
||||
std::shared_ptr<Cuda_Stream_Config> cuda_stream;
|
||||
Det_GPU_Stram()
|
||||
{
|
||||
|
||||
nGPUIdx = 0;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
AIModel_Impl();
|
||||
~AIModel_Impl();
|
||||
|
||||
// 初始化函数
|
||||
int Init(AIModelRun_Config config);
|
||||
int AIDet(const cv::Mat &inImg, cv::Mat &outimg);
|
||||
int AIDet(const cv::Mat &inImg, cv::Mat &outimg0, cv::Mat &outimg1);
|
||||
int AIClass(const cv::Mat &inImg, float *fmaxScore);
|
||||
|
||||
private:
|
||||
// 运行参数检查
|
||||
int ModelRunConfigCheck(AIModelRun_Config &runConfig);
|
||||
// 每个gpu 载入模型
|
||||
int LoadEngine(int ngpuIdx);
|
||||
// 解析 模型的信息
|
||||
int GetEngineInfo1(std::shared_ptr<GPU_Engine> &pgpuengine);
|
||||
|
||||
int AI_Det_In_1_Out_1(Node_Config *pConfig_in, Node_Config *pConfig_out, const unsigned char *p_indata_0, unsigned char *p_outdata_1);
|
||||
|
||||
int AI_Det_In_1_Out_1_class(unsigned char *p_indata_0, float *fmaxScore);
|
||||
int F2softmaxId(float *data, int class_num, float *fmaxScore);
|
||||
|
||||
private:
|
||||
// 调用相关函数
|
||||
int GetStream(std::shared_ptr<Det_GPU_Stram> &pdetStream);
|
||||
cv::Mat InitMat(int channel, int w, int h);
|
||||
|
||||
private:
|
||||
// 模型参数
|
||||
AIModelRun_Config m_modelRun_Config;
|
||||
// 模型的输入输出list
|
||||
std::vector<Node_Config> m_modelNodeList;
|
||||
|
||||
// 输入 输出节点
|
||||
Node_Config *m_pNode_input_0;
|
||||
Node_Config *m_pNode_input_1;
|
||||
Node_Config *m_pNode_output_0;
|
||||
Node_Config *m_pNode_output_1;
|
||||
Node_Config *m_pNode_output_2;
|
||||
// 引擎列表,一个 gpu 一个引擎
|
||||
std::vector<std::shared_ptr<GPU_Engine>> m_GPU_Engine;
|
||||
// 检测信息
|
||||
std::vector<std::shared_ptr<Det_GPU_Stram>> m_DetGPUStream;
|
||||
int m_nALLStreamNum;
|
||||
|
||||
private:
|
||||
// 上次使用的GPU stream Idx;
|
||||
int m_nLast_GPUStreamIdx;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-07-08 17:55:31
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef CUDA_Det_H_
|
||||
#define CUDA_Det_H_
|
||||
#include "cuda_runtime.h"
|
||||
#include "cublas_v2.h"
|
||||
#include "device_launch_parameters.h"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
void Cuda_ucharToFloat_stream(const unsigned char* input, float* output, int size, cudaStream_t stream);
|
||||
void Cuda_FloatTouchar_stream(const float* input, unsigned char* output, int size, cudaStream_t stream);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,588 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-09-03 10:44:31
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-06 22:29:55
|
||||
* @FilePath: /AI_SO_Test/AIEngineModule/src/AIModel_Impl.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
|
||||
#include "AIModel_Impl.h"
|
||||
#include "CUDA_DataChange.cuh"
|
||||
AIModel_Impl::AIModel_Impl()
|
||||
{
|
||||
m_bInitSuccess = false;
|
||||
m_GPU_Engine.clear();
|
||||
m_modelNodeList.clear();
|
||||
m_pNode_input_0 = NULL;
|
||||
m_pNode_input_1 = NULL;
|
||||
m_pNode_output_0 = NULL;
|
||||
m_pNode_output_1 = NULL;
|
||||
m_pNode_output_2 = NULL;
|
||||
m_DetGPUStream.clear();
|
||||
m_nLast_GPUStreamIdx = 0;
|
||||
m_nALLStreamNum = 0;
|
||||
}
|
||||
AIModel_Impl::~AIModel_Impl()
|
||||
{
|
||||
}
|
||||
int AIModel_Impl::Init(AIModelRun_Config config)
|
||||
{
|
||||
m_modelRun_Config.Copy(config);
|
||||
printf(">>> %s Init Start \n", m_modelRun_Config.strName.c_str());
|
||||
|
||||
if (m_bInitSuccess)
|
||||
{
|
||||
printf("strName %s Init Success %d ************ return \n", m_modelRun_Config.strName.c_str(), m_bInitSuccess);
|
||||
return 0;
|
||||
}
|
||||
int re = 0;
|
||||
re = ModelRunConfigCheck(m_modelRun_Config);
|
||||
if (re != 0)
|
||||
{
|
||||
printf("strName %s Init Error =%d run Config error \n", m_modelRun_Config.strName.c_str(), re);
|
||||
return re;
|
||||
}
|
||||
|
||||
// 不同显卡 单独 载入模型
|
||||
if (m_modelRun_Config.gpuconfig.gpu_0)
|
||||
{
|
||||
re = LoadEngine(0);
|
||||
// 加载失败
|
||||
if (re != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (m_modelRun_Config.gpuconfig.gpu_1)
|
||||
{
|
||||
re = LoadEngine(1);
|
||||
// 加载失败
|
||||
if (re != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
int nGPUNum = m_GPU_Engine.size();
|
||||
// 模型载入失败
|
||||
if (nGPUNum <= 0 || nGPUNum > 2)
|
||||
{
|
||||
printf(" %s model Init error \n", m_modelRun_Config.strName.c_str());
|
||||
return 2;
|
||||
}
|
||||
for (int i = 0; i < m_modelNodeList.size(); i++)
|
||||
{
|
||||
if (m_modelNodeList.at(i).type == AI_Buffer_Type_INPUT)
|
||||
{
|
||||
if (m_pNode_input_0 == NULL)
|
||||
{
|
||||
m_pNode_input_0 = &m_modelNodeList.at(i);
|
||||
input_0.copy(*m_pNode_input_0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pNode_input_1 = &m_modelNodeList.at(i);
|
||||
input_1.copy(*m_pNode_input_1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_pNode_output_0 == NULL)
|
||||
{
|
||||
m_pNode_output_0 = &m_modelNodeList.at(i);
|
||||
output_0.copy(*m_pNode_output_0);
|
||||
}
|
||||
else if (m_pNode_output_1 == NULL)
|
||||
{
|
||||
m_pNode_output_1 = &m_modelNodeList.at(i);
|
||||
output_1.copy(*m_pNode_output_1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pNode_output_2 = &m_modelNodeList.at(i);
|
||||
output_2.copy(*m_pNode_output_2);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (m_pNode_input_0 == NULL || m_pNode_output_0 == NULL)
|
||||
{
|
||||
printf(" %s model Init error \n", m_modelRun_Config.strName.c_str());
|
||||
return 3;
|
||||
}
|
||||
|
||||
int streamNum = m_GPU_Engine.at(0)->cudaSteams.size();
|
||||
|
||||
// 生产推理用的 参数信息
|
||||
if (m_GPU_Engine.size() > 1)
|
||||
{
|
||||
if (m_GPU_Engine.at(0)->cudaSteams.size() != m_GPU_Engine.at(1)->cudaSteams.size())
|
||||
{
|
||||
printf(" %s model Init error \n", m_modelRun_Config.strName.c_str());
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if (streamNum <= 0)
|
||||
{
|
||||
printf(" %s model Init streamNum error \n", m_modelRun_Config.strName.c_str());
|
||||
return 4;
|
||||
}
|
||||
|
||||
// 显示初始化信息
|
||||
if (true)
|
||||
{
|
||||
printf("Model Name :%s GUP engine Num %ld\n", m_modelRun_Config.strName.c_str(), m_GPU_Engine.size());
|
||||
|
||||
for (const auto &ge : m_GPU_Engine)
|
||||
{
|
||||
printf(" gpu %d status %d strem Num %ld \n", ge->nGPUIdx, ge->bsucc, ge->cudaSteams.size());
|
||||
|
||||
for (const auto &psteam : ge->cudaSteams)
|
||||
{
|
||||
printf(" steam %d \n", psteam->nstreamIdx);
|
||||
for (const auto &pcon : psteam->streamConfigList)
|
||||
{
|
||||
printf(" type %d [chw] %d %d %d input %p output %p\n",
|
||||
pcon->nodeConfig.type, pcon->nodeConfig.channel, pcon->nodeConfig.height, pcon->nodeConfig.width,
|
||||
pcon->gpu_buffers, pcon->gpu_ImgData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 把所有gup 的所有stream 都放到一起,方便调用。
|
||||
for (int i = 0; i < streamNum; i++)
|
||||
{
|
||||
|
||||
for (int igpu = 0; igpu < nGPUNum; igpu++)
|
||||
{
|
||||
std::shared_ptr<Det_GPU_Stram> temDetStream = std::make_shared<Det_GPU_Stram>();
|
||||
temDetStream->nGPUIdx = m_GPU_Engine.at(igpu)->nGPUIdx;
|
||||
temDetStream->engine = m_GPU_Engine.at(igpu)->engine;
|
||||
temDetStream->cuda_stream = m_GPU_Engine.at(igpu)->cudaSteams.at(i);
|
||||
m_DetGPUStream.push_back(temDetStream);
|
||||
}
|
||||
}
|
||||
m_nALLStreamNum = m_DetGPUStream.size();
|
||||
printf("========********* Model Name :%s GUP engine Num %ld **************=============\n", m_modelRun_Config.strName.c_str(), m_GPU_Engine.size());
|
||||
for (const auto steam : m_DetGPUStream)
|
||||
{
|
||||
printf(">>> gpu %d stream %d \n",
|
||||
steam->nGPUIdx, steam->cuda_stream->nstreamIdx);
|
||||
}
|
||||
|
||||
m_bInitSuccess = true;
|
||||
return 0;
|
||||
}
|
||||
cv::Mat AIModel_Impl::InitMat(int channel, int w, int h)
|
||||
{
|
||||
if (w <= 0 || h <= 0 || channel <= 0 || channel > 3)
|
||||
{
|
||||
return cv::Mat();
|
||||
}
|
||||
|
||||
cv::Mat dst;
|
||||
if (channel == 1)
|
||||
{
|
||||
dst = cv::Mat(h, w, CV_8UC1, cv::Scalar(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
dst = cv::Mat(h, w, CV_8UC3, cv::Scalar(0, 0, 0));
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
int AIModel_Impl::AIDet(const cv::Mat &inImg, cv::Mat &outimg)
|
||||
{
|
||||
|
||||
// 1、准备数据
|
||||
if (m_pNode_input_0 == NULL || m_pNode_output_0 == NULL)
|
||||
{
|
||||
printf("AIDet: Node Config INput output Node error \n");
|
||||
return 1;
|
||||
}
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(2)); // Sleep for 100 milliseconds
|
||||
uchar *p_indata_0 = (uchar *)inImg.data;
|
||||
outimg = InitMat(m_pNode_output_0->channel, m_pNode_output_0->width, m_pNode_output_0->height);
|
||||
uchar *p_outdata_1 = (uchar *)outimg.data;
|
||||
if (!m_bInitSuccess)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
AI_Det_In_1_Out_1(m_pNode_input_0, m_pNode_output_0, p_indata_0, p_outdata_1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AIModel_Impl::AIDet(const cv::Mat &inImg, cv::Mat &outimg0, cv::Mat &outimg1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AIModel_Impl::AIClass(const cv::Mat &inImg, float *fmaxScore)
|
||||
{
|
||||
// 1、准备数据
|
||||
if (m_pNode_input_0 == NULL || m_pNode_output_0 == NULL)
|
||||
{
|
||||
printf("AIDet: Node Config INput output Node error \n");
|
||||
return -1;
|
||||
}
|
||||
if (!m_bInitSuccess)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
uchar *p_indata_0 = (uchar *)inImg.data;
|
||||
|
||||
int class_dix = 0;
|
||||
class_dix = AI_Det_In_1_Out_1_class(p_indata_0, fmaxScore);
|
||||
|
||||
return class_dix;
|
||||
}
|
||||
|
||||
// 检测模型的运行参数是否合法,是否正常
|
||||
int AIModel_Impl::ModelRunConfigCheck(AIModelRun_Config &runConfig)
|
||||
{
|
||||
// GPU 数量判断
|
||||
if (runConfig.gpuconfig.GetNum() == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (runConfig.strPath == "")
|
||||
{
|
||||
printf(" %s model path is error \n", runConfig.strName.c_str());
|
||||
return 2;
|
||||
}
|
||||
if (runConfig.Stream_num <= 0)
|
||||
{
|
||||
runConfig.Stream_num = 1;
|
||||
}
|
||||
if (runConfig.Stream_num > 4)
|
||||
{
|
||||
runConfig.Stream_num = 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 载入模型。。。。
|
||||
int AIModel_Impl::LoadEngine(int ngpuIdx)
|
||||
{
|
||||
std::shared_ptr<GPU_Engine> gpuEngine = std::make_shared<GPU_Engine>();
|
||||
gpuEngine->engine = std::make_shared<Engine>(ngpuIdx);
|
||||
gpuEngine->nGPUIdx = ngpuIdx;
|
||||
if (!gpuEngine->engine)
|
||||
{
|
||||
printf("Engine Create error\n");
|
||||
return -1;
|
||||
}
|
||||
// 1、加载模型
|
||||
bool reload = gpuEngine->engine->loadFromFile(m_modelRun_Config.strPath);
|
||||
|
||||
if (!reload)
|
||||
{
|
||||
printf("GPU %d Load error %s\n", ngpuIdx, m_modelRun_Config.strPath.c_str());
|
||||
printf("Load model error\n");
|
||||
return -2;
|
||||
}
|
||||
printf("%s GPU %d Load succ %s\n", m_modelRun_Config.strName.c_str(), ngpuIdx, m_modelRun_Config.strPath.c_str());
|
||||
|
||||
// 2、 解析 egengine的 相关信息
|
||||
int re = GetEngineInfo1(gpuEngine);
|
||||
if (re != 0)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
// 没有输入输出 节点。
|
||||
if (m_modelNodeList.size() <= 0 || m_modelNodeList.size() > MAX_MODEL_NODE_NUM)
|
||||
{
|
||||
printf("Load model input output error\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
cudaSetDevice(ngpuIdx);
|
||||
// 3、 申请显存
|
||||
for (int i = 0; i < m_modelRun_Config.Stream_num; i++)
|
||||
{
|
||||
std::shared_ptr<Cuda_Stream_Config> cudasteam = std::make_shared<Cuda_Stream_Config>();
|
||||
cudasteam->nstreamIdx = i;
|
||||
|
||||
if (cudaStreamCreate(&cudasteam->stream) != cudaSuccess)
|
||||
{
|
||||
printf("Failed to create CUDA stream\n");
|
||||
return -4;
|
||||
}
|
||||
cudasteam->context = std::unique_ptr<nvinfer1::IExecutionContext>(
|
||||
gpuEngine->engine->engine_->createExecutionContext());
|
||||
// printf("----- stream %d \n", i);
|
||||
// 初始化 数据 内存
|
||||
for (int j = 0; j < m_modelNodeList.size(); j++)
|
||||
{
|
||||
std::shared_ptr<Stream_Node_Config> steamNodeconfig = std::make_shared<Stream_Node_Config>();
|
||||
steamNodeconfig->nodeConfig.copy(m_modelNodeList.at(j));
|
||||
|
||||
cudaMalloc(&steamNodeconfig->gpu_buffers, steamNodeconfig->nodeConfig.floatsize);
|
||||
cudaMalloc(&steamNodeconfig->gpu_ImgData, steamNodeconfig->nodeConfig.ucharsize);
|
||||
// 分类 的模型
|
||||
if (m_modelRun_Config.IsClass)
|
||||
{
|
||||
if (steamNodeconfig->cpu_floatData)
|
||||
{
|
||||
delete steamNodeconfig->cpu_floatData;
|
||||
steamNodeconfig->cpu_floatData = NULL;
|
||||
}
|
||||
|
||||
steamNodeconfig->cpu_floatData = new float[steamNodeconfig->nodeConfig.datalength];
|
||||
}
|
||||
|
||||
printf("-----******GPU %d stream %d cuda malloc %d inOrout %d [chw] %d*%d*%d \n",
|
||||
ngpuIdx, i, j, steamNodeconfig->nodeConfig.type, steamNodeconfig->nodeConfig.channel,
|
||||
steamNodeconfig->nodeConfig.height, steamNodeconfig->nodeConfig.width);
|
||||
|
||||
if (m_modelNodeList.at(j).type == AI_Buffer_Type_INPUT)
|
||||
{
|
||||
if (cudasteam->pstreamNode_input_0 == nullptr)
|
||||
{
|
||||
cudasteam->pstreamNode_input_0 = steamNodeconfig;
|
||||
}
|
||||
else
|
||||
{
|
||||
cudasteam->pstreamNode_input_1 = steamNodeconfig;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cudasteam->pstreamNode_output_0 == nullptr)
|
||||
{
|
||||
cudasteam->pstreamNode_output_0 = steamNodeconfig;
|
||||
}
|
||||
else if (cudasteam->pstreamNode_output_1 == nullptr)
|
||||
{
|
||||
cudasteam->pstreamNode_output_1 = steamNodeconfig;
|
||||
}
|
||||
else
|
||||
{
|
||||
cudasteam->pstreamNode_output_2 = steamNodeconfig;
|
||||
}
|
||||
}
|
||||
cudasteam->streamConfigList.push_back(steamNodeconfig);
|
||||
}
|
||||
gpuEngine->cudaSteams.push_back(cudasteam);
|
||||
}
|
||||
gpuEngine->bsucc = true;
|
||||
|
||||
m_GPU_Engine.push_back(gpuEngine);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AIModel_Impl::GetEngineInfo1(std::shared_ptr<GPU_Engine> &pgpuengine)
|
||||
{
|
||||
int nInputNum = pgpuengine->engine->getNbBindings();
|
||||
|
||||
m_modelNodeList.erase(m_modelNodeList.begin(), m_modelNodeList.end());
|
||||
m_modelNodeList.clear();
|
||||
|
||||
for (int i = 0; i < nInputNum; i++)
|
||||
{
|
||||
Node_Config node_config;
|
||||
|
||||
std::string name = pgpuengine->engine->getBindingName(i);
|
||||
node_config.name = name;
|
||||
Dims dims = pgpuengine->engine->getBindingDims(i);
|
||||
|
||||
if (pgpuengine->engine->bindingIsInput(i))
|
||||
{
|
||||
std::cout << "Input: " << name << "\n";
|
||||
node_config.type = AI_Buffer_Type_INPUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Output: " << name << "\n";
|
||||
node_config.type = AI_Buffer_Type_OUTPUT;
|
||||
}
|
||||
std::cout << "dims.nbDims: " << dims.nbDims << "\n";
|
||||
if (dims.nbDims == 4)
|
||||
{
|
||||
|
||||
switch (m_modelRun_Config.inputType)
|
||||
{
|
||||
case Input_CHW:
|
||||
node_config.channel = dims.d[1];
|
||||
node_config.height = dims.d[2];
|
||||
node_config.width = dims.d[3];
|
||||
break;
|
||||
case Input_HWC:
|
||||
|
||||
node_config.height = dims.d[1];
|
||||
node_config.width = dims.d[2];
|
||||
node_config.channel = dims.d[3];
|
||||
break;
|
||||
default:
|
||||
node_config.channel = dims.d[1];
|
||||
node_config.height = dims.d[2];
|
||||
node_config.width = dims.d[3];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (dims.nbDims == 3)
|
||||
{
|
||||
switch (m_modelRun_Config.inputType)
|
||||
{
|
||||
case Input_CHW:
|
||||
node_config.channel = dims.d[0];
|
||||
node_config.height = dims.d[1];
|
||||
node_config.width = dims.d[2];
|
||||
break;
|
||||
case Input_HWC:
|
||||
|
||||
node_config.height = dims.d[0];
|
||||
node_config.width = dims.d[1];
|
||||
node_config.channel = dims.d[2];
|
||||
break;
|
||||
default:
|
||||
node_config.channel = dims.d[0];
|
||||
node_config.height = dims.d[1];
|
||||
node_config.width = dims.d[2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (dims.nbDims == 2)
|
||||
{
|
||||
node_config.channel = 1;
|
||||
node_config.height = dims.d[0];
|
||||
node_config.width = dims.d[1];
|
||||
}
|
||||
else if (dims.nbDims == 1)
|
||||
{
|
||||
node_config.channel = 1;
|
||||
node_config.height = dims.d[0];
|
||||
node_config.width = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("engine C H W is error\n");
|
||||
return -2;
|
||||
}
|
||||
node_config.CalDataSize();
|
||||
|
||||
m_modelNodeList.push_back(node_config);
|
||||
printf("dim: ");
|
||||
for (int di = 0; di < dims.nbDims; di++)
|
||||
{
|
||||
printf(" %ld ", dims.d[di]);
|
||||
}
|
||||
printf(" \n");
|
||||
printf("C H W [%d %d %d]\n", node_config.channel, node_config.height, node_config.width);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AIModel_Impl::AI_Det_In_1_Out_1(Node_Config *pConfig_in, Node_Config *pConfig_out, const unsigned char *p_indata_0, unsigned char *p_outdata_1)
|
||||
{
|
||||
// printf("=== s1 ");
|
||||
std::shared_ptr<Det_GPU_Stram> pdetStream;
|
||||
GetStream(pdetStream);
|
||||
// printf("=== s2 ");
|
||||
std::lock_guard<std::mutex> lock(pdetStream->AI_mutex);
|
||||
// printf(" ss g %d s %d -- ", pdetStream->nGPUIdx, pdetStream->cuda_stream->nstreamIdx);
|
||||
// // 设置 显卡ID
|
||||
cudaSetDevice(pdetStream->nGPUIdx);
|
||||
|
||||
cudaMemcpyAsync(pdetStream->cuda_stream->pstreamNode_input_0->gpu_ImgData,
|
||||
p_indata_0, pConfig_in->ucharsize, cudaMemcpyHostToDevice, pdetStream->cuda_stream->stream);
|
||||
// // // 在显存中 图片数据从 uchar 转到 float
|
||||
Cuda_ucharToFloat_stream((unsigned char *)pdetStream->cuda_stream->pstreamNode_input_0->gpu_ImgData,
|
||||
(float *)pdetStream->cuda_stream->pstreamNode_input_0->gpu_buffers, pConfig_in->datalength, pdetStream->cuda_stream->stream);
|
||||
|
||||
pdetStream->cuda_stream->context->setTensorAddress(pConfig_in->name.c_str(), pdetStream->cuda_stream->pstreamNode_input_0->gpu_buffers);
|
||||
pdetStream->cuda_stream->context->setTensorAddress(pConfig_out->name.c_str(), pdetStream->cuda_stream->pstreamNode_output_0->gpu_buffers);
|
||||
|
||||
pdetStream->cuda_stream->context->enqueueV3(pdetStream->cuda_stream->stream);
|
||||
|
||||
Cuda_FloatTouchar_stream((float *)pdetStream->cuda_stream->pstreamNode_output_0->gpu_buffers,
|
||||
(unsigned char *)pdetStream->cuda_stream->pstreamNode_output_0->gpu_ImgData, pConfig_out->datalength, pdetStream->cuda_stream->stream);
|
||||
cudaMemcpyAsync(p_outdata_1, pdetStream->cuda_stream->pstreamNode_output_0->gpu_ImgData,
|
||||
pConfig_out->ucharsize, cudaMemcpyDeviceToHost, pdetStream->cuda_stream->stream);
|
||||
cudaStreamSynchronize(pdetStream->cuda_stream->stream);
|
||||
// printf("**ee g %d s %d ** \n", pdetStream->nGPUIdx, pdetStream->cuda_stream->nstreamIdx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AIModel_Impl::GetStream(std::shared_ptr<Det_GPU_Stram> &pdetStream)
|
||||
{
|
||||
int sidx = m_nLast_GPUStreamIdx;
|
||||
|
||||
sidx++;
|
||||
if (sidx >= m_nALLStreamNum)
|
||||
{
|
||||
sidx = 0;
|
||||
}
|
||||
pdetStream = m_DetGPUStream.at(sidx);
|
||||
m_nLast_GPUStreamIdx = sidx;
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AIModel_Impl::AI_Det_In_1_Out_1_class(unsigned char *p_indata_0, float *fmaxScore)
|
||||
{
|
||||
std::shared_ptr<Det_GPU_Stram> pdetStream;
|
||||
GetStream(pdetStream);
|
||||
// printf("=== s2 ");
|
||||
std::lock_guard<std::mutex> lock(pdetStream->AI_mutex);
|
||||
// printf(" ss g %d s %d -- ", pdetStream->nGPUIdx, pdetStream->cuda_stream->nstreamIdx);
|
||||
// // 设置 显卡ID
|
||||
std::shared_ptr<Stream_Node_Config> p_input_0 = pdetStream->cuda_stream->pstreamNode_input_0;
|
||||
std::shared_ptr<Stream_Node_Config> p_output_0 = pdetStream->cuda_stream->pstreamNode_output_0;
|
||||
cudaSetDevice(pdetStream->nGPUIdx);
|
||||
|
||||
cudaMemcpyAsync(p_input_0->gpu_ImgData, p_indata_0,
|
||||
p_input_0->nodeConfig.ucharsize, cudaMemcpyHostToDevice, pdetStream->cuda_stream->stream);
|
||||
// // // 在显存中 图片数据从 uchar 转到 float
|
||||
Cuda_ucharToFloat_stream((unsigned char *)p_input_0->gpu_ImgData,
|
||||
(float *)p_input_0->gpu_buffers, p_input_0->nodeConfig.datalength, pdetStream->cuda_stream->stream);
|
||||
|
||||
pdetStream->cuda_stream->context->setTensorAddress(p_input_0->nodeConfig.name.c_str(), p_input_0->gpu_buffers);
|
||||
pdetStream->cuda_stream->context->setTensorAddress(p_output_0->nodeConfig.name.c_str(), p_output_0->gpu_buffers);
|
||||
|
||||
pdetStream->cuda_stream->context->enqueueV3(pdetStream->cuda_stream->stream);
|
||||
|
||||
cudaMemcpyAsync(p_output_0->cpu_floatData, p_output_0->gpu_buffers,
|
||||
p_output_0->nodeConfig.floatsize, cudaMemcpyDeviceToHost, pdetStream->cuda_stream->stream);
|
||||
cudaStreamSynchronize(pdetStream->cuda_stream->stream);
|
||||
|
||||
int label = F2softmaxId(p_output_0->cpu_floatData, p_output_0->nodeConfig.datalength, fmaxScore);
|
||||
return label;
|
||||
}
|
||||
int AIModel_Impl::F2softmaxId(float *data, int class_num, float *fmaxScore)
|
||||
{
|
||||
int cls_num = class_num;
|
||||
float total = 0;
|
||||
for (int i = 0; i < cls_num; i++)
|
||||
{
|
||||
// std::cout<<"data["<<i<<"]="<<data[i]<<std::endl;
|
||||
total += exp(data[i]);
|
||||
}
|
||||
// std::cout<<"total="<<total<<std::endl;
|
||||
// std::vector<float> output;//这样才可以用push_back-但相比于=更耗时
|
||||
std::vector<float> output(cls_num);
|
||||
for (int i = 0; i < output.size(); i++)
|
||||
{
|
||||
float outi = (float)exp(data[i]) / (float)total;
|
||||
output[i] = outi;
|
||||
// output.push_back(outi);
|
||||
// std::cout<<"output["<<i<<"]="<<output[i]<<std::endl;
|
||||
}
|
||||
|
||||
int max_id = 0;
|
||||
float max_score = 0;
|
||||
for (int i = 0; i < output.size(); i++)
|
||||
{
|
||||
// std::cout << "output[" << i << "]=" << output[i] << std::endl;
|
||||
if (output[i] > max_score)
|
||||
{
|
||||
max_id = i;
|
||||
max_score = output[i];
|
||||
}
|
||||
}
|
||||
*fmaxScore = max_score;
|
||||
// std::cout << "F2softmaxId()----------------------------------max_score=" << max_score << std::endl; // 1023dyy
|
||||
// std::cout << "F2softmaxId()----------------------------------max_id=" << max_id << std::endl; // 1023dyy
|
||||
return max_id;
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-07-11 11:35:40
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-15 10:29:44
|
||||
* @FilePath: /BOE_Bounding/AIEngineModule/src/AIMulThreadRunBase.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "AI_Factory.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <sys/time.h>
|
||||
long getcurTime4444()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return ((long)tv.tv_sec) * 1000 + ((long)tv.tv_usec) / 1000;
|
||||
}
|
||||
AIMulThreadRunBase::AIMulThreadRunBase() : m_running_(false), m_processing_count_(0) {}
|
||||
|
||||
AIMulThreadRunBase::~AIMulThreadRunBase()
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
|
||||
void AIMulThreadRunBase::Start(int num_threads)
|
||||
{
|
||||
if (m_running_)
|
||||
return;
|
||||
m_running_ = true;
|
||||
m_detnum = 0;
|
||||
// num_threads = 2;
|
||||
// 仅启动1个线程
|
||||
for (int i = 0; i < num_threads; ++i)
|
||||
{
|
||||
m_workers_.emplace_back(&AIMulThreadRunBase::ThreadLoop, this);
|
||||
}
|
||||
}
|
||||
|
||||
void AIMulThreadRunBase::Stop()
|
||||
{
|
||||
m_running_ = false;
|
||||
m_task_cv_.notify_all();
|
||||
for (auto &t : m_workers_)
|
||||
{
|
||||
if (t.joinable())
|
||||
t.join();
|
||||
}
|
||||
m_workers_.clear();
|
||||
}
|
||||
|
||||
void AIMulThreadRunBase::SubmitTask(std::shared_ptr<AITask> task)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_task_mutex_);
|
||||
m_tasks_.push(task);
|
||||
}
|
||||
m_processing_count_++;
|
||||
m_task_cv_.notify_one();
|
||||
}
|
||||
|
||||
bool AIMulThreadRunBase::PopResult(std::shared_ptr<AITask> &result)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_result_mutex_);
|
||||
if (m_results_.empty())
|
||||
return false;
|
||||
result = m_results_.front();
|
||||
m_results_.pop();
|
||||
return true;
|
||||
}
|
||||
|
||||
void AIMulThreadRunBase::ThreadLoop()
|
||||
{
|
||||
while (m_running_)
|
||||
{
|
||||
|
||||
std::shared_ptr<AITask> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_task_mutex_);
|
||||
m_task_cv_.wait(lock, [this]()
|
||||
{ return !m_tasks_.empty() || !m_running_; });
|
||||
|
||||
if (!m_running_ && m_tasks_.empty())
|
||||
return;
|
||||
|
||||
task = std::move(m_tasks_.front());
|
||||
m_tasks_.pop();
|
||||
}
|
||||
if (task->bclass)
|
||||
{
|
||||
// 执行推理
|
||||
if (task->engine)
|
||||
{
|
||||
// std::lock_guard<std::mutex> lock(m_AI_mutex_);
|
||||
// long t1 = getcurTime4444();
|
||||
task->cls_label = task->engine->AIClass(task->input, &task->cls_score);
|
||||
// long t2 = getcurTime4444();
|
||||
// printf("det time %d m_tasks_ size %ld\n", t2 - t1,m_tasks_.size());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 执行推理
|
||||
if (task->engine && task->output)
|
||||
{
|
||||
// std::lock_guard<std::mutex> lock(m_AI_mutex_);
|
||||
// long t1 = getcurTime4444();
|
||||
task->engine->AIDet(task->input, *task->output);
|
||||
// long t2 = getcurTime4444();
|
||||
// printf("det time %d m_tasks_ size %ld\n", t2 - t1,m_tasks_.size());
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_result_mutex_);
|
||||
m_results_.push(task);
|
||||
}
|
||||
// m_detnum++;
|
||||
m_processing_count_--;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-09-03 10:33:48
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-14 20:28:10
|
||||
* @FilePath: /AI_SO_Test/AIEngineModule/src/AI_Factory.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "AI_Factory.h"
|
||||
|
||||
#include "AIModel_Impl.h"
|
||||
|
||||
std::shared_ptr<AIModel_Base> AIModel_Base::GetInstance()
|
||||
{
|
||||
std::shared_ptr<AIModel_Base> instance = std::make_shared<AIModel_Impl>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
AIFactory::AIFactory()
|
||||
{
|
||||
}
|
||||
|
||||
AIFactory::~AIFactory()
|
||||
{
|
||||
}
|
||||
std::shared_ptr<AIFactory> AIFactory::GetInstance()
|
||||
{
|
||||
static std::shared_ptr<AIFactory> instance = std::make_shared<AIFactory>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
int AIFactory::InitALLAIModle(GPU_Config gupconfig)
|
||||
{
|
||||
if (gupconfig.GetNum() == 0)
|
||||
{
|
||||
printf("GPU Num Error \n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!CELL_CA_Det)
|
||||
{
|
||||
CELL_CA_Det = AIModel_Base::GetInstance();
|
||||
AIModel_Base::AIModelRun_Config edge_config;
|
||||
edge_config.gpuconfig.copy(gupconfig);
|
||||
edge_config.strPath = "/home/aidlux/BOE/UseModel_CellAOI/Detect_CA.engine";
|
||||
edge_config.strName = "CA_Det";
|
||||
edge_config.inputType = AIModel_Base::Input_HWC;
|
||||
edge_config.Stream_num = 2;
|
||||
CELL_CA_Det->Init(edge_config);
|
||||
}
|
||||
if (!CELL_TA_Det)
|
||||
{
|
||||
CELL_TA_Det = AIModel_Base::GetInstance();
|
||||
AIModel_Base::AIModelRun_Config edge_config;
|
||||
edge_config.gpuconfig.copy(gupconfig);
|
||||
edge_config.strPath = "/home/aidlux/BOE/UseModel_CellAOI/Detect_TA.engine";
|
||||
edge_config.strName = "TA_Det";
|
||||
edge_config.inputType = AIModel_Base::Input_HWC;
|
||||
edge_config.Stream_num = 2;
|
||||
CELL_TA_Det->Init(edge_config);
|
||||
}
|
||||
if (!CELL_Align)
|
||||
{
|
||||
CELL_Align = AIModel_Base::GetInstance();
|
||||
AIModel_Base::AIModelRun_Config edge_config;
|
||||
edge_config.gpuconfig.copy(gupconfig);
|
||||
edge_config.strPath = "/home/aidlux/BOE/UseModel_CellAOI/Align.engine";
|
||||
edge_config.strName = "Align";
|
||||
edge_config.inputType = AIModel_Base::Input_HWC;
|
||||
CELL_Align->Init(edge_config);
|
||||
}
|
||||
if (!CELL_Mark)
|
||||
{
|
||||
CELL_Mark = AIModel_Base::GetInstance();
|
||||
AIModel_Base::AIModelRun_Config edge_config;
|
||||
edge_config.gpuconfig.copy(gupconfig);
|
||||
edge_config.strPath = "/home/aidlux/BOE/UseModel_CellAOI/Cell_marker.engine";
|
||||
edge_config.strName = "Mark";
|
||||
edge_config.inputType = AIModel_Base::Input_HWC;
|
||||
CELL_Mark->Init(edge_config);
|
||||
}
|
||||
if (!CELL_CA_Cls)
|
||||
{
|
||||
CELL_CA_Cls = AIModel_Base::GetInstance();
|
||||
AIModel_Base::AIModelRun_Config jbl_config;
|
||||
jbl_config.gpuconfig.copy(gupconfig);
|
||||
jbl_config.strPath = "/home/aidlux/BOE/UseModel_CellAOI/Class_10.engine";
|
||||
jbl_config.inputType = AIModel_Base::Input_HWC;
|
||||
jbl_config.strName = "CA_Class";
|
||||
jbl_config.IsClass = true;
|
||||
CELL_CA_Cls->Init(jbl_config);
|
||||
}
|
||||
if (!CELL_TA_Cls)
|
||||
{
|
||||
CELL_TA_Cls = AIModel_Base::GetInstance();
|
||||
AIModel_Base::AIModelRun_Config jbl_config;
|
||||
jbl_config.gpuconfig.copy(gupconfig);
|
||||
jbl_config.strPath = "/home/aidlux/BOE/UseModel_CellAOI/Class_10_TA.engine";
|
||||
jbl_config.inputType = AIModel_Base::Input_HWC;
|
||||
jbl_config.strName = "TA_Class";
|
||||
jbl_config.IsClass = true;
|
||||
CELL_TA_Cls->Init(jbl_config);
|
||||
}
|
||||
m_bInitSucc = true;
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
|
||||
#include "CUDA_DataChange.cuh"
|
||||
|
||||
__global__ void ucharToFloat_stream(const unsigned char *input, float *output, int size)
|
||||
{
|
||||
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (tid < size)
|
||||
{
|
||||
output[tid] = static_cast<float>(input[tid]);
|
||||
}
|
||||
}
|
||||
__global__ void floatToUchar_stream(const float *input, unsigned char *output, int size)
|
||||
{
|
||||
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (tid < size)
|
||||
{
|
||||
output[tid] = static_cast<unsigned char>(input[tid]);
|
||||
}
|
||||
}
|
||||
|
||||
void Cuda_ucharToFloat_stream(const unsigned char *input, float *output, int size, cudaStream_t stream)
|
||||
{
|
||||
int blockSize = 1024;
|
||||
int numBlocks = (size + blockSize - 1) / blockSize;
|
||||
ucharToFloat_stream<<<numBlocks, blockSize, 0, stream>>>(input, output, size);
|
||||
}
|
||||
|
||||
void Cuda_FloatTouchar_stream(const float *input, unsigned char *output, int size, cudaStream_t stream)
|
||||
{
|
||||
|
||||
int blockSize = 1024;
|
||||
int numBlocks = (size + blockSize - 1) / blockSize;
|
||||
floatToUchar_stream<<<numBlocks, blockSize, 0, stream>>>(input, output, size);
|
||||
}
|
||||
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-07-05 19:32:41
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-06 11:13:54
|
||||
* @FilePath: /AI_SO_Test/AIEngineModule/src/Engine.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "Engine.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <cuda_runtime_api.h>
|
||||
|
||||
using namespace nvinfer1;
|
||||
|
||||
class Logger : public ILogger
|
||||
{
|
||||
public:
|
||||
void log(Severity severity, const char *msg) noexcept override
|
||||
{
|
||||
if (severity <= Severity::kWARNING)
|
||||
std::cout << "[TensorRT] " << msg << std::endl;
|
||||
}
|
||||
} gLogger;
|
||||
// 实现自定义删除器
|
||||
void TensorRTDeleter::operator()(nvinfer1::IRuntime *ptr) const noexcept
|
||||
{
|
||||
// if (ptr)
|
||||
// {
|
||||
// printf("************ IRuntime \n");
|
||||
// // delete ptr;
|
||||
// }
|
||||
}
|
||||
void TensorRTDeleter::operator()(nvinfer1::IExecutionContext *ptr) const noexcept
|
||||
{
|
||||
// if (!ptr)
|
||||
// return;
|
||||
|
||||
// try
|
||||
// {
|
||||
// printf("************ IExecutionContext \n");
|
||||
// // 检查有效性、上下文等
|
||||
// delete ptr;
|
||||
// }
|
||||
// catch (const std::exception &e)
|
||||
// {
|
||||
// std::cerr << "[Deleter] Exception: " << e.what() << "\n";
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// std::cerr << "[Deleter] Unknown error during deletion\n";
|
||||
// }
|
||||
}
|
||||
void TensorRTDeleter::operator()(nvinfer1::ICudaEngine *ptr) const noexcept
|
||||
{
|
||||
// if (ptr)
|
||||
// {
|
||||
// printf("************ ICudaEngine \n");
|
||||
// delete ptr;
|
||||
// }
|
||||
// if (ptr)
|
||||
// {
|
||||
// printf("************ ICudaEngine \n");
|
||||
// try
|
||||
// {
|
||||
// // delete ptr; //
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// std::cerr << "[Deleter] Exception deleting ICudaEngine\n";
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Engine::Engine(int gpuId) : gpuId_(gpuId) {}
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
// printf("========Engine= start ====\n");
|
||||
// engine_.reset();
|
||||
// runtime_.reset();
|
||||
// printf("========Engine= engine_.reset();====\n");
|
||||
}
|
||||
|
||||
bool Engine::loadFromFile(const std::string &enginePath)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
cudaSetDevice(gpuId_);
|
||||
std::ifstream file(enginePath, std::ios::binary);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "[Engine] Failed to open engine file: " << enginePath << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.seekg(0, file.end);
|
||||
size_t size = file.tellg();
|
||||
file.seekg(0, file.beg);
|
||||
std::vector<char> engineData(size);
|
||||
file.read(engineData.data(), size);
|
||||
runtime_ = std::unique_ptr<IRuntime, TensorRTDeleter>(createInferRuntime(gLogger));
|
||||
if (!runtime_)
|
||||
{
|
||||
std::cerr << "[Engine] Failed to create runtime." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
engine_ = std::unique_ptr<ICudaEngine, TensorRTDeleter>(
|
||||
runtime_->deserializeCudaEngine(engineData.data(), size));
|
||||
|
||||
if (!engine_)
|
||||
{
|
||||
std::cerr << "[Engine] Failed to deserialize engine." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << "[Engine] Exception during loadFromFile: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << "[Engine] Unknown exception during loadFromFile." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int Engine::getNbBindings() const
|
||||
{
|
||||
return engine_ ? engine_->getNbIOTensors() : 0;
|
||||
}
|
||||
|
||||
std::string Engine::getBindingName(int index) const
|
||||
{
|
||||
return engine_ ? engine_->getIOTensorName(index) : "";
|
||||
}
|
||||
|
||||
Dims Engine::getBindingDims(int index) const
|
||||
{
|
||||
if (!engine_)
|
||||
return Dims{};
|
||||
std::string name = engine_->getIOTensorName(index);
|
||||
return engine_->getTensorShape(name.c_str());
|
||||
}
|
||||
|
||||
bool Engine::bindingIsInput(int index) const
|
||||
{
|
||||
if (!engine_)
|
||||
return false;
|
||||
std::string name = engine_->getIOTensorName(index);
|
||||
return engine_->getTensorIOMode(name.c_str()) == TensorIOMode::kINPUT;
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-17 19:09:40
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef AICommonDefine_H_
|
||||
#define AICommonDefine_H_
|
||||
|
||||
// AI缺陷分类缺陷的种类
|
||||
enum AI_CLass_QX_NAME_
|
||||
{
|
||||
|
||||
AI_CLass_QX_NAME_aotudian, // 凹凸点
|
||||
AI_CLass_QX_NAME_other, // 其他
|
||||
AI_CLass_QX_NAME_line, // 线状
|
||||
AI_CLass_QX_NAME_zangwu, // 脏污
|
||||
AI_CLass_QX_NAME_dianzhuang, // 点状
|
||||
AI_CLass_QX_NAME_posun, // 破损
|
||||
AI_CLass_QX_NAME_xianwei, // 纤维
|
||||
AI_CLass_QX_NAME_shuizi, // 水渍
|
||||
AI_CLass_QX_NAME_danban, // 淡斑
|
||||
AI_CLass_QX_NAME_fuchen, // 浮尘
|
||||
AI_CLass_QX_NAME_count,
|
||||
};
|
||||
// 缺陷项对应在参数中的名称
|
||||
static const std::string AI_CLass_QX_NAME_Names[] =
|
||||
{
|
||||
"aotudian",
|
||||
"qx",
|
||||
"line",
|
||||
"zangwu",
|
||||
"dianzhuang",
|
||||
"posun",
|
||||
"xianwei",
|
||||
"shuizi",
|
||||
"danban",
|
||||
"fuchen",
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,236 @@
|
||||
/*
|
||||
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
||||
*/
|
||||
#ifndef AI_Edge_Algin_H_
|
||||
#define AI_Edge_Algin_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "CheckUtil.hpp"
|
||||
#include "OtherDetBaseDefine.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "CheckConfigDefine.h"
|
||||
#include "ImageStorage.h"
|
||||
#include "AI_Factory.h"
|
||||
#include "DetLog.h"
|
||||
using namespace std;
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class AI_Edge_Algin
|
||||
{
|
||||
public:
|
||||
enum Mark_Result_Status
|
||||
{
|
||||
Mark_Result_Status_NULL,
|
||||
Mark_Result_Status_OK,
|
||||
Mark_Result_Status_Error,
|
||||
};
|
||||
struct MarK_Result
|
||||
{
|
||||
Mark_Result_Status status;
|
||||
cv::Rect SearchROI_DetImg; // 相对于 检测图的 搜索区域;
|
||||
cv::Point param_Local_DetImg; // mark的参数位置,相对于检测图片
|
||||
cv::Point det_Local_DetImg; // 检测结果 相对于 检测图片
|
||||
|
||||
cv::Rect SearchROI_SrcImg; // 相对于 检测图的 搜索区域;
|
||||
cv::Point param_Local_SrcImg; // mark的参数位置,相对于检测图片
|
||||
cv::Point det_Local_SrcImg; // 检测结果 相对于 检测图片
|
||||
MarK_Result()
|
||||
{
|
||||
status = Mark_Result_Status_NULL;
|
||||
SearchROI_DetImg = cv::Rect(0, 0, 0, 0);
|
||||
param_Local_DetImg = cv::Point(0, 0);
|
||||
det_Local_DetImg = cv::Point(0, 0);
|
||||
|
||||
SearchROI_SrcImg = cv::Rect(0, 0, 0, 0);
|
||||
param_Local_SrcImg = cv::Point(0, 0);
|
||||
det_Local_SrcImg = cv::Point(0, 0);
|
||||
}
|
||||
};
|
||||
// 边缘搜索定位结果
|
||||
struct Edge_AI_Result
|
||||
{
|
||||
int nresult;
|
||||
cv::Rect roi;
|
||||
bool buseOfft;
|
||||
int offt_x;
|
||||
int offt_y;
|
||||
cv::Mat H;
|
||||
|
||||
std::vector<MarK_Result> markresulList;
|
||||
|
||||
Edge_AI_Result()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
buseOfft = false;
|
||||
nresult = 0;
|
||||
offt_x = 0;
|
||||
offt_y = 0;
|
||||
roi = cv::Rect(0, 0, 0, 0);
|
||||
markresulList.clear();
|
||||
if (!H.empty())
|
||||
{
|
||||
H.release();
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
enum SaveProcessType
|
||||
{
|
||||
Save_Close, // 不保存
|
||||
Save_Filter, // 过滤的
|
||||
Save_ALL, // 全部
|
||||
};
|
||||
|
||||
/// @brief 检测过程的参数
|
||||
struct DetConfig
|
||||
{
|
||||
int ncamId; // 相机ID
|
||||
BaseCheckFunction *pBaseCheckFunction;
|
||||
std::string strChannel; // 通道
|
||||
int nthresholdvalue; // 背景阈值
|
||||
int nAIErodesize; // 边缘腐蚀强度
|
||||
bool bSaveResultImg; // 保存结果图片
|
||||
SaveProcessType saveProcessImg; // 保存过程图片
|
||||
bool bUseDrawRoi_Check; // 是否用绘制的ROI进行校验
|
||||
cv::Rect drawRoi; // 绘制的 ROi;
|
||||
cv::Mat drawMask; // 绘制的maksk
|
||||
DetConfig()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
pBaseCheckFunction = NULL;
|
||||
ncamId = 0;
|
||||
nthresholdvalue = 1;
|
||||
nAIErodesize = 7;
|
||||
bSaveResultImg = false;
|
||||
saveProcessImg = Save_Close;
|
||||
bUseDrawRoi_Check = false;
|
||||
drawRoi = cv::Rect(0, 0, 0, 0);
|
||||
if (!drawMask.empty())
|
||||
{
|
||||
drawMask.release();
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
void Print()
|
||||
{
|
||||
printf("nthresholdvalue:%d;nAIErodesize %d;bSaveResultImg %s SaveProcessImg %d\n",
|
||||
nthresholdvalue, nAIErodesize, BOOL_TO_STR(bSaveResultImg), saveProcessImg);
|
||||
|
||||
printf("bUseDrawRoi_Check %s roi %s \n",
|
||||
BOOL_TO_STR(bUseDrawRoi_Check), CheckUtil::GetRectString(drawRoi).c_str());
|
||||
}
|
||||
bool IsSaveProcessImg()
|
||||
{
|
||||
if (saveProcessImg != Save_Close)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
AI_Edge_Algin(std::shared_ptr<DetLog>& log_ref);
|
||||
~AI_Edge_Algin();
|
||||
// 初始化检测模型
|
||||
int Init(OtherDet_Config *pOtherDet_Config);
|
||||
int InitModel_ALL();
|
||||
int Detect(const cv::Mat &img, DetConfig *pDetConfig, std::shared_ptr<Edge_AI_Result> &pCheckResult_Aling);
|
||||
int SaveSmallImg(const cv::Mat &img, const cv::Mat &mask, cv::Rect roi);
|
||||
// 利用mark 实现精确定位
|
||||
int MarkAlign(const cv::Mat &img, DetConfig *pDetConfig, cv::Rect bigroi);
|
||||
|
||||
private:
|
||||
int InitModel_Big();
|
||||
int InitModel_Mark();
|
||||
int Det_big(const cv::Mat &img, DetConfig *pDetConfig, std::string strChannel, cv::Rect &bigRoi);
|
||||
int Det_MarkPoint(const cv::Mat &img, DetConfig *pDetConfig, cv::Rect bigroi, cv::Point SampleImg_Local);
|
||||
int AnalsysMarkPoint(const cv::Mat &img, DetConfig *pDetConfig);
|
||||
|
||||
int creatsavedir();
|
||||
|
||||
private:
|
||||
bool m_bInitSucc; // 是否初始化成功
|
||||
// 检测结果
|
||||
std::shared_ptr<Edge_AI_Result> m_pCheckResult_Aling;
|
||||
|
||||
OtherDet_Config *m_pOtherDet_Config;
|
||||
DetConfig *m_pDetConfig;
|
||||
|
||||
std::shared_ptr<DetLog>& m_pdetlog;
|
||||
|
||||
bool m_bInitialized;
|
||||
bool m_bModelSucc;
|
||||
bool m_bModel_Mark_Succ;
|
||||
|
||||
bool m_bshowimg;
|
||||
cv::Mat showimg;
|
||||
std::string m_strRootPath_Big;
|
||||
std::string m_strSavePath_Big;
|
||||
std::string m_strRootPath_Mark;
|
||||
std::string m_strSavePath_Mark;
|
||||
std::string m_strLastDate;
|
||||
|
||||
ImageStorage *m_pImageStorage;
|
||||
|
||||
std::shared_ptr<AIFactory> AI_Factory;
|
||||
|
||||
private:
|
||||
/* data */
|
||||
};
|
||||
|
||||
// 图片特征定位
|
||||
class Image_Feature_Algin
|
||||
{
|
||||
public:
|
||||
struct DetConfig
|
||||
{
|
||||
bool bSaveImg;
|
||||
bool bSave_Process; // 存储过程图片
|
||||
|
||||
float fscore;
|
||||
cv::Mat TemplateImg; // 模版图片
|
||||
cv::Mat DetImg; // 检测图片
|
||||
|
||||
cv::Rect Search_Roi; // 搜索 范围
|
||||
cv::Rect feature_Roi; // 特征区域
|
||||
cv::Rect param_CropRoi; // 裁剪区域,在参数图片上
|
||||
cv::Rect DetImg_CropROi; // 裁剪区域,在检测图片上
|
||||
DetConfig()
|
||||
{
|
||||
bSaveImg = false;
|
||||
bSave_Process = false;
|
||||
fscore = 0.9;
|
||||
Search_Roi = cv::Rect(0, 0, 0, 0);
|
||||
feature_Roi = cv::Rect(0, 0, 0, 0);
|
||||
param_CropRoi = cv::Rect(0, 0, 0, 0);
|
||||
DetImg_CropROi = cv::Rect(0, 0, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
Image_Feature_Algin(/* args */);
|
||||
~Image_Feature_Algin();
|
||||
int Detect(DetConfig *pDetConfig, Align_Result *pResult, std::vector<std::string> &LogList);
|
||||
|
||||
private:
|
||||
cv::Point findBestTemplateMatch(const cv::Mat &detectionImage, const cv::Mat &templateImage, double &bestScore, int method = cv::TM_CCOEFF_NORMED);
|
||||
|
||||
private:
|
||||
PRINT_LOG_ m_PrintLog;
|
||||
|
||||
private:
|
||||
/* data */
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-16 21:20:28
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef CameraResult_H_
|
||||
#define CameraResult_H_
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include "Define_Product.hpp"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "ImageAllResult.h"
|
||||
#include "DetLog.h"
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
class CameraResult
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
CameraResult(/* args */);
|
||||
~CameraResult();
|
||||
|
||||
void AddLog(std::string str);
|
||||
|
||||
// 添加图片信息
|
||||
int AddDetImage(std::shared_ptr<shareImage> p);
|
||||
// 是否全部检测完成
|
||||
bool bCheckCamplate();
|
||||
|
||||
// 设置 检测步骤
|
||||
Check_Step GetCheckStep();
|
||||
void SetCheckStep(Check_Step step);
|
||||
|
||||
// 送图是否全部完成
|
||||
bool getImgPushComplate();
|
||||
void setImgPushComplate();
|
||||
|
||||
// 返回一个未检测的 图片进行检测
|
||||
std::shared_ptr<ImageAllResult> GetNoDetImg();
|
||||
long time_start;
|
||||
bool bJson = false;
|
||||
|
||||
public:
|
||||
std::vector<std::string> LogList;
|
||||
std::shared_ptr<DetLog> detlog;
|
||||
std::vector<std::shared_ptr<ImageAllResult>> ImageALLDetResultList; // 每个通道的检测结果 ,返回的结果。
|
||||
std::shared_ptr<ProductBaseResult> productBaseResult;
|
||||
std::shared_ptr<CameraBaseResult> cameraBaseResult;
|
||||
CameraImage_Status cameraImage_Status; // 图片状态
|
||||
|
||||
std::mutex mtx_Det; // 互斥量
|
||||
private:
|
||||
bool bIsImgComplete = false; // 图片是否都送完了。
|
||||
Check_Step checkStep = Check_Step_NODet; // 检测步骤
|
||||
PRINT_LOG_ m_PrintLog;
|
||||
// 多线程安全
|
||||
std::mutex mtx_DetImageList;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
//其他类的检测
|
||||
*/
|
||||
#ifndef CheckResultJson_H_
|
||||
#define CheckResultJson_H_
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "JsonCoversion.h"
|
||||
#include <stdio.h>
|
||||
#include "ImageDetConfig.h"
|
||||
class CheckResultJson : public JsonCoversion
|
||||
{
|
||||
public:
|
||||
CheckResultJson() {}
|
||||
virtual ~CheckResultJson() {}
|
||||
|
||||
public:
|
||||
virtual Json::Value toJsonValue();
|
||||
virtual void toObjectFromValue(Json::Value root);
|
||||
int GetConfig(std::string strJson, std::shared_ptr<One_Image_CheckResult_> &pOneImgDetResult);
|
||||
std::string GetResultString(std::shared_ptr<One_Image_CheckResult_> &pOneImgDetResult);
|
||||
|
||||
private:
|
||||
std::shared_ptr<One_Image_CheckResult_> m_pOneImgDetResult;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: sueRimn
|
||||
* @Date: 2022-04-28 10:41:42
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-08-03 21:32:02
|
||||
*/
|
||||
/*
|
||||
* FileName:CoreLogicFactory.hpp
|
||||
* Version:V1.0
|
||||
* Description:
|
||||
* Created On:Mon Sep 10 11:13:13 UTC 2018
|
||||
* Modified date:
|
||||
* Author:Sky
|
||||
*/
|
||||
#ifndef _CheckUtil_HPP_
|
||||
#define _CheckUtil_HPP_
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <opencv2/opencv.hpp>
|
||||
using namespace std;
|
||||
class CheckUtil
|
||||
{
|
||||
public:
|
||||
static long getcurTime();
|
||||
static std::string getCurrentDate();
|
||||
static std::string getCurTimeHMS();
|
||||
static std::string Op_float2String(float nvalue);
|
||||
static int64_t getSnowId();
|
||||
static bool JudgRect(cv::Rect roi, int img_w, int img_h);
|
||||
static bool JudgRect_SZ(cv::Rect roi, int w, int h);
|
||||
static bool compareIgnoreCase(const std::string &str1, const std::string &str2);
|
||||
static bool RoiInImg(cv::Rect roi, cv::Mat img);
|
||||
static int printROI(cv::Rect roi, std::string str = "");
|
||||
static float CalIoU(cv::Rect rect1, cv::Rect rect2);
|
||||
static float CalIoU_t(cv::Rect rect1, cv::Rect rect2);
|
||||
static int CheckRect(cv::Rect &roi, int img_w, int img_h);
|
||||
static int SizeRect(cv::Rect &roi, int img_w, int img_h, int addw, int addh);
|
||||
static int CalHj(const cv::Mat &img, const cv::Mat &mask,int b_value);
|
||||
static int CalHj(const cv::Mat &img, const cv::Mat &mask,const cv::Mat &backgroundimg);
|
||||
static int CalHjWeighted(const cv::Mat &img, const cv::Mat &mask, int b_value, float power = 2.0f);
|
||||
// 计算平均灰度
|
||||
static float CalImgBrightness(cv::Mat imgRoi);
|
||||
// 计算角度
|
||||
static float Cal2PointAngle(cv::Point p_left, cv::Point p_right);
|
||||
|
||||
// 找图片的最大外轮廓
|
||||
static cv::Rect getLargestContourROI(const cv::Mat &binaryImg, bool &found);
|
||||
|
||||
static std::string GetRectString(cv::Rect rect);
|
||||
//创建目录
|
||||
static int CreateDir(const std::string &dir);
|
||||
|
||||
// 点的距离是否过小
|
||||
static bool bcalDis(cv::Point p1, cv::Point p2, int disT);
|
||||
static double calDis(cv::Point p1, cv::Point p2);
|
||||
static void PrintRect(cv::Rect roi, std::string str = "");
|
||||
static int cutSmallImg(cv::Mat img, std::vector<cv::Rect> &samllRoiList, cv::Rect config_roi, int config_SmallImg_Width, int config_SmallImg_Height, int config_MinOverlap_Width, int config_MinOverlap_Height);
|
||||
static cv::Point2f transformPoint(const cv::Point2f &point, const cv::Mat &transform_matrix);
|
||||
};
|
||||
template <typename... Args>
|
||||
static std::string str_Format(const std::string &format, Args... args)
|
||||
{
|
||||
auto size_buf = std::snprintf(nullptr, 0, format.c_str(), args...) + 1;
|
||||
std::unique_ptr<char[]> buf(new (std::nothrow) char[size_buf]);
|
||||
|
||||
if (!buf)
|
||||
return std::string("");
|
||||
|
||||
std::snprintf(buf.get(), size_buf, format.c_str(), args...);
|
||||
return std::string(buf.get(), buf.get() + size_buf - 1);
|
||||
|
||||
}
|
||||
#endif //_CORELOGICFACTORY_HPP_
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
//定义整个系统基础的 定义 信息
|
||||
*/
|
||||
#ifndef Define_Base_H_
|
||||
#define Define_Base_H_
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "CheckUtil.hpp"
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "Define_Error.h"
|
||||
|
||||
// 检测分析线程类数目
|
||||
#define IMGCHECKANALYSISY_NUM 2
|
||||
|
||||
|
||||
|
||||
// 相机ID 的相关定义
|
||||
enum Camera_IDX
|
||||
{
|
||||
Camera_IDX_0 = 0,
|
||||
Camera_IDX_1 = 1,
|
||||
};
|
||||
static const std::string strCameraName[] =
|
||||
{
|
||||
"left",
|
||||
"right"};
|
||||
struct Camera_Info
|
||||
{
|
||||
Camera_IDX camera_ID;
|
||||
std::string camera_name;
|
||||
Camera_Info()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
camera_ID = Camera_IDX_0;
|
||||
camera_name = strCameraName[camera_ID];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
//定义整个系统基础的 定义 信息
|
||||
*/
|
||||
#ifndef Define_Error_H_
|
||||
#define Define_Error_H_
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
enum ERRORCODEDEFINE
|
||||
{
|
||||
CHECK_OK,
|
||||
CHECK_ERROR_VERSION, // 参数或接口版本问题
|
||||
CHECK_ERROR_Config_Null, // 参数指针为空
|
||||
CHECK_ERROR_Config_Value, // 参数值错误
|
||||
CHECK_ERROR_Path_NULL, // 路径为空
|
||||
CHECK_ERROR_Mask_Empty, // mask 图片为空
|
||||
CHECK_ERROR_Config_cutRoi, // 参数的 roi 错误
|
||||
CHECK_ERROR_CheckImg_Empty, // 检测 图片为空
|
||||
CHECK_ERROR_PushImg_ListSize, // 送图错误 队列太长
|
||||
CHECK_ERROR_PushImg_NoDetChannel, // 不检测通道
|
||||
CHECK_ERROR_PushImg_Existing_ID, // ID 已存在
|
||||
CHECK_ERROR_PushImg_ID_Error, // ID 错误
|
||||
CHECK_ERROR_ID_Error, // ID 错误
|
||||
CHECK_ERROR_L255_Empty, // L255 为空
|
||||
CHECK_ERROR_L255_Edge_Fail, // L255 边界搜索失败
|
||||
CHECK_ERROR_PRODUCT_ID_EXIST, // 产品 ID 已存在
|
||||
CHECK_ERROR_Camear_ID_Error, // 相机ID 错误
|
||||
INIT_CameraCheck_Error, // 初始化 相机处理类错误
|
||||
};
|
||||
static const std::string str_ErrorName[] =
|
||||
{
|
||||
"ok",
|
||||
"ERROR_VERSION",
|
||||
"Config_Null",
|
||||
"Config_Value",
|
||||
"Path_NULL",
|
||||
"Mask_Empty",
|
||||
"Config_cutRoi",
|
||||
"CheckImg_Empty",
|
||||
"PushImg_ListSize",
|
||||
"PushImg_NoDetChannel",
|
||||
"PushImg_Existing_ID",
|
||||
"PushImg_ID_Error",
|
||||
"ID_Error",
|
||||
"L255_Empty",
|
||||
"L255_Edge_Fail",
|
||||
"L255_Empty",
|
||||
"L255_Empty",
|
||||
"PRODUCT_ID_EXIST",
|
||||
"Camear_ID_Error",
|
||||
"INIT_CameraCheck_Error"};
|
||||
struct ErrorInfo
|
||||
{
|
||||
int nerror_code; // 错误代码
|
||||
string strerror_msg; // 错误信息
|
||||
ErrorInfo()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
nerror_code = CHECK_OK;
|
||||
strerror_msg = str_ErrorName[CHECK_OK];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
#ifndef Define_Product_HPP_
|
||||
#define Define_Product_HPP_
|
||||
#include "Define_Base.h"
|
||||
#include "ImgCheckConfig.h"
|
||||
|
||||
// 相机的一些状态情况
|
||||
struct CameraImage_Status
|
||||
{
|
||||
bool bImgComplete; /// 图片送完成了
|
||||
bool bHaveImg; // 是否有图片
|
||||
bool bHave_L255; // 是否有L55图片
|
||||
bool bHave_DP; // 是否有DP图片
|
||||
bool bhave_UP; // 是否有UP图片
|
||||
bool bDetCutRoi; // 是否完成边缘检测
|
||||
CameraImage_Status()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
bImgComplete = false;
|
||||
bHaveImg = false;
|
||||
bHave_L255 = false;
|
||||
bHave_DP = false;
|
||||
bhave_UP = false;
|
||||
bDetCutRoi = false;
|
||||
}
|
||||
};
|
||||
// 处理状态
|
||||
enum Check_Step
|
||||
{
|
||||
Check_Step_NODet = 0, // 未处理
|
||||
Check_Step_PreDet, // 预处理
|
||||
Check_Step_ImgeDet, // 图片处理
|
||||
Check_Step_ResultParamJudg, // 结果参数判断
|
||||
Check_Step_ImgeDet_End, // 图片检测完成
|
||||
Check_Step_Complete, // 处理完成
|
||||
Check_Step_COUNT,
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-16 22:35:59
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef DetLog_H_
|
||||
#define DetLog_H_
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <vector>
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
using namespace std;
|
||||
enum PrintLevel_
|
||||
{
|
||||
PrintLevel_0,
|
||||
PrintLevel_1,
|
||||
PrintLevel_2,
|
||||
PrintLevel_3,
|
||||
PrintLevel_4,
|
||||
};
|
||||
template <typename... Args>
|
||||
std::string str_Format_1(const std::string &format, Args... args)
|
||||
{
|
||||
// 先尝试用小缓冲
|
||||
char buf[256];
|
||||
int size = std::snprintf(buf, sizeof(buf), format.c_str(), args...);
|
||||
|
||||
if (size < 0)
|
||||
return {};
|
||||
|
||||
if (size < sizeof(buf))
|
||||
{
|
||||
return std::string(buf, size); // 直接返回
|
||||
}
|
||||
else
|
||||
{
|
||||
// 超过栈缓存时才用堆分配
|
||||
std::vector<char> dynamic_buf(size + 1);
|
||||
std::snprintf(dynamic_buf.data(), dynamic_buf.size(), format.c_str(), args...);
|
||||
return std::string(dynamic_buf.data(), size);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测过程临结果
|
||||
struct DetLog
|
||||
{
|
||||
|
||||
std::vector<std::string> logList;
|
||||
bool bPrintStr; // 是否打印日志
|
||||
int addLogLevel;
|
||||
|
||||
DetLog()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
logList.clear();
|
||||
bPrintStr = false;
|
||||
addLogLevel = DET_LOG_LEVEL_3;
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void AddCheckstr(PrintLevel_ step, std::string stepStr, const std::string &format, Args... args)
|
||||
{
|
||||
std::string str = "";
|
||||
|
||||
if (step <= PrintLevel_0)
|
||||
{
|
||||
str += ".. ";
|
||||
}
|
||||
else if (step == PrintLevel_1)
|
||||
{
|
||||
str += "..... ";
|
||||
}
|
||||
else if (step == PrintLevel_2)
|
||||
{
|
||||
str += "........ ";
|
||||
}
|
||||
else if (step == PrintLevel_3)
|
||||
{
|
||||
str += "........... ";
|
||||
}
|
||||
else if (step >= PrintLevel_4)
|
||||
{
|
||||
str += ".............. ";
|
||||
}
|
||||
str += stepStr + ": ";
|
||||
str += str_Format_1(format, args...);
|
||||
if (bPrintStr)
|
||||
{
|
||||
printf("%s\n", str.c_str());
|
||||
}
|
||||
|
||||
logList.push_back(str);
|
||||
}
|
||||
template <typename... Args>
|
||||
void AddCheckstr(PrintLevel_ step, int LogLevel, std::string stepStr, const std::string &format, Args... args)
|
||||
{
|
||||
std::string str = "";
|
||||
|
||||
if (step <= PrintLevel_0)
|
||||
{
|
||||
str += ".. ";
|
||||
}
|
||||
else if (step == PrintLevel_1)
|
||||
{
|
||||
str += "..... ";
|
||||
}
|
||||
else if (step == PrintLevel_2)
|
||||
{
|
||||
str += "........ ";
|
||||
}
|
||||
else if (step == PrintLevel_3)
|
||||
{
|
||||
str += "........... ";
|
||||
}
|
||||
else if (step >= PrintLevel_4)
|
||||
{
|
||||
str += ".............. ";
|
||||
}
|
||||
str += stepStr + ": ";
|
||||
str += str_Format_1(format, args...);
|
||||
if (bPrintStr)
|
||||
{
|
||||
printf("%s\n", str.c_str());
|
||||
}
|
||||
|
||||
if (LogLevel <= addLogLevel)
|
||||
{
|
||||
logList.push_back(str);
|
||||
}
|
||||
}
|
||||
void printLog(std::string str)
|
||||
{
|
||||
printf("===========================%s==============================\n", str.c_str());
|
||||
for (auto strl : logList)
|
||||
{
|
||||
printf("%s\n", strl.c_str());
|
||||
}
|
||||
printf("==========================================================\n");
|
||||
}
|
||||
};
|
||||
#endif
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-23 10:45:58
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef ImageAllResult_H_
|
||||
#define ImageAllResult_H_
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include "Define_Product.hpp"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "DetLog.h"
|
||||
#include "CheckResultJson.h"
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// 包含所有的图片检测结果,如 返回的结果,临时结果, 其他检测结果
|
||||
class ImageAllResult
|
||||
{
|
||||
public:
|
||||
enum DetStep
|
||||
{
|
||||
DetStep_NotDet,
|
||||
DetStep_Deting,
|
||||
DetStep_Complet,
|
||||
};
|
||||
struct AI_Det_MaskImg
|
||||
{
|
||||
cv::Rect roi;
|
||||
cv::Mat AI_inImg;
|
||||
cv::Mat AI_mask;
|
||||
};
|
||||
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
ImageAllResult(/* args */);
|
||||
~ImageAllResult();
|
||||
|
||||
void AddLog(std::string str);
|
||||
// 添加图片信息
|
||||
int AddDetImage(std::shared_ptr<shareImage> p);
|
||||
DetStep getStep();
|
||||
void setStep(DetStep step);
|
||||
bool IsNotDet();
|
||||
|
||||
public:
|
||||
// 裁切大小
|
||||
cv::Rect CropRoi = cv::Rect(0, 0, 0, 0);
|
||||
// 检测的原始图片
|
||||
cv::Mat detImg;
|
||||
// AI 推理的mask图片
|
||||
cv::Mat AIMaskImg;
|
||||
// 结果图片
|
||||
cv::Mat resultImg;
|
||||
|
||||
float fscale_detToresult_x = 0;
|
||||
float fscale_detToresult_y = 0;
|
||||
|
||||
int NG_num = 0;
|
||||
int YS_num = 0;
|
||||
int Ok_num = 0;
|
||||
int NoJudge_num = 0;
|
||||
|
||||
public:
|
||||
DetStep m_step = DetStep_NotDet;
|
||||
std::string strBaseInfo = "";
|
||||
std::string strChannel = "";
|
||||
std::vector<std::string> LogList;
|
||||
std::shared_ptr<DetLog> detlog;
|
||||
std::shared_ptr<CheckResult> result; // 返回检测结果
|
||||
std::shared_ptr<One_Image_CheckResult_> pDetResult; // 检测结果 后续主要对pDetResult 继续分析
|
||||
std::shared_ptr<ProductBaseResult> productBaseResult; // 产品相关的基本结果信息
|
||||
std::shared_ptr<CameraBaseResult> cameraBaseResult; // 相机相关的基本结果信息
|
||||
|
||||
std::vector<std::shared_ptr<AI_Det_MaskImg>> AI_Qx_MaskList;
|
||||
std::mutex mtx_Det; // 互斥量
|
||||
private:
|
||||
PRINT_LOG_ m_PrintLog;
|
||||
|
||||
CheckResultJson m_CheckResultJson;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,44 @@
|
||||
#ifndef IMAGE_STORAGE_H
|
||||
#define IMAGE_STORAGE_H
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
class ImageStorage {
|
||||
private:
|
||||
std::queue<std::pair<cv::Mat, std::string>> imageQueue;
|
||||
std::mutex queueMutex;
|
||||
std::condition_variable cv;
|
||||
std::thread storageThread;
|
||||
|
||||
static ImageStorage* instance; // 静态成员指针,存储单例对象
|
||||
|
||||
bool stopFlag;
|
||||
|
||||
// 私有构造函数和析构函数,防止外部创建实例
|
||||
ImageStorage();
|
||||
~ImageStorage();
|
||||
|
||||
// 存储线程的工作函数
|
||||
void storeImages();
|
||||
|
||||
public:
|
||||
// 获取单例实例
|
||||
static ImageStorage* getInstance();
|
||||
|
||||
// 禁止拷贝构造和赋值
|
||||
ImageStorage(const ImageStorage&) = delete;
|
||||
ImageStorage& operator=(const ImageStorage&) = delete;
|
||||
|
||||
// 添加图片到队列
|
||||
int addImage(const std::string &path,const cv::Mat &image,bool badd = false);
|
||||
|
||||
// 停止存储线程
|
||||
void stop();
|
||||
};
|
||||
|
||||
#endif // IMAGE_STORAGE_H
|
||||
@ -0,0 +1,460 @@
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: sueRimn
|
||||
* @Date: 2022-03-16 17:09:11
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-23 10:15:49
|
||||
*/
|
||||
/***********************************************/
|
||||
/************ ***************/
|
||||
/************金佰利检测算法参数定义**************/
|
||||
/************ **************/
|
||||
/**********************************************/
|
||||
#ifndef _ImgCheckConfig_HPP_
|
||||
#define _ImgCheckConfig_HPP_
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <unordered_map> // unordered_map
|
||||
#define RESULT_VERSION 31
|
||||
|
||||
#define MAX_BLOB_NUM 200
|
||||
|
||||
// 输入模型图片尺寸
|
||||
#define SRCIMG_WIDTH 14200
|
||||
#define SRCIMG_HEIGHT 10640
|
||||
|
||||
#define CHECKIMG_HEIGHT 2000
|
||||
#define CHECKIMG_WIDTH 4000
|
||||
|
||||
#define MASK_IMG_STEP 16
|
||||
#define MASK_IMG_STARTVALUE 48
|
||||
|
||||
// 检测日志 等级
|
||||
enum DET_LOG_LEVEL_
|
||||
{
|
||||
DET_LOG_LEVEL_0, // 极简信息
|
||||
DET_LOG_LEVEL_1, // 包含检测关键信息
|
||||
DET_LOG_LEVEL_2, // 关键信息+ 一般节点信息
|
||||
DET_LOG_LEVEL_3, // 详细信息
|
||||
};
|
||||
struct VERSION_INFO
|
||||
{
|
||||
int ConfigVersion = 0;
|
||||
int ResultVersion = RESULT_VERSION;
|
||||
int InterfaceVersion = 0;
|
||||
};
|
||||
// 检测错误代码
|
||||
enum ERROR_TYPE_
|
||||
{
|
||||
ERROR_TYPE_OK, // 1 疑是
|
||||
ERROR_TYPE_aotudian, // 2 凹凸点
|
||||
ERROR_TYPE_other, // 3 其他
|
||||
ERROR_TYPE_line, // 4 线状
|
||||
ERROR_TYPE_zangwu, // 5 脏污
|
||||
ERROR_TYPE_edge, // 6 边缘
|
||||
ERROR_TYPE_ymhs, // 7 研磨划伤
|
||||
ERROR_TYPE_dianzhuang, // 8 点状
|
||||
ERROR_TYPE_posun, // 9 破损
|
||||
ERROR_TYPE_xianwei, // 10 纤维
|
||||
ERROR_TYPE_shuizi, // 11 水渍
|
||||
ERROR_TYPE_danban, // 12 淡斑
|
||||
ERROR_TYPE_fuchen, // 13 浮尘
|
||||
ERROR_TYPE_COUNT,
|
||||
};
|
||||
extern std::vector<std::string> QX_Result_Names;
|
||||
extern std::vector<std::string> QX_Result_Code;
|
||||
// 检测检测参数类型
|
||||
enum CHECK_CONFIG_TYPE_
|
||||
{
|
||||
CHECK_CONFIG_Run, // 运行参数
|
||||
CHECK_CONFIG_Module, // 参数模块
|
||||
CHECK_CONFIG_COUNT,
|
||||
};
|
||||
// 输入检测图片的
|
||||
enum IMG_INPUT_
|
||||
{
|
||||
IMG_INPUT_SRC,
|
||||
IMG_INPUT_COUNT,
|
||||
};
|
||||
// 输入检测缺陷小图
|
||||
enum IMG_OUTPUT_
|
||||
{
|
||||
IMG_OUTPUT_RESIZE,
|
||||
IMG_OUTPUT_COUNT,
|
||||
};
|
||||
// 输入图片的状态
|
||||
enum IN_IMG_Status_
|
||||
{
|
||||
IN_IMG_Status_Start,
|
||||
IN_IMG_Status_Other,
|
||||
IN_IMG_Status_End,
|
||||
IN_IMG_Status_OneImg,
|
||||
};
|
||||
// 检测模式
|
||||
enum DET_MODE_
|
||||
{
|
||||
DET_MODE_NULL,
|
||||
DET_MODE_EDGE,
|
||||
DET_MODE_MergeImg,
|
||||
DET_MODE_YX,
|
||||
DET_MODE_UP,
|
||||
DET_MODE_Det,
|
||||
DET_MODE_MarkLine,
|
||||
DET_MODE_ReJson,
|
||||
};
|
||||
|
||||
#define MAX_REGION_NUM 20
|
||||
struct ReadFlawCode
|
||||
{
|
||||
std::string flaw_name;
|
||||
std::string flaw_code;
|
||||
std::vector<std::string> config_flaw_name;
|
||||
ReadFlawCode()
|
||||
{
|
||||
config_flaw_name.clear();
|
||||
flaw_name = "";
|
||||
flaw_code = "";
|
||||
}
|
||||
};
|
||||
extern std::vector<ReadFlawCode> m_FlawCodeList;
|
||||
|
||||
// 一个检测项基本信息,包括图片序号,图片、开始时间
|
||||
struct shareImage
|
||||
{
|
||||
int Det_Mode; // 检测模式
|
||||
int Status;
|
||||
bool bCam_AB; // 是AB两个相机
|
||||
int camera_ID; // 相机ID
|
||||
int img_id;
|
||||
cv::Mat img;
|
||||
cv::Mat img_B;
|
||||
cv::Mat other_channel_Result_mask;
|
||||
cv::Mat AI_maskImg; // 推理图片
|
||||
std::string strSnowID; // 相机发古来的雪花码
|
||||
long getImgTimeMs; // 获取图片的时间点
|
||||
long readImg_start;
|
||||
long readImg_end;
|
||||
long time_PushIn;
|
||||
long time_sendCheck;
|
||||
long time_startCheck;
|
||||
long time_EndCheck;
|
||||
int imgtype;
|
||||
cv::Rect cutRoi;
|
||||
|
||||
int ninstruct; // 运行指令
|
||||
int nlogLevel; // 日志等级
|
||||
|
||||
std::string strCameraName; // 相机名称
|
||||
std::string strImgProductID; // 产品名称
|
||||
std::string strChannel; // 通道名称
|
||||
std::string strImgName; // 图片名称
|
||||
std::string imgstr;
|
||||
|
||||
int nImgBigIdx;
|
||||
int otherValue;
|
||||
int otherValue_1;
|
||||
std::string resultJson; // 检测结果 json 字符串
|
||||
bool bsaveProcessImg; // 保存处理图片
|
||||
|
||||
std::unordered_map<std::string, int> runCommand; // 运行命令 map
|
||||
shareImage()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
~shareImage()
|
||||
{
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
if (!img.empty())
|
||||
{
|
||||
img.release();
|
||||
}
|
||||
if (!other_channel_Result_mask.empty())
|
||||
{
|
||||
other_channel_Result_mask.release();
|
||||
}
|
||||
if (!AI_maskImg.empty())
|
||||
{
|
||||
AI_maskImg.release();
|
||||
}
|
||||
Det_Mode = 0;
|
||||
Status = 0;
|
||||
nlogLevel = DET_LOG_LEVEL_0;
|
||||
img_id = -1;
|
||||
getImgTimeMs = 0;
|
||||
time_PushIn = 0;
|
||||
time_sendCheck = 0;
|
||||
time_startCheck = 0;
|
||||
time_EndCheck = 0;
|
||||
readImg_start = 0;
|
||||
readImg_end = 0;
|
||||
imgtype = 0;
|
||||
imgstr = "";
|
||||
strSnowID = "";
|
||||
camera_ID = 0;
|
||||
bCam_AB = false;
|
||||
strImgName = "";
|
||||
strCameraName = "";
|
||||
strImgProductID = "";
|
||||
strChannel = "";
|
||||
nImgBigIdx = 0;
|
||||
cutRoi = cv::Rect(0, 0, 0, 0);
|
||||
otherValue = 0;
|
||||
ninstruct = 0;
|
||||
resultJson = "";
|
||||
bsaveProcessImg = false;
|
||||
}
|
||||
void InitImg(int ImgW, int imgH, bool Isgray = true)
|
||||
{
|
||||
if (Isgray)
|
||||
{
|
||||
img = cv::Mat(imgH, ImgW, CV_8UC1);
|
||||
}
|
||||
else
|
||||
{
|
||||
img = cv::Mat(imgH, ImgW, CV_8UC3);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 检测结果基本信息
|
||||
struct BasicResult
|
||||
{
|
||||
int img_id;
|
||||
long checkUseTimeMs; // 所有时间
|
||||
int64_t snowId; // 雪花ID
|
||||
int imgtype;
|
||||
std::string imgstr;
|
||||
std::string strChannel;
|
||||
void Init()
|
||||
{
|
||||
img_id = 0;
|
||||
checkUseTimeMs = 0;
|
||||
snowId = 0;
|
||||
imgtype = 0;
|
||||
imgstr = "";
|
||||
strChannel = "";
|
||||
}
|
||||
void copy(BasicResult tem)
|
||||
{
|
||||
this->img_id = tem.img_id;
|
||||
this->checkUseTimeMs = tem.checkUseTimeMs;
|
||||
this->snowId = tem.snowId;
|
||||
this->imgtype = tem.imgtype;
|
||||
this->imgstr = tem.imgstr;
|
||||
this->strChannel = tem.strChannel;
|
||||
}
|
||||
};
|
||||
|
||||
struct DetectInfo
|
||||
{
|
||||
int nresult;
|
||||
std::string keyName;
|
||||
std::string keyCode;
|
||||
int num;
|
||||
DetectInfo()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
nresult = 0;
|
||||
num = 0;
|
||||
keyName = "";
|
||||
keyCode = "";
|
||||
}
|
||||
void copy(DetectInfo tem)
|
||||
{
|
||||
this->nresult = tem.nresult;
|
||||
this->num = tem.num;
|
||||
this->keyName = tem.keyName;
|
||||
this->keyCode = tem.keyCode;
|
||||
}
|
||||
};
|
||||
|
||||
struct QXImageResult
|
||||
{
|
||||
int type; // 缺陷类型
|
||||
std::string qx_Code; // 缺陷code
|
||||
std::string strTypeName; // 缺陷名称
|
||||
|
||||
cv::Mat srcImg; // 缺陷原始图片
|
||||
cv::Mat resizeImg; // 缺陷缩略图
|
||||
cv::Mat AI_in_Img;
|
||||
cv::Mat AI_out_img;
|
||||
|
||||
cv::Rect srcImgroi; // 相对原图的 框坐标;
|
||||
cv::Rect CutImgroi; // 裁剪原图 框坐标;
|
||||
cv::Rect resizeImgroi; // 相对相对小图 框坐标;
|
||||
|
||||
float x_pixel; // 缺陷坐标 像素
|
||||
float y_pixel; // 缺陷坐标 像素
|
||||
|
||||
float x_mm; // 缺陷坐标 mm
|
||||
float y_mm; // 缺陷坐标 mm
|
||||
int idx;
|
||||
float area;
|
||||
float energy;
|
||||
float hj;
|
||||
float max_v;
|
||||
float len;
|
||||
float breadth;
|
||||
float fScore;
|
||||
int qx_type; // 缺陷的原因
|
||||
float minDis_mm;
|
||||
int qx_num;
|
||||
float density; // 密度
|
||||
|
||||
QXImageResult()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
if (!srcImg.empty())
|
||||
{
|
||||
srcImg.release();
|
||||
}
|
||||
if (!resizeImg.empty())
|
||||
{
|
||||
resizeImg.release();
|
||||
}
|
||||
if (!AI_in_Img.empty())
|
||||
{
|
||||
AI_in_Img.release();
|
||||
/* code */
|
||||
}
|
||||
if (!AI_out_img.empty())
|
||||
{
|
||||
AI_out_img.release();
|
||||
/* code */
|
||||
}
|
||||
|
||||
x_pixel = 0;
|
||||
y_pixel = 0;
|
||||
x_mm = 0;
|
||||
y_mm = 0;
|
||||
type = 0;
|
||||
area = 0;
|
||||
energy = 0;
|
||||
hj = 0;
|
||||
max_v = 0;
|
||||
strTypeName = "";
|
||||
qx_Code = "";
|
||||
len = 0;
|
||||
breadth = 0;
|
||||
idx = 0;
|
||||
fScore = 0;
|
||||
qx_type = 0;
|
||||
minDis_mm = 0;
|
||||
qx_num = 0;
|
||||
density = 0;
|
||||
srcImgroi = cv::Rect(0, 0, 0, 0);
|
||||
CutImgroi = cv::Rect(0, 0, 0, 0);
|
||||
resizeImgroi = cv::Rect(0, 0, 0, 0);
|
||||
}
|
||||
};
|
||||
// 结果信息
|
||||
struct CheckResult
|
||||
{
|
||||
// 原始图片,输入检测的图片
|
||||
int checkStatus;
|
||||
int nDetStep; // 处理步骤
|
||||
int nresult;
|
||||
int nProductResult; // 产品结果
|
||||
int nYS_result;
|
||||
float productWidht_mm; // 产品宽度 毫米
|
||||
float productHeight_mm; // 产品 高度 毫米
|
||||
cv::Mat cutSrcimg;
|
||||
cv::Mat resultimg;
|
||||
cv::Mat SrcResultImg; // 结果
|
||||
cv::Mat resultMaskImg; // AI mask Result
|
||||
std::shared_ptr<shareImage> in_shareImage; // 输入图片信息
|
||||
DetectInfo defectResultList[ERROR_TYPE_COUNT]; // 缺陷检测结果list
|
||||
BasicResult basicResult; // 基本检测结果信息
|
||||
std::vector<QXImageResult> qxImageResult; // 缺陷小图结果
|
||||
std::vector<QXImageResult> YS_ImageResult; // 疑似小图结果
|
||||
std::vector<std::string> det_LogList; // 检测日志
|
||||
std::string strResultJson; // 缺陷结果 jason
|
||||
bool bSaveALL;
|
||||
int nflage1;
|
||||
int nflage2;
|
||||
CheckResult()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
~CheckResult()
|
||||
{
|
||||
release();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
nProductResult = 0;
|
||||
checkStatus = 0;
|
||||
nDetStep = 0;
|
||||
nresult = ERROR_TYPE_OK;
|
||||
nYS_result = ERROR_TYPE_OK;
|
||||
bSaveALL = false;
|
||||
nflage1 = 0;
|
||||
nflage2 = 0;
|
||||
productWidht_mm = 0;
|
||||
productHeight_mm = 0;
|
||||
basicResult.Init();
|
||||
strResultJson = "";
|
||||
if (!resultimg.empty())
|
||||
{
|
||||
resultimg.release();
|
||||
}
|
||||
if (!cutSrcimg.empty())
|
||||
{
|
||||
cutSrcimg.release();
|
||||
}
|
||||
if (!SrcResultImg.empty())
|
||||
{
|
||||
SrcResultImg.release();
|
||||
}
|
||||
if (!resultMaskImg.empty())
|
||||
{
|
||||
resultMaskImg.release();
|
||||
}
|
||||
for (int i = 0; i < ERROR_TYPE_COUNT; i++)
|
||||
{
|
||||
defectResultList[i].Init();
|
||||
}
|
||||
std::vector<QXImageResult> tmp;
|
||||
qxImageResult.swap(tmp);
|
||||
YS_ImageResult.swap(tmp);
|
||||
qxImageResult.erase(qxImageResult.begin(), qxImageResult.end());
|
||||
YS_ImageResult.erase(YS_ImageResult.begin(), YS_ImageResult.end());
|
||||
det_LogList.erase(det_LogList.begin(), det_LogList.end());
|
||||
}
|
||||
|
||||
void release()
|
||||
{
|
||||
if (!resultimg.empty())
|
||||
{
|
||||
resultimg.release();
|
||||
}
|
||||
if (!cutSrcimg.empty())
|
||||
{
|
||||
cutSrcimg.release();
|
||||
}
|
||||
if (!SrcResultImg.empty())
|
||||
{
|
||||
SrcResultImg.release();
|
||||
}
|
||||
if (!resultMaskImg.empty())
|
||||
{
|
||||
resultMaskImg.release();
|
||||
}
|
||||
strResultJson = "";
|
||||
std::vector<QXImageResult> tmp;
|
||||
qxImageResult.swap(tmp);
|
||||
YS_ImageResult.swap(tmp);
|
||||
det_LogList.erase(det_LogList.begin(), det_LogList.end());
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_CORELOGICFACTORY_HPP_
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-17 18:57:39
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef OtherDetBaseDefine_H_
|
||||
#define OtherDetBaseDefine_H_
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "BlobBase.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct OtherDet_Config
|
||||
{
|
||||
int nDeviceId; // GPU 号
|
||||
int nUserValue;
|
||||
int nShowImg_Width;
|
||||
int nShowImg_Height;
|
||||
|
||||
OtherDet_Config()
|
||||
{
|
||||
|
||||
|
||||
nDeviceId = 0;
|
||||
nUserValue = 0;
|
||||
nShowImg_Width = 100;
|
||||
nShowImg_Height = 100;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,73 @@
|
||||
/*
|
||||
//其他类的检测
|
||||
*/
|
||||
#ifndef OtherDetect_H_
|
||||
#define OtherDetect_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "CheckUtil.hpp"
|
||||
#include "OtherDetBaseDefine.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
// 基础类
|
||||
class AIDetectBase
|
||||
{
|
||||
|
||||
public:
|
||||
AIDetectBase(/* args */);
|
||||
~AIDetectBase();
|
||||
int Init(OtherDet_Config *pOtherDet_Config);
|
||||
|
||||
protected:
|
||||
OtherDet_Config *m_pOtherDet_Config;
|
||||
|
||||
bool m_bInitialized;
|
||||
bool m_bModelSucc;
|
||||
};
|
||||
|
||||
// 缺pol 检测
|
||||
class LackPolDet : public AIDetectBase
|
||||
{
|
||||
|
||||
public:
|
||||
/// @brief 检测过程的参数
|
||||
struct DetConfig
|
||||
{
|
||||
float fImgage_Scale_X;
|
||||
float fImgage_Scale_Y;
|
||||
bool bSaveResultImg; // 保存结果图片
|
||||
std::string strChannel; // 通道名称
|
||||
cv::Mat detMaskImg; // 检测区域图片
|
||||
DetConfig()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
fImgage_Scale_X = 0.03f;
|
||||
fImgage_Scale_Y = 0.03f;
|
||||
bSaveResultImg = false;
|
||||
strChannel = "";
|
||||
}
|
||||
void Print()
|
||||
{
|
||||
printf("bSaveResultImg %s strChannel %s\n",
|
||||
BOOL_TO_STR(bSaveResultImg), strChannel.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
LackPolDet(/* args */);
|
||||
~LackPolDet();
|
||||
int InitModel_ALL();
|
||||
int Detect(const cv::Mat &img, DetConfig *pDetConfig, cv::Mat &outMask);
|
||||
|
||||
private:
|
||||
int Init_LackPol();
|
||||
|
||||
public:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-16 21:19:45
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef Product_H_
|
||||
#define Product_H_
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include "Define_Product.hpp"
|
||||
#include "CameraResult.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImageDetConfig.h"
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class Product
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
Product(/* args */);
|
||||
~Product();
|
||||
|
||||
std::shared_ptr<CameraResult> GetCameraResult(std::string strcameraName);
|
||||
void AddLog(std::string str);
|
||||
// 更新 送图状态
|
||||
void UpdatePushStatus(int status);
|
||||
|
||||
// 是否全部检测完成
|
||||
bool bCheckCamplate();
|
||||
void SetCheckEnd();
|
||||
|
||||
public:
|
||||
// 相机结果
|
||||
std::vector<std::shared_ptr<CameraResult>> m_pCameraResultList;
|
||||
std::shared_ptr<ProductBaseResult> productBaseResult;
|
||||
// 图片是否都送完了。
|
||||
bool bIsImgComplete = false;
|
||||
// 日志
|
||||
std::vector<std::string> LogList;
|
||||
std::mutex mtx_CameraResultList;
|
||||
|
||||
|
||||
private:
|
||||
std::mutex mtx_;
|
||||
// 多线程安全
|
||||
|
||||
PRINT_LOG_ m_PrintLog;
|
||||
std::string strEndTime;
|
||||
long time_pushImg_end;
|
||||
long time_CheckImg_end;
|
||||
long product_UseAllTime;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2025-09-16 10:14:05
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef Task_H_
|
||||
#define Task_H_
|
||||
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
enum TaskName
|
||||
{
|
||||
Task_AI,
|
||||
Task_Class,
|
||||
Task_Count,
|
||||
};
|
||||
enum TaskStep
|
||||
{
|
||||
TaskStep_Idle,
|
||||
TaskStep_Waite,
|
||||
TaskStep_run,
|
||||
TaskStep_compate,
|
||||
};
|
||||
struct TaskInfo
|
||||
{
|
||||
TaskName taskname;
|
||||
TaskStep status; // 运行状态
|
||||
int nresult; // 运行结果
|
||||
|
||||
// 🔑 新增变量
|
||||
std::mutex mtx;
|
||||
std::condition_variable cv;
|
||||
|
||||
// 设置状态,线程安全
|
||||
void SetStatus(TaskStep newStatus)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
status = newStatus;
|
||||
}
|
||||
cv.notify_all(); // 通知等待者
|
||||
}
|
||||
bool isComplate()
|
||||
{
|
||||
bool bcom = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
if (status == TaskStep_compate)
|
||||
{
|
||||
bcom = true;
|
||||
}
|
||||
}
|
||||
|
||||
return bcom;
|
||||
}
|
||||
// 等待任务完成
|
||||
void waitComplate()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
cv.wait(lock, [this]
|
||||
{ return status == TaskStep_compate; });
|
||||
}
|
||||
};
|
||||
using namespace std;
|
||||
|
||||
class Task
|
||||
{
|
||||
public:
|
||||
Task();
|
||||
~Task();
|
||||
int sendTask(std::shared_ptr<TaskInfo> task);
|
||||
std::shared_ptr<TaskInfo> GetTask();
|
||||
|
||||
private:
|
||||
std::queue<std::shared_ptr<TaskInfo>> m_tasks_;
|
||||
std::mutex m_task_mutex_;
|
||||
std::condition_variable m_task_cv_;
|
||||
|
||||
private:
|
||||
public:
|
||||
private:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,106 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
#include <mutex>
|
||||
|
||||
class snowflake_nonlock
|
||||
{
|
||||
public:
|
||||
void lock()
|
||||
{
|
||||
}
|
||||
void unlock()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<int64_t Twepoch, typename Lock = snowflake_nonlock>
|
||||
class snowflake
|
||||
{
|
||||
using lock_type = Lock;
|
||||
static constexpr int64_t TWEPOCH = Twepoch;
|
||||
static constexpr int64_t WORKER_ID_BITS = 5L;
|
||||
static constexpr int64_t DATACENTER_ID_BITS = 5L;
|
||||
static constexpr int64_t MAX_WORKER_ID = (1 << WORKER_ID_BITS) - 1;
|
||||
static constexpr int64_t MAX_DATACENTER_ID = (1 << DATACENTER_ID_BITS) - 1;
|
||||
static constexpr int64_t SEQUENCE_BITS = 12L;
|
||||
static constexpr int64_t WORKER_ID_SHIFT = SEQUENCE_BITS;
|
||||
static constexpr int64_t DATACENTER_ID_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS;
|
||||
static constexpr int64_t TIMESTAMP_LEFT_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS + DATACENTER_ID_BITS;
|
||||
static constexpr int64_t SEQUENCE_MASK = (1 << SEQUENCE_BITS) - 1;
|
||||
|
||||
using time_point = std::chrono::time_point<std::chrono::steady_clock>;
|
||||
|
||||
time_point start_time_point_ = std::chrono::steady_clock::now();
|
||||
int64_t start_millsecond_ = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
||||
int64_t last_timestamp_ = -1;
|
||||
int64_t workerid_ = 0;
|
||||
int64_t datacenterid_ = 0;
|
||||
int64_t sequence_ = 0;
|
||||
lock_type lock_;
|
||||
public:
|
||||
snowflake() = default;
|
||||
|
||||
snowflake(const snowflake&) = delete;
|
||||
|
||||
snowflake& operator=(const snowflake&) = delete;
|
||||
|
||||
void init(int64_t workerid, int64_t datacenterid)
|
||||
{
|
||||
if (workerid > MAX_WORKER_ID || workerid < 0) {
|
||||
throw std::runtime_error("worker Id can't be greater than 31 or less than 0");
|
||||
}
|
||||
|
||||
if (datacenterid > MAX_DATACENTER_ID || datacenterid < 0) {
|
||||
throw std::runtime_error("datacenter Id can't be greater than 31 or less than 0");
|
||||
}
|
||||
|
||||
workerid_ = workerid;
|
||||
datacenterid_ = datacenterid;
|
||||
}
|
||||
|
||||
int64_t nextid()
|
||||
{
|
||||
std::lock_guard<lock_type> lock(lock_);
|
||||
//std::chrono::steady_clock cannot decrease as physical time moves forward
|
||||
auto timestamp = millsecond();
|
||||
if (last_timestamp_ == timestamp)
|
||||
{
|
||||
sequence_ = (sequence_ + 1)&SEQUENCE_MASK;
|
||||
if (sequence_ == 0)
|
||||
{
|
||||
timestamp = wait_next_millis(last_timestamp_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sequence_ = 0;
|
||||
}
|
||||
|
||||
last_timestamp_ = timestamp;
|
||||
|
||||
return ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT)
|
||||
| (datacenterid_ << DATACENTER_ID_SHIFT)
|
||||
| (workerid_ << WORKER_ID_SHIFT)
|
||||
| sequence_;
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t millsecond() const noexcept
|
||||
{
|
||||
auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time_point_);
|
||||
return start_millsecond_ + diff.count();
|
||||
}
|
||||
|
||||
int64_t wait_next_millis(int64_t last) const noexcept
|
||||
{
|
||||
auto timestamp = millsecond();
|
||||
while (timestamp <= last)
|
||||
{
|
||||
timestamp = millsecond();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,695 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:50:00
|
||||
* @LastEditTime: 2025-09-22 16:44:43
|
||||
* @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 "ALLImgCheckAnalysisy.hpp"
|
||||
#include "CheckUtil.hpp"
|
||||
#include "Define.h"
|
||||
#include "AI_Factory.h"
|
||||
#include <fstream>
|
||||
|
||||
std::vector<ReadFlawCode> m_FlawCodeList;
|
||||
|
||||
std::vector<std::string> QX_Result_Names =
|
||||
{
|
||||
"OK",
|
||||
"aotudian",
|
||||
"other",
|
||||
"line",
|
||||
"zangwu",
|
||||
"edge",
|
||||
"ymhs",
|
||||
"dianzhuang",
|
||||
"posun",
|
||||
"xianwei",
|
||||
"shuizi",
|
||||
"danban",
|
||||
"fuchen",
|
||||
};
|
||||
std::vector<std::string> QX_Result_Code =
|
||||
{
|
||||
"P0000",
|
||||
"MA507",
|
||||
"MA508",
|
||||
"MA506",
|
||||
"MA504",
|
||||
"MA503",
|
||||
"MA502",
|
||||
"MA505",
|
||||
"MA501",
|
||||
"P0001",
|
||||
"P0002",
|
||||
"P0003",
|
||||
"P0004",
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
double calculateDistanceBetweenRectCenters(const cv::Rect &rect1, const cv::Rect &rect2, float fx, float fy)
|
||||
{
|
||||
// 计算矩形1的中心点
|
||||
cv::Point center1(rect1.x + rect1.width / 2, rect1.y + rect1.height / 2);
|
||||
|
||||
// 计算矩形2的中心点
|
||||
cv::Point center2(rect2.x + rect2.width / 2, rect2.y + rect2.height / 2);
|
||||
center1.x *= fx;
|
||||
center1.y *= fy;
|
||||
|
||||
center2.x *= fx;
|
||||
center2.y *= fy;
|
||||
|
||||
// 计算中心点之间的欧几里得距离
|
||||
double distance = cv::norm(center1 - center2);
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
ALLImgCheckAnalysisy::ALLImgCheckAnalysisy()
|
||||
{
|
||||
|
||||
m_strTest = "";
|
||||
}
|
||||
|
||||
ALLImgCheckAnalysisy::~ALLImgCheckAnalysisy()
|
||||
{
|
||||
StopThread();
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::RunStart(void *pconfig1)
|
||||
{
|
||||
VERSION_INFO *pVersionconfig = (VERSION_INFO *)pconfig1;
|
||||
if (pVersionconfig == NULL)
|
||||
{
|
||||
printf("**************************** \n");
|
||||
m_nErrorCode = CHECK_ERROR_VERSION; // 参数或接口版本问题
|
||||
return m_nErrorCode;
|
||||
}
|
||||
|
||||
int v1 = ALL_INTERFACE_VERSION;
|
||||
int v2 = CONFIGBASE_VERSION;
|
||||
int v3 = RESULT_VERSION;
|
||||
printf("**************************** ALL_INTERFACE_VERSION so: %d in:%d CONFIGBASE_VERSION so:%d in:%d RESULT_VERSION so:%d in:%d\n",
|
||||
v1, pVersionconfig->InterfaceVersion, v2, pVersionconfig->ConfigVersion, v3, pVersionconfig->ResultVersion);
|
||||
// 版本控制
|
||||
if (pVersionconfig->InterfaceVersion != ALL_INTERFACE_VERSION ||
|
||||
pVersionconfig->ConfigVersion != CONFIGBASE_VERSION ||
|
||||
pVersionconfig->ResultVersion != RESULT_VERSION)
|
||||
{
|
||||
m_nErrorCode = CHECK_ERROR_VERSION; // 参数或接口版本问题
|
||||
return m_nErrorCode;
|
||||
}
|
||||
int re = 0;
|
||||
|
||||
re = InitCameraCheckAnalysisy();
|
||||
if (re != 0)
|
||||
{
|
||||
printf("*************InitCameraCheckAnalysisy error %d*************** \n", re);
|
||||
m_nErrorCode = INIT_CameraCheck_Error;
|
||||
return m_nErrorCode;
|
||||
}
|
||||
|
||||
re = InitRun();
|
||||
if (CHECK_OK != re)
|
||||
{
|
||||
m_nErrorCode = re;
|
||||
return m_nErrorCode;
|
||||
}
|
||||
re = InitAIFactory();
|
||||
if (CHECK_OK != re)
|
||||
{
|
||||
m_nErrorCode = re;
|
||||
return m_nErrorCode;
|
||||
}
|
||||
m_nErrorCode = CHECK_OK;
|
||||
printf(">>>> ALLImgCheckAnalysisy Start Succ \n");
|
||||
|
||||
m_nErrorCode = CHECK_OK;
|
||||
m_bInitSucc = true;
|
||||
return m_nErrorCode;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::SetDataRun_SharePtr(std::shared_ptr<shareImage> p)
|
||||
{
|
||||
|
||||
int re = PushInImg_New(p);
|
||||
|
||||
// printf("SetDataRun_SharePtr======================= re %d \n", re);
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::GetCheckReuslt(std::shared_ptr<CheckResult> &pResult)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(mtx_CheckResult); // 使用 unique_lock
|
||||
CheckResult_cond.wait(lk, [this]
|
||||
{ return !m_CheckResultList.empty(); }); // 等待直到数据队列非空
|
||||
pResult = m_CheckResultList.front(); // 从队列中取出数
|
||||
m_CheckResultList.pop();
|
||||
lk.unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::ReJson(std::shared_ptr<shareImage> p, std::shared_ptr<CheckResult> &pResult)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::CheckImg(std::shared_ptr<shareImage> p, std::shared_ptr<CheckResult> &pResult)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::GetStatus()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::UpdateConfig(void *pconfig, int nConfigType)
|
||||
{
|
||||
int re = 0;
|
||||
RunInfoST *tempconfig;
|
||||
switch (nConfigType)
|
||||
{
|
||||
case CHECK_CONFIG_Run:
|
||||
tempconfig = (RunInfoST *)pconfig;
|
||||
m_RunConfig.copy(*tempconfig);
|
||||
break;
|
||||
case CHECK_CONFIG_Module:
|
||||
m_pConfigManager = (ConfigManagerBase *)pconfig;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ALLImgCheckAnalysisy::GetVersion()
|
||||
{
|
||||
return std::string("BOE_2.0.5");
|
||||
}
|
||||
|
||||
std::string ALLImgCheckAnalysisy::GetErrorInfo()
|
||||
{
|
||||
std::string result = "";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::ErrorReturn(std::shared_ptr<shareImage> p)
|
||||
{
|
||||
|
||||
std::shared_ptr<CheckResult> result = std::make_shared<CheckResult>();
|
||||
result->in_shareImage = p;
|
||||
result->checkStatus = 1;
|
||||
result->nresult = -CHECK_ERROR_PushImg_ID_Error;
|
||||
result->basicResult.img_id = p->img_id;
|
||||
result->basicResult.imgtype = p->imgtype;
|
||||
result->basicResult.imgstr = p->imgstr;
|
||||
result->basicResult.strChannel = p->strChannel;
|
||||
// printf("ErrorReturn==== %s %s\n", p->strImgProductID.c_str(), p->strChannel.c_str());
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_CheckResult);
|
||||
m_CheckResultList.push(result);
|
||||
}
|
||||
CheckResult_cond.notify_all();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<Product> ALLImgCheckAnalysisy::GetProduct(std::string strProduct)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_ProductList);
|
||||
for (int i = 0; i < m_ProductList.size(); i++)
|
||||
{
|
||||
// printf("ddd %s \n", m_ProductList.at(i)->productBaseResult->strproductName.c_str());
|
||||
if (m_ProductList.at(i)->productBaseResult->strproductName == strProduct)
|
||||
{
|
||||
return m_ProductList.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<Product>();
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::InitAIFactory()
|
||||
{
|
||||
std::shared_ptr<AIFactory> AI_Factory;
|
||||
AI_Factory = AIFactory::GetInstance();
|
||||
|
||||
GPU_Config gpu;
|
||||
gpu.gpu_0 = true;
|
||||
gpu.gpu_1 = true;
|
||||
|
||||
AI_Factory->InitALLAIModle(gpu);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::LoadRunConfig(void *p)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::LoadCheckConfig(void *p)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::InitRun()
|
||||
{
|
||||
int re;
|
||||
re = StartThread();
|
||||
if (CHECK_OK != re)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::StartCheck()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::SetIDLE()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::StartThread()
|
||||
{
|
||||
m_bExit = false;
|
||||
|
||||
{ // 开启检测线程
|
||||
ptr_thread_Run = std::make_shared<std::thread>(std::bind(&ALLImgCheckAnalysisy::Run, this));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::StopThread()
|
||||
{
|
||||
m_bExit = true;
|
||||
if (ptr_thread_Run != nullptr)
|
||||
{
|
||||
if (ptr_thread_Run->joinable())
|
||||
{
|
||||
ptr_thread_Run->join();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::ExitSystem()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::InitCameraCheckAnalysisy()
|
||||
{
|
||||
string defect_list_file = m_pConfigManager->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);
|
||||
m_pCameraCheckAnalysisyList.clear();
|
||||
for (const auto &config : m_pConfigManager->Config_instances_)
|
||||
{
|
||||
|
||||
std::cout << "key: " << config.first << std::endl;
|
||||
std::shared_ptr<CameraCheckAnalysisy> p = std::make_shared<CameraCheckAnalysisy>();
|
||||
|
||||
p->m_RunConfig.copy(m_RunConfig);
|
||||
p->m_pConfig = config.second;
|
||||
int re = p->Init(config.first);
|
||||
if (re != 0)
|
||||
{
|
||||
std::cout << "Init CameraCheckAnalysisy " << config.first << " Failed" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
m_pCameraCheckAnalysisyList[config.first] = p;
|
||||
}
|
||||
if (m_pCameraCheckAnalysisyList.size() <= 0)
|
||||
{
|
||||
printf("ALLImgCheckAnalysisy::InitCameraCheckAnalysisy error camera config is null \n");
|
||||
return 1;
|
||||
/* code */
|
||||
}
|
||||
|
||||
// for (const auto &pCameraCheckAnalysisy : m_pCameraCheckAnalysisyList)
|
||||
// {
|
||||
// std::cout << "key: " << pCameraCheckAnalysisy.first << std::endl;
|
||||
// }
|
||||
printf("ALLImgCheckAnalysisy::InitCameraCheckAnalysisy end \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::InitData()
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::Det_Product(std::shared_ptr<Product> &product)
|
||||
{
|
||||
|
||||
// 处理每个相机
|
||||
while (true)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(product->mtx_CameraResultList); //
|
||||
for (auto &ptr : product->m_pCameraResultList)
|
||||
{
|
||||
if (ptr->GetCheckStep() == Check_Step_NODet)
|
||||
{
|
||||
m_pCameraCheckAnalysisyList[ptr->cameraBaseResult->strCameraName]->StartCheck(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断每个相机是否都处理完了。
|
||||
bool bdetComplete = product->bCheckCamplate();
|
||||
// 处理完成,退出循环
|
||||
if (bdetComplete)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 联合分析
|
||||
// AnalysiyAll(0);
|
||||
SetProductResult(product);
|
||||
product->SetCheckEnd();
|
||||
string cur_time = CheckUtil::getCurTimeHMS();
|
||||
printf("[%s]>>>>>>>>>>>>>>>Det_Product****************det End************\n", cur_time.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<Product> ALLImgCheckAnalysisy::GetProduct()
|
||||
{
|
||||
|
||||
std::unique_lock<std::mutex> lk(mtx_ProductList); // 使用 unique_lock
|
||||
ProductList_cond.wait(lk, [this]
|
||||
{ return !m_ProductList.empty(); }); // 等待直到数据队列非空
|
||||
std::shared_ptr<Product> tem = m_ProductList.at(0);
|
||||
lk.unlock();
|
||||
return tem;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::AnalysiyAll(int productIdx)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::SetProductResult(std::shared_ptr<Product> product)
|
||||
{
|
||||
|
||||
int nDetCamNum = product->m_pCameraResultList.size();
|
||||
// 相机2的起始位置
|
||||
bool bNG = false;
|
||||
for (int icam = 0; icam < nDetCamNum; icam++)
|
||||
{
|
||||
|
||||
std::shared_ptr<CameraResult> pcam = product->m_pCameraResultList.at(icam);
|
||||
for (int i = 0; i < pcam->ImageALLDetResultList.size(); i++)
|
||||
{
|
||||
|
||||
std::shared_ptr<CheckResult> pCheckResult = pcam->ImageALLDetResultList.at(i)->result;
|
||||
|
||||
if (pCheckResult->qxImageResult.size() > 0)
|
||||
{
|
||||
bNG = true;
|
||||
}
|
||||
if (bNG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bNG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bNG)
|
||||
{
|
||||
for (int icam = 0; icam < nDetCamNum; icam++)
|
||||
{
|
||||
|
||||
std::shared_ptr<CameraResult> pcam = product->m_pCameraResultList.at(icam);
|
||||
for (int i = 0; i < pcam->ImageALLDetResultList.size(); i++)
|
||||
{
|
||||
|
||||
std::shared_ptr<CheckResult> pCheckResult = pcam->ImageALLDetResultList.at(i)->result;
|
||||
pCheckResult->nProductResult = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::SetSetComplet_New(std::shared_ptr<Product> product, int nerror)
|
||||
{
|
||||
if (product)
|
||||
{
|
||||
|
||||
int nDetCamNum = product->m_pCameraResultList.size();
|
||||
for (int icam = 0; icam < nDetCamNum; icam++)
|
||||
{
|
||||
std::shared_ptr<CameraResult> pcam = product->m_pCameraResultList.at(icam);
|
||||
for (int i = 0; i < pcam->ImageALLDetResultList.size(); i++)
|
||||
{
|
||||
std::shared_ptr<CheckResult> pCheckResult = pcam->ImageALLDetResultList.at(i)->result;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock123(mtx_CheckResult);
|
||||
m_CheckResultList.push(pCheckResult);
|
||||
}
|
||||
CheckResult_cond.notify_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::PushInImg_New(std::shared_ptr<shareImage> p)
|
||||
{
|
||||
|
||||
if (!m_bInitSucc)
|
||||
{
|
||||
printf("Init fail exit \n");
|
||||
return CHECK_ERROR_Config_Null;
|
||||
}
|
||||
|
||||
std::string strlog = "";
|
||||
m_strTest += " PushInImg->SN:";
|
||||
m_strTest += p->strImgProductID;
|
||||
m_strTest += " Channel:";
|
||||
m_strTest += p->strChannel;
|
||||
m_strTest += " CameraID:";
|
||||
m_strTest += p->strCameraName;
|
||||
std::string strBase = "";
|
||||
strBase += " PushInImg->SN:";
|
||||
strBase += p->strImgProductID;
|
||||
strBase += " Channel:";
|
||||
strBase += p->strChannel;
|
||||
printf("strBase %s p->Status %d\n", strBase.c_str(), p->Status);
|
||||
std::shared_ptr<Product> product;
|
||||
{
|
||||
std::string strcameraName = p->strCameraName;
|
||||
cout << "strcameraName: " << strcameraName << endl;
|
||||
if(m_pCameraCheckAnalysisyList.size() <= 0){
|
||||
cout << "m_pCameraCheckAnalysisyList.size(): " << m_pCameraCheckAnalysisyList.size() << endl;
|
||||
}
|
||||
for (auto it = m_pCameraCheckAnalysisyList.begin(); it != m_pCameraCheckAnalysisyList.end(); ++it) {
|
||||
std::cout << "m_pCameraCheckAnalysisyList_Key: " << it->first << std::endl;
|
||||
}
|
||||
// 判断 相机名称是否存在
|
||||
|
||||
if (!m_pCameraCheckAnalysisyList.count(strcameraName) && -1 != p->Status)
|
||||
{
|
||||
return CHECK_ERROR_Camear_ID_Error;
|
||||
}
|
||||
|
||||
product = GetProduct(p->strImgProductID);
|
||||
bool ProductID_Exist = false; // 是否存在当前产品ID
|
||||
if (product)
|
||||
{
|
||||
ProductID_Exist = true;
|
||||
}
|
||||
|
||||
// 产品存在 并且 模式 是第一张图, 则,返回异常。
|
||||
if (IN_IMG_Status_Start == p->Status && ProductID_Exist)
|
||||
{
|
||||
return CHECK_ERROR_PRODUCT_ID_EXIST;
|
||||
}
|
||||
// 产品存在,但是 图片都已经完了的状态
|
||||
if (ProductID_Exist && product->bIsImgComplete)
|
||||
{
|
||||
ErrorReturn(p);
|
||||
return CHECK_ERROR_PRODUCT_ID_EXIST;
|
||||
}
|
||||
// 产品不存在 新建一个
|
||||
if (!product)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_ProductList);
|
||||
{
|
||||
if (m_ProductList.size() > 5)
|
||||
{
|
||||
|
||||
return CHECK_ERROR_PushImg_ListSize;
|
||||
}
|
||||
}
|
||||
product = std::make_shared<Product>();
|
||||
product->productBaseResult->strproductName = p->strImgProductID;
|
||||
m_ProductList.push_back(product);
|
||||
std::string strTimg = CheckUtil::getCurTimeHMS();
|
||||
product->productBaseResult->detlog->AddCheckstr(PrintLevel_0, "PushInImg", "add new product %s %s ", p->strImgProductID.c_str(), strTimg.c_str());
|
||||
}
|
||||
// 送入图的状态 不是结束
|
||||
if (-1 != p->Status)
|
||||
{
|
||||
// 对应相机的 检测结果
|
||||
std::shared_ptr<CameraResult> pCamera = product->GetCameraResult(strcameraName);
|
||||
|
||||
if (pCamera.get() == nullptr)
|
||||
{
|
||||
ErrorReturn(p);
|
||||
return CHECK_ERROR_Camear_ID_Error;
|
||||
}
|
||||
// 添加产品信息
|
||||
pCamera->AddDetImage(p);
|
||||
}
|
||||
product->UpdatePushStatus(p->Status);
|
||||
if (-1 == p->Status || IN_IMG_Status_End == p->Status)
|
||||
{
|
||||
m_strTest += "\n";
|
||||
product->AddLog(m_strTest);
|
||||
m_strTest = "";
|
||||
}
|
||||
|
||||
ProductList_cond.notify_all();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ALLImgCheckAnalysisy::Run()
|
||||
{
|
||||
|
||||
while (!m_bExit)
|
||||
{
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
|
||||
std::shared_ptr<Product> product = GetProduct();
|
||||
|
||||
int re = Det_Product(product);
|
||||
// // 检测失败
|
||||
// if (re != 0)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
SetSetComplet_New(product, re);
|
||||
|
||||
// 更新 产品队列
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_ProductList); //
|
||||
if (!m_ProductList.empty())
|
||||
{
|
||||
m_ProductList.erase(m_ProductList.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int ALLImgCheckAnalysisy::set_cpu_id(const std::vector<int> &cpu_set_vec)
|
||||
{
|
||||
// for cpu affinity
|
||||
int nRet = 0;
|
||||
#ifdef __linux
|
||||
cpu_set_t _cur_cpu_set;
|
||||
CPU_ZERO(&_cur_cpu_set);
|
||||
for (auto _id : cpu_set_vec)
|
||||
{
|
||||
CPU_SET(_id, &_cur_cpu_set);
|
||||
}
|
||||
if (0 > pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &_cur_cpu_set))
|
||||
{
|
||||
perror("set cpu affinity failed: ");
|
||||
printf("Warning: set cpu affinity failed ... ...\n");
|
||||
nRet = -1;
|
||||
}
|
||||
#endif //__linux
|
||||
return nRet;
|
||||
}
|
||||
@ -0,0 +1,979 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "BlobBase.h"
|
||||
void pretest(double x)
|
||||
{
|
||||
printf("fff %f \n", x);
|
||||
}
|
||||
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
static inline int GetType(int nvalue, int *qx_list)
|
||||
{
|
||||
// int re = 0;
|
||||
// if ((nvalue & Value_ERR_TYPE_1) != 0)
|
||||
// {
|
||||
// re = 1;
|
||||
// qx_list[ERR_TYPE_1] = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qx_list[ERR_TYPE_1] = 0;
|
||||
// }
|
||||
// if ((nvalue & Value_ERR_TYPE_2) != 0)
|
||||
// {
|
||||
// re = 1;
|
||||
// qx_list[ERR_TYPE_2] = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qx_list[ERR_TYPE_2] = 0;
|
||||
// }
|
||||
|
||||
// return re;
|
||||
qx_list[ERR_TYPE_1] = !!(nvalue & Value_ERR_TYPE_1);
|
||||
qx_list[ERR_TYPE_2] = !!(nvalue & Value_ERR_TYPE_2);
|
||||
|
||||
return qx_list[ERR_TYPE_1] | qx_list[ERR_TYPE_2];
|
||||
}
|
||||
//-------------sxg added
|
||||
|
||||
void AddErrorScan(ERROR_DOTS_SCAN_ROW *curRow, ERROR_DOTS_SCAN_ROW *prevRow, int x, int len, int y, int difSum, int minArea, int minEng, int mdx, int *pErrClass)
|
||||
{
|
||||
|
||||
if (curRow->scanCount < _MAX_ERROR_SCAN_LINE_PER_ROW)
|
||||
{
|
||||
|
||||
int lastScanLineIndex = curRow->scanCount++;
|
||||
ERROR_DOTS_SCAN_DATA *scan = curRow->errorScanLineTab + lastScanLineIndex;
|
||||
scan->x = x;
|
||||
scan->count = len;
|
||||
int ex = x + len - 1;
|
||||
scan->energy = difSum;
|
||||
scan->area = scan->count;
|
||||
scan->xposSum = (x + (len >> 1)) * len;
|
||||
scan->yposSum = y * len;
|
||||
scan->minx = x;
|
||||
scan->miny = y;
|
||||
scan->maxx = ex;
|
||||
scan->maxy = y;
|
||||
scan->macro = mdx;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
scan->ErrClass[ec] = pErrClass[ec];
|
||||
}
|
||||
|
||||
curRow->macro[scan->macro] = len;
|
||||
|
||||
int linkIndexTab[_MAX_ERROR_SCAN_LINE_PER_ROW];
|
||||
int linkCount = 0;
|
||||
if (prevRow)
|
||||
{
|
||||
for (int t = 0; t < _MAX_MACRO_COUNT; t++)
|
||||
{
|
||||
curRow->macro[t] += prevRow->macro[t];
|
||||
// prevRow->macro[t]=0;
|
||||
}
|
||||
|
||||
int prevLastScanLineIndex = prevRow->scanCount - 1;
|
||||
ERROR_DOTS_SCAN_DATA *pscan = prevRow->errorScanLineTab + prevLastScanLineIndex;
|
||||
for (; prevLastScanLineIndex >= 0; --prevLastScanLineIndex, --pscan)
|
||||
{
|
||||
int psx = pscan->x - 1;
|
||||
int pex = psx + pscan->count - 1 + 1;
|
||||
// sxg modified waitting for valid 9.5
|
||||
if (x <= pex && ex >= psx)
|
||||
{
|
||||
if (pscan->area > 0)
|
||||
{
|
||||
int area = scan->area + (pscan->area);
|
||||
scan->area = area;
|
||||
if (scan->macro != pscan->macro)
|
||||
{
|
||||
if (scan->macro < pscan->macro)
|
||||
scan->macro = pscan->macro;
|
||||
}
|
||||
scan->energy += pscan->energy;
|
||||
scan->xposSum += pscan->xposSum;
|
||||
scan->yposSum += pscan->yposSum;
|
||||
scan->minx = min(scan->minx, pscan->minx);
|
||||
scan->miny = min(scan->miny, pscan->miny);
|
||||
scan->maxx = max(scan->maxx, pscan->maxx);
|
||||
scan->maxy = max(scan->maxy, pscan->maxy);
|
||||
pscan->area = 0;
|
||||
pscan->energy = lastScanLineIndex;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
scan->ErrClass[ec] = pErrClass[ec] + (pscan->ErrClass[ec]);
|
||||
}
|
||||
linkIndexTab[/*0xff & */ (linkCount++)] = prevLastScanLineIndex;
|
||||
}
|
||||
// else
|
||||
//{
|
||||
// int bindex = 0xff & pscan->energy;
|
||||
// ERROR_DOTS_SCAN_DATA * hscan = curRow->errorScanLineTab + bindex;
|
||||
// hscan->count = ex - hscan->x + 1;
|
||||
// hscan->area += scan->area;
|
||||
// hscan->energy += scan->energy;
|
||||
// hscan->xposSum += scan->xposSum;
|
||||
// hscan->yposSum += scan->yposSum;
|
||||
// hscan->minx = min(scan->minx , hscan->minx);
|
||||
// hscan->miny = min(scan->miny , hscan->miny);
|
||||
// hscan->maxx = max(scan->maxx , hscan->maxx);
|
||||
// hscan->maxy = max(scan->maxy , hscan->maxy);
|
||||
// scan->area = 0;
|
||||
// for(;linkCount > 0 ; --linkCount)
|
||||
// {
|
||||
// ERROR_DOTS_SCAN_DATA * p = prevRow->errorScanLineTab + linkIndexTab[0xff & (linkCount - 1)];
|
||||
// p->energy = bindex;
|
||||
// }
|
||||
// curRow->scanCount--;
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LinkScanLineToBlob(ERROR_DOTS_BLOBS *blobs, ERROR_DOTS_SCAN_ROW *prevRow, int sx, int sy, int minArea, int minEnergy, int mergeDistanceX, int mergeDistanceY, int width)
|
||||
{
|
||||
if (prevRow)
|
||||
{
|
||||
int prevLastScanLineIndex = prevRow->scanCount - 1;
|
||||
ERROR_DOTS_SCAN_DATA *pscan = prevRow->errorScanLineTab + prevLastScanLineIndex;
|
||||
// int minArea = param->minArea;
|
||||
// int minEnergy = param->minEnergy;
|
||||
for (; prevLastScanLineIndex >= 0; --prevLastScanLineIndex, --pscan)
|
||||
{
|
||||
if (pscan->area > 0)
|
||||
{
|
||||
int x = pscan->xposSum / pscan->area + sx;
|
||||
int y = pscan->yposSum / pscan->area + sy;
|
||||
int minx = pscan->minx + sx;
|
||||
int miny = pscan->miny + sy;
|
||||
int maxx = pscan->maxx + sx;
|
||||
int maxy = pscan->maxy + sy;
|
||||
if (x < width)
|
||||
{
|
||||
int blobIndex = blobs->blobCount;
|
||||
// int mergeDistance = param->mergeDistance;
|
||||
ERROR_DOTS_BLOB_DATA *pblob = blobs->blobTab + blobIndex - 1;
|
||||
int left = minx - mergeDistanceX, right = maxx + mergeDistanceX;
|
||||
int top = miny - mergeDistanceY, bottom = maxy + mergeDistanceY;
|
||||
for (int i = blobIndex - 1; i >= 0; --i, --pblob)
|
||||
{
|
||||
|
||||
if (1)
|
||||
{
|
||||
if (pblob->maxy > top && pblob->miny < bottom)
|
||||
{
|
||||
if (pblob->maxx > left && pblob->minx < right)
|
||||
{
|
||||
int area = pblob->area + pscan->area;
|
||||
pblob->x = (pblob->x * pblob->area + x * pscan->area) / area;
|
||||
pblob->y = (pblob->y * pblob->area + y * pscan->area) / area;
|
||||
pblob->area = area;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
pblob->ErrClass[ec] += pscan->ErrClass[ec];
|
||||
}
|
||||
|
||||
pblob->energy += pscan->energy;
|
||||
pblob->minx = min(pblob->minx, minx);
|
||||
pblob->miny = min(pblob->miny, miny);
|
||||
pblob->maxx = max(pblob->maxx, maxx);
|
||||
pblob->maxy = max(pblob->maxy, maxy);
|
||||
pblob->macro[pscan->macro] += prevRow->macro[pscan->macro];
|
||||
prevRow->macro[pscan->macro] -= pscan->area;
|
||||
blobIndex = _MAX_ERROR_DOT_BLOB;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pscan->area > minArea /*|| pscan->energy > minEnergy*/)
|
||||
{
|
||||
if (blobIndex < _MAX_ERROR_DOT_BLOB)
|
||||
{
|
||||
pblob = blobs->blobTab + blobIndex;
|
||||
pblob->x = x;
|
||||
pblob->y = y;
|
||||
pblob->area = pscan->area;
|
||||
pblob->energy = pscan->energy;
|
||||
pblob->minx = minx;
|
||||
pblob->miny = miny;
|
||||
pblob->maxx = maxx;
|
||||
pblob->maxy = maxy;
|
||||
blobs->blobCount++;
|
||||
for (int t = 0; t < _MAX_MACRO_COUNT; t++)
|
||||
{
|
||||
pblob->macro[t] = 0;
|
||||
}
|
||||
pblob->macro[pscan->macro] = pscan->area;
|
||||
prevRow->macro[pscan->macro] -= pscan->area;
|
||||
// prevRow->macro[pscan->macro]=0;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
pblob->ErrClass[ec] = pscan->ErrClass[ec];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pscan->area = 0;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
pscan->ErrClass[ec] = 0;
|
||||
}
|
||||
}
|
||||
// for (int t=0;t<MAX_MACRO_COUNT;t++)
|
||||
//{
|
||||
// //curRow->macro[t]+=prevRow->macro[t];
|
||||
// prevRow->macro[t]=0;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void MergeBlob(ERROR_DOTS_BLOBS *blobs, ERROR_DOTS_BLOB_PARAM *param)
|
||||
{
|
||||
int count = blobs->blobCount;
|
||||
ERROR_DOTS_BLOB_DATA *blob = blobs->blobTab + count - 1;
|
||||
int pace = param->mergeDistance;
|
||||
for (int i = count - 1; i > 0; --i, --blob)
|
||||
{
|
||||
int minx = blob->minx;
|
||||
int miny = blob->miny;
|
||||
int maxx = blob->maxx;
|
||||
int maxy = blob->maxy;
|
||||
int energy = blob->energy;
|
||||
|
||||
int left = minx - pace, right = maxx + pace;
|
||||
int top = miny - 1, bottom = maxy + 1;
|
||||
ERROR_DOTS_BLOB_DATA *pblob = blob - 1;
|
||||
for (int j = i - 1; j >= 0; --j, --pblob)
|
||||
{
|
||||
|
||||
if (pblob->ErrType == blob->ErrType)
|
||||
{
|
||||
if (pblob->maxy > top && pblob->miny < bottom)
|
||||
{
|
||||
if (pblob->maxx > left && pblob->minx < right)
|
||||
{
|
||||
int areaSum = pblob->area + blob->area;
|
||||
int x = blob->x, y = blob->y;
|
||||
pblob->x = (pblob->x * pblob->area + x * blob->area) / areaSum;
|
||||
pblob->y = (pblob->y * pblob->area + y * blob->area) / areaSum;
|
||||
pblob->area = areaSum;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
pblob->ErrClass[ec] += blob->ErrClass[ec];
|
||||
}
|
||||
|
||||
pblob->energy += energy;
|
||||
pblob->minx = min(pblob->minx, minx);
|
||||
pblob->miny = min(pblob->miny, miny);
|
||||
pblob->maxx = max(pblob->maxx, maxx);
|
||||
pblob->maxy = max(pblob->maxy, maxy);
|
||||
for (int t = 0; t < _MAX_MACRO_COUNT; t++)
|
||||
{
|
||||
pblob->macro[t] += blob->macro[t];
|
||||
blob->macro[t] = 0;
|
||||
}
|
||||
count--;
|
||||
memmove(blob, blob + 1, (count - i) * sizeof(blob[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
blobs->blobCount = count;
|
||||
}
|
||||
// static int __cdecl compareBlob(const void * p1, const void * p2)
|
||||
static int compareBlob(const void *p1, const void *p2)
|
||||
{
|
||||
ERROR_DOTS_BLOB_DATA *b1 = (ERROR_DOTS_BLOB_DATA *)p1;
|
||||
ERROR_DOTS_BLOB_DATA *b2 = (ERROR_DOTS_BLOB_DATA *)p2;
|
||||
return (b2->area) - (b1->area);
|
||||
}
|
||||
|
||||
void SortBlob(ERROR_DOTS_BLOBS *blobs)
|
||||
{
|
||||
int count = blobs->blobCount;
|
||||
ERROR_DOTS_BLOB_DATA *blob = blobs->blobTab;
|
||||
qsort(blob, count, sizeof(blob[0]), compareBlob);
|
||||
}
|
||||
|
||||
// 当前行和前面行合并
|
||||
void AddErrorScan_New(ERROR_DOTS_SCAN_ROW *curRow, ERROR_DOTS_SCAN_ROW *prevRow, int x, int len, int y, int difSum, int minArea, int minEng, int errorType)
|
||||
{
|
||||
if (curRow->scanCount < _MAX_ERROR_SCAN_LINE_PER_ROW)
|
||||
{
|
||||
|
||||
int lastScanLineIndex = curRow->scanCount++;
|
||||
ERROR_DOTS_SCAN_DATA *scan = curRow->errorScanLineTab + lastScanLineIndex;
|
||||
scan->x = x;
|
||||
scan->count = len;
|
||||
int ex = x + len - 1;
|
||||
scan->energy = difSum;
|
||||
scan->area = scan->count;
|
||||
scan->xposSum = (x + (len >> 1)) * len;
|
||||
scan->yposSum = y * len;
|
||||
scan->minx = x;
|
||||
scan->miny = y;
|
||||
scan->maxx = ex;
|
||||
scan->maxy = y;
|
||||
scan->type = errorType;
|
||||
|
||||
if (prevRow)
|
||||
{
|
||||
int prevLastScanLineIndex = prevRow->scanCount - 1;
|
||||
ERROR_DOTS_SCAN_DATA *pscan = prevRow->errorScanLineTab + prevLastScanLineIndex;
|
||||
for (; prevLastScanLineIndex >= 0; --prevLastScanLineIndex, --pscan)
|
||||
{
|
||||
int psx = pscan->x - 1;
|
||||
int pex = psx + pscan->count - 1 + 1;
|
||||
if (x <= pex && ex >= psx && pscan->type == scan->type)
|
||||
{
|
||||
if (pscan->area > 0)
|
||||
{
|
||||
int area = scan->area + (pscan->area);
|
||||
scan->area = area;
|
||||
scan->energy += pscan->energy;
|
||||
scan->xposSum += pscan->xposSum;
|
||||
scan->yposSum += pscan->yposSum;
|
||||
scan->minx = min(scan->minx, pscan->minx);
|
||||
scan->miny = min(scan->miny, pscan->miny);
|
||||
scan->maxx = max(scan->maxx, pscan->maxx);
|
||||
scan->maxy = max(scan->maxy, pscan->maxy);
|
||||
pscan->area = 0;
|
||||
pscan->energy = lastScanLineIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LinkScanLineToBlob_New(ERROR_DOTS_BLOBS *blobs, ERROR_DOTS_SCAN_ROW *prevRow, int sx, int sy, int minArea, int minEnergy, int mergeDistanceX, int mergeDistanceY, int width)
|
||||
{
|
||||
if (prevRow)
|
||||
{
|
||||
int prevLastScanLineIndex = prevRow->scanCount - 1;
|
||||
ERROR_DOTS_SCAN_DATA *pscan = prevRow->errorScanLineTab + prevLastScanLineIndex;
|
||||
// int minArea = param->minArea;
|
||||
// int minEnergy = param->minEnergy;
|
||||
for (; prevLastScanLineIndex >= 0; --prevLastScanLineIndex, --pscan)
|
||||
{
|
||||
if (pscan->area > 0)
|
||||
{
|
||||
int x = pscan->xposSum / pscan->area + sx;
|
||||
int y = pscan->yposSum / pscan->area + sy;
|
||||
int minx = pscan->minx + sx;
|
||||
int miny = pscan->miny + sy;
|
||||
int maxx = pscan->maxx + sx;
|
||||
int maxy = pscan->maxy + sy;
|
||||
if (x < width)
|
||||
{
|
||||
int blobIndex = blobs->blobCount;
|
||||
// int mergeDistance = param->mergeDistance;
|
||||
ERROR_DOTS_BLOB_DATA *pblob = blobs->blobTab + blobIndex - 1;
|
||||
int left = minx - mergeDistanceX, right = maxx + mergeDistanceX;
|
||||
int top = miny - mergeDistanceY, bottom = maxy + mergeDistanceY;
|
||||
for (int i = blobIndex - 1; i >= 0; --i, --pblob)
|
||||
{
|
||||
if (pblob->ErrType == pscan->type)
|
||||
{
|
||||
if (pblob->maxy > top && pblob->miny < bottom)
|
||||
{
|
||||
if (pblob->maxx > left && pblob->minx < right)
|
||||
{
|
||||
int area = pblob->area + pscan->area;
|
||||
pblob->x = (pblob->x * pblob->area + x * pscan->area) / area;
|
||||
pblob->y = (pblob->y * pblob->area + y * pscan->area) / area;
|
||||
pblob->area = area;
|
||||
// for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
// {
|
||||
// pblob->ErrClass[ec] += pscan->ErrClass[ec];
|
||||
// }
|
||||
|
||||
pblob->energy += pscan->energy;
|
||||
pblob->minx = min(pblob->minx, minx);
|
||||
pblob->miny = min(pblob->miny, miny);
|
||||
pblob->maxx = max(pblob->maxx, maxx);
|
||||
pblob->maxy = max(pblob->maxy, maxy);
|
||||
// pblob->macro[pscan->macro] += prevRow->macro[pscan->macro];
|
||||
// prevRow->macro[pscan->macro] -= pscan->area;
|
||||
blobIndex = _MAX_ERROR_DOT_BLOB;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pscan->area > minArea /*|| pscan->energy > minEnergy*/)
|
||||
{
|
||||
if (blobIndex < _MAX_ERROR_DOT_BLOB)
|
||||
{
|
||||
pblob = blobs->blobTab + blobIndex;
|
||||
pblob->x = x;
|
||||
pblob->y = y;
|
||||
pblob->area = pscan->area;
|
||||
pblob->energy = pscan->energy;
|
||||
pblob->ErrType = pscan->type;
|
||||
pblob->minx = minx;
|
||||
pblob->miny = miny;
|
||||
pblob->maxx = maxx;
|
||||
pblob->maxy = maxy;
|
||||
blobs->blobCount++;
|
||||
// for (int t = 0; t < _MAX_MACRO_COUNT; t++)
|
||||
// {
|
||||
// pblob->macro[t] = 0;
|
||||
// }
|
||||
// pblob->macro[pscan->macro] = pscan->area;
|
||||
// prevRow->macro[pscan->macro] -= pscan->area;
|
||||
// prevRow->macro[pscan->macro]=0;
|
||||
// for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
// {
|
||||
// pblob->ErrClass[ec] = pscan->ErrClass[ec];
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pscan->area = 0;
|
||||
for (int ec = 0; ec < _MAX_ERR_CLASS; ec++)
|
||||
{
|
||||
pscan->ErrClass[ec] = 0;
|
||||
}
|
||||
}
|
||||
// for (int t=0;t<MAX_MACRO_COUNT;t++)
|
||||
//{
|
||||
// //curRow->macro[t]+=prevRow->macro[t];
|
||||
// prevRow->macro[t]=0;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
int GetBlobs_V2(ERROR_DOTS_BLOBS *blobs, unsigned char *pImgdata, unsigned char *pErrordata, int width, int height, int basev, int minArea)
|
||||
{
|
||||
|
||||
if (blobs == NULL || pErrordata == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int pitch = width;
|
||||
int offset;
|
||||
|
||||
int point_is_err = 0;
|
||||
int wLineErrsList = 0;
|
||||
int errPos_xList = 0;
|
||||
int difSumList = 0;
|
||||
int point_is_errList = 0;
|
||||
|
||||
// memset(blobs, 0x00, sizeof(ERROR_DOTS_BLOBS));
|
||||
|
||||
ERROR_DOTS_SCAN_ROW rowDataTab[2];
|
||||
ERROR_DOTS_SCAN_ROW *curRow = 0;
|
||||
ERROR_DOTS_SCAN_ROW *prevRow = 0;
|
||||
|
||||
int MIN_AREA = minArea;
|
||||
if (minArea <= 0)
|
||||
{
|
||||
MIN_AREA = 10;
|
||||
}
|
||||
|
||||
int minEnergy = 2;
|
||||
int mergeDistanceX = 1;
|
||||
int mergeDistanceY = 1;
|
||||
offset = 0;
|
||||
int nErrorType = 0;
|
||||
int lasttype = -1;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
curRow = rowDataTab + (y & 1);
|
||||
curRow->scanCount = 0;
|
||||
offset = y * pitch - 1;
|
||||
nErrorType = -1;
|
||||
lasttype = -1;
|
||||
int kh = 0;
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
offset++;
|
||||
point_is_err = 0;
|
||||
if (pErrordata[offset] != 0 && pImgdata[offset] > basev)
|
||||
{
|
||||
point_is_err = 1;
|
||||
difSumList += 1;
|
||||
wLineErrsList++;
|
||||
errPos_xList = x;
|
||||
kh = 1;
|
||||
}
|
||||
else // 没有残点 所有缺陷都需要判断是否截止
|
||||
{
|
||||
// 当前点 该缺陷类型 为FALSE 并且 改缺陷类型 有过残点
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
}
|
||||
kh = 0;
|
||||
}
|
||||
|
||||
if (x == width - 1)
|
||||
{
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
|
||||
prevRow = curRow;
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
ERROR_DOTS_BLOB_PARAM blobParam;
|
||||
memset(&blobParam, 0x00, sizeof(ERROR_DOTS_BLOB_PARAM));
|
||||
blobParam.mergeDistance = 1;
|
||||
MergeBlob(blobs, &blobParam);
|
||||
SortBlob(blobs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobs_V3(ERROR_DOTS_BLOBS *blobs, unsigned char *pErrordata, int width, int height, int minArea)
|
||||
{
|
||||
|
||||
if (blobs == NULL || pErrordata == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int pitch = width;
|
||||
int offset;
|
||||
|
||||
int point_is_err = 0;
|
||||
int wLineErrsList = 0;
|
||||
int errPos_xList = 0;
|
||||
int difSumList = 0;
|
||||
int point_is_errList = 0;
|
||||
|
||||
// memset(blobs, 0x00, sizeof(ERROR_DOTS_BLOBS));
|
||||
|
||||
ERROR_DOTS_SCAN_ROW rowDataTab[2];
|
||||
ERROR_DOTS_SCAN_ROW *curRow = 0;
|
||||
ERROR_DOTS_SCAN_ROW *prevRow = 0;
|
||||
|
||||
int MIN_AREA = minArea;
|
||||
if (minArea <= 0)
|
||||
{
|
||||
MIN_AREA = 10;
|
||||
}
|
||||
|
||||
int minEnergy = 2;
|
||||
int mergeDistanceX = 20;
|
||||
int mergeDistanceY = 20;
|
||||
offset = 0;
|
||||
int nErrorType = 0;
|
||||
int lasttype = -1;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
curRow = rowDataTab + (y & 1);
|
||||
curRow->scanCount = 0;
|
||||
offset = y * pitch - 1;
|
||||
nErrorType = -1;
|
||||
lasttype = -1;
|
||||
int kh = 0;
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
offset++;
|
||||
point_is_err = 0;
|
||||
if (pErrordata[offset] != 0)
|
||||
{
|
||||
point_is_err = 1;
|
||||
difSumList += 1;
|
||||
wLineErrsList++;
|
||||
errPos_xList = x;
|
||||
kh = 1;
|
||||
}
|
||||
else // 没有残点 所有缺陷都需要判断是否截止
|
||||
{
|
||||
// 当前点 该缺陷类型 为FALSE 并且 改缺陷类型 有过残点
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
}
|
||||
kh = 0;
|
||||
}
|
||||
|
||||
if (x == width - 1)
|
||||
{
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
|
||||
prevRow = curRow;
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
ERROR_DOTS_BLOB_PARAM blobParam;
|
||||
memset(&blobParam, 0x00, sizeof(ERROR_DOTS_BLOB_PARAM));
|
||||
blobParam.mergeDistance = 1;
|
||||
MergeBlob(blobs, &blobParam);
|
||||
SortBlob(blobs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobs_V3_CA(ERROR_DOTS_BLOBS *blobs, unsigned char *pErrordata, int width, int height, int minArea, int err_1_value, int err_2_value)
|
||||
{
|
||||
|
||||
if (blobs == NULL || pErrordata == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int pitch = width;
|
||||
int offset;
|
||||
|
||||
int point_is_err = 0;
|
||||
int wLineErrsList = 0;
|
||||
int errPos_xList = 0;
|
||||
int difSumList = 0;
|
||||
int point_is_errList = 0;
|
||||
|
||||
// memset(blobs, 0x00, sizeof(ERROR_DOTS_BLOBS));
|
||||
|
||||
ERROR_DOTS_SCAN_ROW rowDataTab[2];
|
||||
ERROR_DOTS_SCAN_ROW *curRow = 0;
|
||||
ERROR_DOTS_SCAN_ROW *prevRow = 0;
|
||||
|
||||
int MIN_AREA = minArea;
|
||||
if (minArea <= 0)
|
||||
{
|
||||
MIN_AREA = 10;
|
||||
}
|
||||
|
||||
int minEnergy = 2;
|
||||
int mergeDistanceX = 20;
|
||||
int mergeDistanceY = 20;
|
||||
offset = 0;
|
||||
int nErrorType = 0;
|
||||
int lasttype = -1;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
curRow = rowDataTab + (y & 1);
|
||||
curRow->scanCount = 0;
|
||||
offset = y * pitch - 1;
|
||||
nErrorType = -1;
|
||||
lasttype = -1;
|
||||
int kh = 0;
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
offset++;
|
||||
point_is_err = 0;
|
||||
if (pErrordata[offset] == err_1_value || pErrordata[offset] == err_2_value)
|
||||
{
|
||||
point_is_err = 1;
|
||||
difSumList += 1;
|
||||
wLineErrsList++;
|
||||
errPos_xList = x;
|
||||
kh = 1;
|
||||
}
|
||||
else // 没有残点 所有缺陷都需要判断是否截止
|
||||
{
|
||||
// 当前点 该缺陷类型 为FALSE 并且 改缺陷类型 有过残点
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
}
|
||||
kh = 0;
|
||||
}
|
||||
|
||||
if (x == width - 1)
|
||||
{
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
|
||||
prevRow = curRow;
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
ERROR_DOTS_BLOB_PARAM blobParam;
|
||||
memset(&blobParam, 0x00, sizeof(ERROR_DOTS_BLOB_PARAM));
|
||||
blobParam.mergeDistance = 1;
|
||||
MergeBlob(blobs, &blobParam);
|
||||
SortBlob(blobs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobs_ALL_New(ERROR_DOTS_BLOBS *blobs, unsigned char *pErrordata, unsigned char *pHdata, int width, int height, int minArea)
|
||||
{
|
||||
if (blobs == NULL || pErrordata == NULL || pHdata == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int pitch = width;
|
||||
int offset;
|
||||
|
||||
int point_is_err = 0;
|
||||
int wLineErrsList[ERR_TYPE_COUNT] = {0};
|
||||
int errPos_xList[ERR_TYPE_COUNT] = {0};
|
||||
int difSumList[ERR_TYPE_COUNT] = {0};
|
||||
|
||||
memset(blobs, 0x00, sizeof(ERROR_DOTS_BLOBS));
|
||||
|
||||
ERROR_DOTS_SCAN_ROW rowDataTab[2];
|
||||
ERROR_DOTS_SCAN_ROW *curRow = 0;
|
||||
ERROR_DOTS_SCAN_ROW *prevRow = 0;
|
||||
|
||||
// int MIN_AREA = 2;
|
||||
int MIN_AREA = minArea;
|
||||
if (minArea <= 0)
|
||||
{
|
||||
MIN_AREA = 10;
|
||||
}
|
||||
int minEnergy = 2;
|
||||
int mergeDistanceX = 25;
|
||||
int mergeDistanceY = 25;
|
||||
offset = 0;
|
||||
int nErrorType = 0;
|
||||
int lasttype = -1;
|
||||
int qx_list[ERR_TYPE_COUNT] = {0};
|
||||
int kv = 0;
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
if (kv == 1)
|
||||
{
|
||||
memset(&wLineErrsList, 0, sizeof(int) * ERR_TYPE_COUNT);
|
||||
memset(&difSumList, 0, sizeof(int) * ERR_TYPE_COUNT);
|
||||
}
|
||||
unsigned char *p = pErrordata + y * pitch;
|
||||
curRow = rowDataTab + (y & 1);
|
||||
curRow->scanCount = 0;
|
||||
offset = y * pitch;
|
||||
nErrorType = -1;
|
||||
lasttype = -1;
|
||||
kv = 0;
|
||||
// 表示 这一行缺陷残点
|
||||
if (pHdata[y])
|
||||
{
|
||||
for (int x = 0; x < width; x++, p++)
|
||||
{
|
||||
point_is_err = 0;
|
||||
if (*p)
|
||||
{
|
||||
point_is_err = GetType(*p, qx_list);
|
||||
kv = 1;
|
||||
for (int qx_i = 0; qx_i < ERR_TYPE_COUNT; qx_i++)
|
||||
{
|
||||
if (qx_list[qx_i] > 0)
|
||||
{
|
||||
difSumList[qx_i] += 1;
|
||||
wLineErrsList[qx_i]++;
|
||||
errPos_xList[qx_i] = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (kv == 1) // 这一行有残点
|
||||
{
|
||||
for (int qx_i = 0; qx_i < ERR_TYPE_COUNT; qx_i++)
|
||||
{
|
||||
if (wLineErrsList[qx_i] > 0)
|
||||
{
|
||||
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList[qx_i] - wLineErrsList[qx_i] + 1, wLineErrsList[qx_i], y, difSumList[qx_i], 0, 0, qx_i);
|
||||
wLineErrsList[qx_i] = 0;
|
||||
difSumList[qx_i] = 0;
|
||||
}
|
||||
if (!wLineErrsList[ERR_TYPE_1] && !wLineErrsList[ERR_TYPE_2])
|
||||
{
|
||||
kv = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x == width - 1)
|
||||
{
|
||||
for (int qx_i = 0; qx_i < ERR_TYPE_COUNT; qx_i++)
|
||||
{
|
||||
if (wLineErrsList[qx_i] > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList[qx_i] - wLineErrsList[qx_i] + 1, wLineErrsList[qx_i], y, difSumList[qx_i], 0, 0, qx_i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// offset++;
|
||||
}
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
|
||||
prevRow = curRow;
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
ERROR_DOTS_BLOB_PARAM blobParam;
|
||||
memset(&blobParam, 0x00, sizeof(ERROR_DOTS_BLOB_PARAM));
|
||||
blobParam.mergeDistance = 1;
|
||||
blobs->srcBlobCount = blobs->blobCount;
|
||||
MergeBlob(blobs, &blobParam);
|
||||
SortBlob(blobs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobs_oneLabe(ERROR_DOTS_BLOBS *blobs, unsigned char *pErrordata, unsigned char *pHdata, int width, int height, int minArea)
|
||||
{
|
||||
if (blobs == NULL || pErrordata == NULL || pHdata == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pitch = width;
|
||||
int offset;
|
||||
|
||||
int point_is_err = 0;
|
||||
int wLineErrsList = 0;
|
||||
int errPos_xList = 0;
|
||||
int difSumList = 0;
|
||||
int point_is_errList = 0;
|
||||
|
||||
// memset(blobs, 0x00, sizeof(ERROR_DOTS_BLOBS));
|
||||
|
||||
ERROR_DOTS_SCAN_ROW rowDataTab[2];
|
||||
ERROR_DOTS_SCAN_ROW *curRow = 0;
|
||||
ERROR_DOTS_SCAN_ROW *prevRow = 0;
|
||||
|
||||
int MIN_AREA = minArea;
|
||||
if (minArea <= 0)
|
||||
{
|
||||
MIN_AREA = 10;
|
||||
}
|
||||
|
||||
int minEnergy = 2;
|
||||
int mergeDistanceX = 20;
|
||||
int mergeDistanceY = 20;
|
||||
offset = 0;
|
||||
int nErrorType = 0;
|
||||
int lasttype = -1;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
curRow = rowDataTab + (y & 1);
|
||||
curRow->scanCount = 0;
|
||||
offset = y * pitch - 1;
|
||||
nErrorType = -1;
|
||||
lasttype = -1;
|
||||
int kh = 0;
|
||||
// 表示 这一行缺陷残点
|
||||
if (pHdata[y])
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
offset++;
|
||||
point_is_err = 0;
|
||||
if (pErrordata[offset] != 0)
|
||||
{
|
||||
point_is_err = 1;
|
||||
difSumList += 1;
|
||||
wLineErrsList++;
|
||||
errPos_xList = x;
|
||||
kh = 1;
|
||||
}
|
||||
else // 没有残点 所有缺陷都需要判断是否截止
|
||||
{
|
||||
// 当前点 该缺陷类型 为FALSE 并且 改缺陷类型 有过残点
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
wLineErrsList = 0;
|
||||
difSumList = 0;
|
||||
}
|
||||
kh = 0;
|
||||
}
|
||||
|
||||
if (x == width - 1)
|
||||
{
|
||||
if (wLineErrsList > 0)
|
||||
{
|
||||
AddErrorScan_New(curRow, prevRow, errPos_xList - wLineErrsList + 1, wLineErrsList, y, difSumList, 0, 0, ERR_TYPE_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
|
||||
prevRow = curRow;
|
||||
}
|
||||
|
||||
LinkScanLineToBlob_New(blobs, prevRow, 0, 0, MIN_AREA, minEnergy, mergeDistanceX, mergeDistanceY, width);
|
||||
ERROR_DOTS_BLOB_PARAM blobParam;
|
||||
memset(&blobParam, 0x00, sizeof(ERROR_DOTS_BLOB_PARAM));
|
||||
blobParam.mergeDistance = 1;
|
||||
blobs->srcBlobCount = blobs->blobCount;
|
||||
MergeBlob(blobs, &blobParam);
|
||||
SortBlob(blobs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PushBlob(ERROR_DOTS_BLOBS *blobs, ERROR_DOTS_BLOBS *addblobs)
|
||||
{
|
||||
for (int i = 0; i < addblobs->blobCount; i++)
|
||||
{
|
||||
int bhave = 0;
|
||||
for (int j = 0; j < addblobs->blobCount; j++)
|
||||
{
|
||||
if (addblobs->blobTab[i].ErrType == blobs->blobTab[j].ErrType &&
|
||||
addblobs->blobTab[i].minx == blobs->blobTab[j].minx &&
|
||||
addblobs->blobTab[i].miny == blobs->blobTab[j].miny &&
|
||||
addblobs->blobTab[i].maxx == blobs->blobTab[j].maxx &&
|
||||
addblobs->blobTab[i].maxy == blobs->blobTab[j].maxy)
|
||||
{
|
||||
bhave = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bhave)
|
||||
{
|
||||
int ncount = blobs->blobCount;
|
||||
if (ncount < _MAX_ERROR_DOT_BLOB)
|
||||
{
|
||||
memcpy(&blobs->blobTab[ncount], &addblobs->blobTab[i], sizeof(ERROR_DOTS_BLOB_DATA));
|
||||
blobs->blobCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-09-13 20:39:37
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-17 16:39:47
|
||||
* @FilePath: /BOE_CELL_AOI_Detect/AlgorithmModule/src/CameraResult.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "CameraResult.h"
|
||||
|
||||
CameraResult::CameraResult()
|
||||
{
|
||||
cameraBaseResult = std::make_shared<CameraBaseResult>();
|
||||
detlog = std::make_shared<DetLog>();
|
||||
time_start = 0;
|
||||
}
|
||||
|
||||
CameraResult::~CameraResult()
|
||||
{
|
||||
}
|
||||
|
||||
void CameraResult::AddLog(std::string str)
|
||||
{
|
||||
LogList.push_back(str);
|
||||
}
|
||||
|
||||
int CameraResult::AddDetImage(std::shared_ptr<shareImage> p)
|
||||
{
|
||||
if (time_start == 0)
|
||||
{
|
||||
time_start = CheckUtil::getcurTime();
|
||||
/* code */
|
||||
}
|
||||
|
||||
std::shared_ptr<ImageAllResult> imgResult = std::make_shared<ImageAllResult>();
|
||||
imgResult->cameraBaseResult = cameraBaseResult;
|
||||
imgResult->productBaseResult = productBaseResult;
|
||||
if (p->Det_Mode == DET_MODE_ReJson)
|
||||
{
|
||||
bJson = true;
|
||||
}
|
||||
|
||||
imgResult->AddDetImage(p);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_DetImageList);
|
||||
ImageALLDetResultList.push_back(imgResult);
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
cameraImage_Status.bHaveImg = true;
|
||||
cameraImage_Status.bHave_L255 = true;
|
||||
}
|
||||
std::string strTimg = CheckUtil::getCurTimeHMS();
|
||||
|
||||
detlog->AddCheckstr(PrintLevel_0, "PushInImg", " product %s Cam %s add new image channel = %s %s",
|
||||
productBaseResult->strproductName.c_str(),
|
||||
cameraBaseResult->strCameraName.c_str(), imgResult->strChannel.c_str(), strTimg.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CameraResult::bCheckCamplate()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
|
||||
if (checkStep == Check_Step_Complete)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Check_Step CameraResult::GetCheckStep()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
return checkStep;
|
||||
}
|
||||
|
||||
void CameraResult::SetCheckStep(Check_Step step)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
checkStep = step;
|
||||
}
|
||||
|
||||
bool CameraResult::getImgPushComplate()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
return bIsImgComplete;
|
||||
}
|
||||
|
||||
void CameraResult::setImgPushComplate()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
bIsImgComplete = true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ImageAllResult> CameraResult::GetNoDetImg()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_DetImageList);
|
||||
for (auto ptr : ImageALLDetResultList)
|
||||
{
|
||||
if (ptr->IsNotDet())
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
std::string GetErrorCodeInfo(int nErrorCode)
|
||||
{
|
||||
std::string str = "";
|
||||
switch (nErrorCode)
|
||||
{
|
||||
case CHECK_OK:
|
||||
str = "OK";
|
||||
break;
|
||||
case CHECK_ERROR_VERSION:
|
||||
str = "interface version or config version error";
|
||||
break;
|
||||
case CHECK_ERROR_Config_Null:
|
||||
str = "prt* config is null";
|
||||
break;
|
||||
case CHECK_ERROR_Config_Value:
|
||||
str = "config value error";
|
||||
break;
|
||||
case CHECK_ERROR_Path_NULL:
|
||||
str = "file Path is Null";
|
||||
break;
|
||||
case CHECK_ERROR_Mask_Empty:
|
||||
str = "mask Image is empty";
|
||||
break;
|
||||
case CHECK_ERROR_Config_cutRoi:
|
||||
str = "config Rect Value error";
|
||||
break;
|
||||
case CHECK_ERROR_CheckImg_Empty:
|
||||
str = "check image is empty";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@ -0,0 +1,169 @@
|
||||
#include "CheckResultJson.h"
|
||||
|
||||
Json::Value CheckResultJson::toJsonValue()
|
||||
{
|
||||
Json::Value root;
|
||||
|
||||
{
|
||||
|
||||
root["cutRoi"]["x"] = m_pOneImgDetResult->CutRoi.x;
|
||||
root["cutRoi"]["y"] = m_pOneImgDetResult->CutRoi.y;
|
||||
root["cutRoi"]["width"] = m_pOneImgDetResult->CutRoi.width;
|
||||
root["cutRoi"]["height"] = m_pOneImgDetResult->CutRoi.height;
|
||||
}
|
||||
{
|
||||
|
||||
root["Param_CropRoi"]["x"] = m_pOneImgDetResult->Param_CropRoi.x;
|
||||
root["Param_CropRoi"]["y"] = m_pOneImgDetResult->Param_CropRoi.y;
|
||||
root["Param_CropRoi"]["width"] = m_pOneImgDetResult->Param_CropRoi.width;
|
||||
root["Param_CropRoi"]["height"] = m_pOneImgDetResult->Param_CropRoi.height;
|
||||
}
|
||||
for (int i = 0; i < m_pOneImgDetResult->pQx_ErrorList->size(); i++)
|
||||
{
|
||||
QX_ERROR_INFO_ *p = &m_pOneImgDetResult->pQx_ErrorList->at(i);
|
||||
Json::Value value;
|
||||
{
|
||||
|
||||
value["Idx"] = p->Idx;
|
||||
value["result"] = p->result;
|
||||
value["result_Name"] = p->result_name;
|
||||
value["roi"]["x"] = p->roi.x;
|
||||
value["roi"]["y"] = p->roi.y;
|
||||
value["roi"]["width"] = p->roi.width;
|
||||
value["roi"]["height"] = p->roi.height;
|
||||
value["area"] = p->area;
|
||||
value["energy"] = p->energy;
|
||||
value["JudgArea"] = p->JudgArea;
|
||||
value["JudgArea_second"] = p->JudgArea_second;
|
||||
value["flen"] = p->flen;
|
||||
value["nconfig_qx_type"] = p->nconfig_qx_type;
|
||||
value["qx_name"] = p->qx_name;
|
||||
value["maxValue"] = p->maxValue;
|
||||
value["grayDis"] = p->grayDis;
|
||||
value["fUpIou"] = p->fUpIou;
|
||||
value["density"] = p->density;
|
||||
// return root;
|
||||
for (int jr = 0; jr < p->detRegionidxList.size(); jr++)
|
||||
{
|
||||
|
||||
value["regionlist"].append(p->detRegionidxList[jr]);
|
||||
}
|
||||
}
|
||||
root["Qx"].append(value);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
void CheckResultJson::toObjectFromValue(Json::Value root)
|
||||
{
|
||||
|
||||
m_pOneImgDetResult = std::make_shared<One_Image_CheckResult_>();
|
||||
m_pOneImgDetResult->pQx_ErrorList = std::make_shared<std::vector<QX_ERROR_INFO_>>();
|
||||
// std::cout << root << std::endl;
|
||||
|
||||
{
|
||||
auto value = root["cutRoi"];
|
||||
if (value.isObject())
|
||||
{
|
||||
|
||||
m_pOneImgDetResult->CutRoi.x = root["cutRoi"]["x"].asInt();
|
||||
m_pOneImgDetResult->CutRoi.y = root["cutRoi"]["y"].asInt();
|
||||
m_pOneImgDetResult->CutRoi.width = root["cutRoi"]["width"].asInt();
|
||||
m_pOneImgDetResult->CutRoi.height = root["cutRoi"]["height"].asInt();
|
||||
}
|
||||
}
|
||||
{
|
||||
auto value = root["Param_CropRoi"];
|
||||
if (value.isObject())
|
||||
{
|
||||
|
||||
m_pOneImgDetResult->Param_CropRoi.x = root["Param_CropRoi"]["x"].asInt();
|
||||
m_pOneImgDetResult->Param_CropRoi.y = root["Param_CropRoi"]["y"].asInt();
|
||||
m_pOneImgDetResult->Param_CropRoi.width = root["Param_CropRoi"]["width"].asInt();
|
||||
m_pOneImgDetResult->Param_CropRoi.height = root["Param_CropRoi"]["height"].asInt();
|
||||
}
|
||||
}
|
||||
{
|
||||
if (root.isMember("Qx"))
|
||||
{
|
||||
|
||||
const Json::Value &errorList = root["Qx"];
|
||||
for (const auto &errorJson : errorList)
|
||||
{
|
||||
|
||||
QX_ERROR_INFO_ tem;
|
||||
tem.Idx = errorJson["Idx"].asInt();
|
||||
|
||||
// tem.result = errorJson["result"].asInt();
|
||||
// tem.result_name = errorJson["result_Name"].asString();
|
||||
|
||||
tem.roi.x = errorJson["roi"]["x"].asInt();
|
||||
tem.roi.y = errorJson["roi"]["y"].asInt();
|
||||
tem.roi.width = errorJson["roi"]["width"].asInt();
|
||||
tem.roi.height = errorJson["roi"]["height"].asInt();
|
||||
tem.area = errorJson["area"].asInt();
|
||||
tem.energy = errorJson["energy"].asInt();
|
||||
tem.JudgArea = errorJson["JudgArea"].asFloat();
|
||||
if (errorJson["JudgArea_second"])
|
||||
{
|
||||
tem.JudgArea_second = errorJson["JudgArea_second"].asFloat();
|
||||
}
|
||||
else
|
||||
{
|
||||
tem.JudgArea_second = tem.JudgArea;
|
||||
}
|
||||
|
||||
tem.flen = errorJson["flen"].asFloat();
|
||||
tem.nconfig_qx_type = errorJson["nconfig_qx_type"].asInt();
|
||||
tem.qx_name = errorJson["qx_name"].asString();
|
||||
tem.maxValue = errorJson["maxValue"].asInt();
|
||||
tem.grayDis = errorJson["grayDis"].asFloat();
|
||||
tem.fUpIou = errorJson["fUpIou"].asFloat();
|
||||
tem.density = errorJson["density"].asFloat();
|
||||
|
||||
const Json::Value ®ionvalue = errorJson["regionlist"];
|
||||
|
||||
if (regionvalue.isArray())
|
||||
{
|
||||
// std::cout<<regionvalue<<std::endl;
|
||||
for (const auto ®ion : regionvalue)
|
||||
{
|
||||
tem.detRegionidxList.push_back(region.asInt());
|
||||
}
|
||||
}
|
||||
|
||||
m_pOneImgDetResult->pQx_ErrorList->push_back(tem);
|
||||
|
||||
// tem.print(std::to_string(m_pOneImgDetResult->pQx_ErrorList->size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CheckResultJson::GetConfig(std::string strJson, std::shared_ptr<One_Image_CheckResult_> &pOneImgDetResult)
|
||||
{
|
||||
Json::CharReader *reader = readerBuilder.newCharReader();
|
||||
string errs;
|
||||
bool parsingSuccessful = reader->parse(strJson.c_str(), strJson.c_str() + strJson.size(), &root, &errs);
|
||||
delete reader;
|
||||
if (!parsingSuccessful)
|
||||
{
|
||||
cout << "Failed to parse JSON string: " << errs << endl;
|
||||
return 1;
|
||||
}
|
||||
toObjectFromValue(root);
|
||||
pOneImgDetResult = m_pOneImgDetResult;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string CheckResultJson::GetResultString(std::shared_ptr<One_Image_CheckResult_> &pOneImgDetResult)
|
||||
{
|
||||
m_pOneImgDetResult = pOneImgDetResult;
|
||||
|
||||
Json::Value root = toJsonValue();
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
std::string jsonString = Json::writeString(writerBuilder, root);
|
||||
|
||||
return jsonString;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-09-13 20:39:37
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-23 14:29:12
|
||||
* @FilePath: /BOE_CELL_AOI_Detect/AlgorithmModule/src/CameraResult.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "ImageAllResult.h"
|
||||
|
||||
ImageAllResult::ImageAllResult()
|
||||
{
|
||||
detlog = std::make_shared<DetLog>();
|
||||
pDetResult = std::make_shared<One_Image_CheckResult_>();
|
||||
}
|
||||
|
||||
ImageAllResult::~ImageAllResult()
|
||||
{
|
||||
}
|
||||
|
||||
void ImageAllResult::AddLog(std::string str)
|
||||
{
|
||||
LogList.push_back(str);
|
||||
}
|
||||
ImageAllResult::DetStep ImageAllResult::getStep()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
return m_step;
|
||||
}
|
||||
void ImageAllResult::setStep(DetStep step)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
m_step = step;
|
||||
}
|
||||
|
||||
bool ImageAllResult::IsNotDet()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
if (m_step == DetStep_NotDet)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int ImageAllResult::AddDetImage(std::shared_ptr<shareImage> p)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock_cam(mtx_Det);
|
||||
result = std::make_shared<CheckResult>();
|
||||
p->time_PushIn = CheckUtil::getcurTime();
|
||||
result->in_shareImage = p;
|
||||
result->checkStatus = 1;
|
||||
result->nDetStep = 0;
|
||||
result->nresult = -1;
|
||||
result->basicResult.img_id = p->img_id;
|
||||
result->basicResult.imgtype = p->imgtype;
|
||||
result->basicResult.imgstr = p->imgstr;
|
||||
result->basicResult.strChannel = p->strChannel;
|
||||
|
||||
strChannel = p->strChannel;
|
||||
strBaseInfo = productBaseResult->strproductName + " cam " + cameraBaseResult->strCameraName + " channel " + strChannel;
|
||||
|
||||
if (p->Det_Mode == DET_MODE_ReJson)
|
||||
{
|
||||
m_CheckResultJson.GetConfig(p->resultJson, pDetResult);
|
||||
|
||||
fscale_detToresult_x = 1;
|
||||
fscale_detToresult_y = 1;
|
||||
// 图片
|
||||
if (!p->img.empty())
|
||||
{
|
||||
detImg = p->img;
|
||||
/* code */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pDetResult->CutRoi.width > 0 && pDetResult->CutRoi.height > 0)
|
||||
{
|
||||
detImg = cv::Mat::zeros(pDetResult->CutRoi.height, pDetResult->CutRoi.width, CV_8UC1);
|
||||
}
|
||||
else
|
||||
{
|
||||
detImg = cv::Mat::zeros(1000, 2000, CV_8UC1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
cv::Size sz;
|
||||
sz.width = RESIZE_IMAGE_WIDTH;
|
||||
|
||||
float fw = RESIZE_IMAGE_WIDTH * 1.0f / detImg.cols;
|
||||
sz.height = int(detImg.rows * fw);
|
||||
|
||||
cv::resize(detImg, resultImg, sz);
|
||||
if (resultImg.channels() == 1)
|
||||
{
|
||||
cv::cvtColor(resultImg, resultImg, cv::COLOR_GRAY2BGR);
|
||||
}
|
||||
|
||||
result->resultimg = resultImg;
|
||||
|
||||
result->cutSrcimg = detImg;
|
||||
|
||||
fscale_detToresult_x = resultImg.cols * 1.0f / detImg.cols;
|
||||
fscale_detToresult_y = resultImg.rows * 1.0f / detImg.rows;
|
||||
}
|
||||
|
||||
// pDetResult->print("result");
|
||||
// getchar();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:50:00
|
||||
* @LastEditTime: 2022-09-26 16:27:27
|
||||
* @LastEditors: sueRimn
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/src/CamDeal.cpp
|
||||
*/
|
||||
#include "ImageDetBase.h"
|
||||
#include "ImgCheckAnalysisy.hpp"
|
||||
ImgCheckBase *ImgCheckBase::GetInstance()
|
||||
{
|
||||
return (ImgCheckBase *)new ImgCheckAnalysisy();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-09-11 15:32:52
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-16 09:40:36
|
||||
* @FilePath: /BOE_CELL_AOI_Detect/AlgorithmModule/src/ImageStorage.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
#include "ImageStorage.h"
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
ImageStorage *ImageStorage::instance = nullptr;
|
||||
|
||||
ImageStorage::ImageStorage() : stopFlag(false)
|
||||
{
|
||||
// 启动存储线程
|
||||
storageThread = std::thread(&ImageStorage::storeImages, this);
|
||||
}
|
||||
|
||||
ImageStorage::~ImageStorage()
|
||||
{
|
||||
stop(); // 在销毁时确保线程被正确停止
|
||||
}
|
||||
|
||||
// 获取单例实例的静态方法
|
||||
ImageStorage *ImageStorage::getInstance()
|
||||
{
|
||||
if (instance == nullptr)
|
||||
{
|
||||
instance = new ImageStorage(); // 如果实例为空,则创建新实例
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ImageStorage::storeImages()
|
||||
{
|
||||
while (!stopFlag)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Sleep for 100 milliseconds
|
||||
std::unique_lock<std::mutex> lock(queueMutex);
|
||||
cv.wait(lock, [this]()
|
||||
{ return !imageQueue.empty() || stopFlag; });
|
||||
|
||||
if (stopFlag && imageQueue.empty())
|
||||
break;
|
||||
|
||||
auto item = imageQueue.front();
|
||||
imageQueue.pop();
|
||||
lock.unlock();
|
||||
cv::Mat temimg = item.first;
|
||||
if (!temimg.empty())
|
||||
{
|
||||
cv::imwrite(item.second, item.first); // 保存图片到文件
|
||||
// std::cout << "Image saved to: " << item.second << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ImageStorage::addImage(const std::string &path, const cv::Mat &image, bool badd)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
|
||||
if (imageQueue.size() > 1000 && !badd)
|
||||
{
|
||||
std::cout << "Queue has more than 10 items, not adding new images." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
imageQueue.push({image, path});
|
||||
cv.notify_one(); // 通知存储线程处理新任务
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ImageStorage::stop()
|
||||
{
|
||||
stopFlag = true;
|
||||
cv.notify_one(); // 通知存储线程停止
|
||||
if (storageThread.joinable())
|
||||
{
|
||||
storageThread.join(); // 等待线程退出
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:50:00
|
||||
* @LastEditTime: 2022-09-26 16:27:27
|
||||
* @LastEditors: sueRimn
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/src/CamDeal.cpp
|
||||
*/
|
||||
#include "ImgCheckBase.h"
|
||||
#include "ImgCheckAnalysisy.hpp"
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "ALLImgCheckAnalysisy.hpp"
|
||||
ALLImgCheckBase *ALLImgCheckBase::instance = nullptr;
|
||||
ALLImgCheckBase *ALLImgCheckBase::GetInstance()
|
||||
{
|
||||
// if (instance == nullptr)
|
||||
// {
|
||||
// instance = (ALLImgCheckBase *)new ALLImgCheckAnalysisy();
|
||||
// }
|
||||
return (ALLImgCheckBase *)new ALLImgCheckAnalysisy();;
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
|
||||
#include "OtherDetect.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
|
||||
AIDetectBase ::AIDetectBase(/* args */)
|
||||
{
|
||||
m_pOtherDet_Config = NULL;
|
||||
|
||||
m_bInitialized = false;
|
||||
m_bModelSucc = false;
|
||||
}
|
||||
|
||||
AIDetectBase ::~AIDetectBase()
|
||||
{
|
||||
}
|
||||
int AIDetectBase ::Init(OtherDet_Config *pOtherDet_Config)
|
||||
{
|
||||
m_pOtherDet_Config = pOtherDet_Config;
|
||||
|
||||
m_bInitialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
LackPolDet::LackPolDet(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
LackPolDet::~LackPolDet()
|
||||
{
|
||||
}
|
||||
int LackPolDet::Init_LackPol()
|
||||
{
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
int LackPolDet::InitModel_ALL()
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
int LackPolDet::Detect(const cv::Mat &img, DetConfig *pDetConfig, cv::Mat &outMask)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-09-13 19:26:19
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-17 18:10:38
|
||||
* @FilePath: /BOE_CELL_AOI_Detect/AlgorithmModule/src/Product.cpp
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*
|
||||
*/
|
||||
#include "Product.h"
|
||||
|
||||
Product::Product(/* args */)
|
||||
{
|
||||
productBaseResult = std::make_shared<ProductBaseResult>();
|
||||
productBaseResult->detlog = std::make_shared<DetLog>();
|
||||
}
|
||||
|
||||
Product::~Product()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<CameraResult> Product::GetCameraResult(std::string strcameraName)
|
||||
{
|
||||
// 加锁保证多线程安全
|
||||
std::lock_guard<std::mutex> lock(mtx_CameraResultList);
|
||||
for (auto &ptr : m_pCameraResultList)
|
||||
{
|
||||
if (ptr->cameraBaseResult->strCameraName == strcameraName)
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
// 不存在,创建新的 CameraResult 并插入 map
|
||||
std::shared_ptr<CameraResult> newResult = std::make_shared<CameraResult>();
|
||||
newResult->productBaseResult = productBaseResult;
|
||||
newResult->cameraBaseResult->strCameraName = strcameraName;
|
||||
m_pCameraResultList.push_back(newResult);
|
||||
productBaseResult->detlog->AddCheckstr(PrintLevel_0, "PushInImg", "add new Camera %s ", strcameraName.c_str());
|
||||
return newResult;
|
||||
}
|
||||
void Product::AddLog(std::string str)
|
||||
{
|
||||
LogList.push_back(str);
|
||||
}
|
||||
|
||||
void Product::UpdatePushStatus(int status)
|
||||
{
|
||||
if (IN_IMG_Status_End == status ||
|
||||
IN_IMG_Status_OneImg == status ||
|
||||
-1 == status)
|
||||
{
|
||||
bIsImgComplete = true;
|
||||
std::lock_guard<std::mutex> lock(mtx_CameraResultList); // 加锁保护 map
|
||||
|
||||
for (auto &ptr : m_pCameraResultList)
|
||||
{
|
||||
ptr->setImgPushComplate();
|
||||
}
|
||||
std::string strTimg = CheckUtil::getCurTimeHMS();
|
||||
strEndTime = strTimg;
|
||||
time_pushImg_end = CheckUtil::getcurTime();
|
||||
productBaseResult->detlog->AddCheckstr(PrintLevel_0, "PushInImg", "%s Add ALL img end %s ", productBaseResult->strproductName.c_str(), strTimg.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool Product::bCheckCamplate()
|
||||
{
|
||||
// 所有的图都送完了。
|
||||
if (bIsImgComplete)
|
||||
{
|
||||
bool ballcomplate = true;
|
||||
std::lock_guard<std::mutex> lock(mtx_CameraResultList); // 加锁保护 map
|
||||
for (auto &ptr : m_pCameraResultList)
|
||||
{
|
||||
if (!ptr->bCheckCamplate())
|
||||
{
|
||||
ballcomplate = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ballcomplate)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Product::SetCheckEnd() {
|
||||
time_CheckImg_end = CheckUtil::getcurTime();
|
||||
product_UseAllTime = time_CheckImg_end - time_pushImg_end;
|
||||
std::string strTimg = CheckUtil::getCurTimeHMS();
|
||||
|
||||
productBaseResult->detlog->AddCheckstr(PrintLevel_0, "Product", "Product Usetime %ld ms,start %s end %s",\
|
||||
product_UseAllTime, strEndTime.c_str(), strTimg.c_str());
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
#include "Task.h"
|
||||
|
||||
Task::Task()
|
||||
{
|
||||
}
|
||||
|
||||
Task::~Task()
|
||||
{
|
||||
}
|
||||
|
||||
int Task::sendTask(std::shared_ptr<TaskInfo> task)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_task_mutex_);
|
||||
task->SetStatus(TaskStep_Waite);
|
||||
m_tasks_.push(task);
|
||||
}
|
||||
|
||||
m_task_cv_.notify_one();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<TaskInfo> Task::GetTask()
|
||||
{
|
||||
std::shared_ptr<TaskInfo> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_task_mutex_);
|
||||
m_task_cv_.wait(lock, [this]()
|
||||
{ return !m_tasks_.empty(); });
|
||||
|
||||
task = std::move(m_tasks_.front());
|
||||
m_tasks_.pop();
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
#限定CMake的版本
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
|
||||
project(rootproject)
|
||||
set(CHECK_WORK_Value "POL_ET")
|
||||
|
||||
if (DEFINED WORK)
|
||||
set(CHECK_WORK_Value ${WORK})
|
||||
endif()
|
||||
|
||||
# 根据宏设置编译时宏
|
||||
add_definitions(-DCHECK_WORK="${CHECK_WORK_Value}")
|
||||
|
||||
message(STATUS "CHECK_WORK: ${CHECK_WORK_Value}")
|
||||
|
||||
find_package( OpenCV REQUIRED )
|
||||
|
||||
message(STATUS "oPENCV Library status:")
|
||||
message(STATUS ">version:${OpenCV_VERSION}")
|
||||
message(STATUS "Include:${OpenCV_INCLUDE_DIRS}")
|
||||
|
||||
set(CMAKE_BUILD_TYPE "release")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON) # 要求编译器支持 C++17
|
||||
set(CMAKE_CXX_EXTENSIONS OFF) # 禁用 GNU 特定的扩展
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
#set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; --default-stream per-thread)
|
||||
|
||||
add_definitions(-DCUDA_API_PER_THREAD_DEFAULT_STREAM)
|
||||
# PROJECT_INCLUDE_DIR当作全局头文件变量
|
||||
set(PROJECT_INCLUDE_DIR c/include)
|
||||
|
||||
# x86_64,aarch64
|
||||
set(BUILD_ARCH x86_64 CACHE STRING "Arch of this project" FORCE)
|
||||
MESSAGE(STATUS "BUILD_ARCH : ${BUILD_ARCH}")
|
||||
|
||||
MESSAGE(STATUS "CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}")
|
||||
MESSAGE(STATUS "This is BINARY dir " ${PROJECT_BINARY_DIR})
|
||||
MESSAGE(STATUS "This is SOURCE dir " ${PROJECT_SOURCE_DIR})
|
||||
|
||||
#包含通用的编译环境模块到顶层目录
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/default_variabes.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/cpp_c_flags.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/print_archs.cmake)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/include/)
|
||||
include_directories(/usr/local/boost/include
|
||||
/usr/include
|
||||
${OpenCV_INCLUDE_DIRS}
|
||||
)
|
||||
link_directories(
|
||||
${PROJECT_SOURCE_DIR}/lib/x86_64/
|
||||
/usr/local/boost/lib
|
||||
)
|
||||
|
||||
#下一级的编译目录
|
||||
|
||||
MESSAGE("build dependent module - start")
|
||||
#当程序执行命令 ADD_SUBDIRECTORY(src)时进入目录 src 对其中的 CMakeLists.txt 进行解析。
|
||||
|
||||
add_subdirectory(ExtractImageModule)
|
||||
MESSAGE("ExtractImageModule")
|
||||
|
||||
|
||||
add_subdirectory(ConfigModule)
|
||||
MESSAGE("ConfigModule")
|
||||
|
||||
# CommonUtil
|
||||
add_subdirectory(AlgorithmModule)
|
||||
MESSAGE("AlgorithmModule")
|
||||
|
||||
add_subdirectory(example)
|
||||
MESSAGE("example")
|
||||
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:49:50
|
||||
* @LastEditTime: 2022-09-23 21:51:58
|
||||
* @LastEditors: sueRimn
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
|
||||
*/
|
||||
#ifndef Base_Define_H_
|
||||
#define Base_Define_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#define RECT_TO_STRING(rect) \
|
||||
"(x=" + std::to_string((rect).x) + ", y=" + std::to_string((rect).y) \
|
||||
+ ", width=" + std::to_string((rect).width) + ", height=" + std::to_string((rect).height) + ")"
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,42 @@
|
||||
#版本限定
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
|
||||
set(ModuleName "ConfigModule")
|
||||
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/default_variabes.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/cpp_c_flags.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/print_archs.cmake)
|
||||
|
||||
|
||||
#头文件
|
||||
include_directories(
|
||||
/usr/local/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
link_directories(
|
||||
/usr/local/lib/
|
||||
)
|
||||
# 用set设置变量不能使用*.cpp
|
||||
file(GLOB SRC_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
add_library(Config SHARED ${SRC_LISTS})
|
||||
|
||||
target_link_libraries(Config
|
||||
${OpenCV_LIBS}
|
||||
)
|
||||
set(ModuleName "")
|
||||
|
||||
#add_subdirectory(example)
|
||||
|
||||
# make install 安装到/usr/local下
|
||||
# 自定义安装前缀
|
||||
set(CMAKE_INSTALL_PREFIX /usr/local/polet CACHE PATH "Install path prefix" FORCE)
|
||||
set(HEADER_FILES include/ConfigBase.h)
|
||||
# 安装动态库
|
||||
install(TARGETS Config
|
||||
LIBRARY DESTINATION lib # 安装到 CMAKE_INSTALL_PREFIX/lib
|
||||
ARCHIVE DESTINATION lib/static
|
||||
RUNTIME DESTINATION bin
|
||||
PUBLIC_HEADER DESTINATION include) # 安装到 CMAKE_INSTALL_PREFIX/include
|
||||
# 安装头文件
|
||||
install(FILES ${HEADER_FILES} DESTINATION include)
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,86 @@
|
||||
#ifndef CamConfig_H
|
||||
#define CamConfig_H
|
||||
|
||||
#include "JsonCoversion.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "CheckConfigDefine.h"
|
||||
#include "Define.h"
|
||||
|
||||
class CommonParamJson : public JsonCoversion
|
||||
{
|
||||
public:
|
||||
CommonParamJson() {}
|
||||
virtual ~CommonParamJson() {}
|
||||
|
||||
public:
|
||||
virtual Json::Value toJsonValue();
|
||||
virtual void toObjectFromValue(Json::Value root);
|
||||
int GetConfig(CommonParamST &config);
|
||||
|
||||
private:
|
||||
CommonParamST _config;
|
||||
};
|
||||
|
||||
class CommonParamToCheckConfigJson : public JsonCoversion
|
||||
{
|
||||
public:
|
||||
CommonParamToCheckConfigJson() {}
|
||||
virtual ~CommonParamToCheckConfigJson() {}
|
||||
|
||||
public:
|
||||
virtual Json::Value toJsonValue();
|
||||
virtual void toObjectFromValue(Json::Value root);
|
||||
int GetConfig(CommonCheckConfigST &config);
|
||||
|
||||
private:
|
||||
CommonCheckConfigST _config;
|
||||
};
|
||||
|
||||
class CheckConfigJson : public JsonCoversion
|
||||
{
|
||||
public:
|
||||
CheckConfigJson() {}
|
||||
virtual ~CheckConfigJson() {}
|
||||
|
||||
public:
|
||||
virtual Json::Value toJsonValue();
|
||||
virtual void toObjectFromValue(Json::Value root);
|
||||
int GetConfig(CheckConfigST &config);
|
||||
|
||||
private:
|
||||
CheckConfigST _config;
|
||||
};
|
||||
|
||||
class ChannelFuntonConfigJson : public JsonCoversion
|
||||
{
|
||||
public:
|
||||
ChannelFuntonConfigJson() {}
|
||||
virtual ~ChannelFuntonConfigJson() {}
|
||||
|
||||
public:
|
||||
virtual Json::Value toJsonValue();
|
||||
virtual void toObjectFromValue(Json::Value root);
|
||||
int GetConfig(ALLChannelCheckFunction &config);
|
||||
int GetFunction(Json::Value value, CheckFunction &function);
|
||||
|
||||
private:
|
||||
ALLChannelCheckFunction _config;
|
||||
};
|
||||
|
||||
class BaseFuntonConfigJson : public JsonCoversion
|
||||
{
|
||||
public:
|
||||
BaseFuntonConfigJson() {}
|
||||
virtual ~BaseFuntonConfigJson() {}
|
||||
|
||||
public:
|
||||
virtual Json::Value toJsonValue();
|
||||
virtual void toObjectFromValue(Json::Value root);
|
||||
int GetConfig(BaseCheckFunction &config);
|
||||
int GetFunction(Json::Value value);
|
||||
|
||||
private:
|
||||
BaseCheckFunction _config;
|
||||
};
|
||||
#endif //
|
||||
@ -0,0 +1,31 @@
|
||||
#ifndef JsonCoversion_H
|
||||
#define JsonCoversion_H
|
||||
#include<iostream>
|
||||
#include<memory>
|
||||
#include<string>
|
||||
#include "json/json.h"
|
||||
using namespace std;
|
||||
|
||||
class JsonCoversion
|
||||
{
|
||||
protected:
|
||||
Json::Value root;
|
||||
|
||||
// Json::FastWriter writer; //弃用 改用StreamWriterBuilder
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
|
||||
// Json::Reader reader; //弃用 改用CharReaderBuilder
|
||||
Json::CharReaderBuilder readerBuilder;
|
||||
public:
|
||||
JsonCoversion();
|
||||
virtual ~JsonCoversion();
|
||||
protected:
|
||||
public:
|
||||
string toJson();
|
||||
void toObject(string & strBuf);
|
||||
protected:
|
||||
virtual Json::Value toJsonValue() = 0;
|
||||
virtual void toObjectFromValue(Json::Value root) = 0;
|
||||
};
|
||||
|
||||
#endif // JsonCoversion_H
|
||||
@ -0,0 +1,346 @@
|
||||
/// Json-cpp amalgamated forward header (http://jsoncpp.sourceforge.net/).
|
||||
/// It is intended to be used with #include "json/json-forwards.h"
|
||||
/// This header provides forward declaration for all JsonCpp types.
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// Beginning of content of file: LICENSE
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
The JsonCpp library's source code, including accompanying documentation,
|
||||
tests and demonstration applications, are licensed under the following
|
||||
conditions...
|
||||
|
||||
Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
|
||||
jurisdictions which recognize such a disclaimer. In such jurisdictions,
|
||||
this software is released into the Public Domain.
|
||||
|
||||
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
|
||||
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
|
||||
The JsonCpp Authors, and is released under the terms of the MIT License (see below).
|
||||
|
||||
In jurisdictions which recognize Public Domain property, the user of this
|
||||
software may choose to accept it either as 1) Public Domain, 2) under the
|
||||
conditions of the MIT License (see below), or 3) under the terms of dual
|
||||
Public Domain/MIT License conditions described here, as they choose.
|
||||
|
||||
The MIT License is about as close to Public Domain as a license can get, and is
|
||||
described in clear, concise terms at:
|
||||
|
||||
http://en.wikipedia.org/wiki/MIT_License
|
||||
|
||||
The full text of the MIT License follows:
|
||||
|
||||
========================================================================
|
||||
Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy,
|
||||
modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
========================================================================
|
||||
(END LICENSE TEXT)
|
||||
|
||||
The MIT license is compatible with both the GPL and commercial
|
||||
software, affording one all of the rights of Public Domain with the
|
||||
minor nuisance of being required to keep the above copyright notice
|
||||
and license text in the source code. Note also that by accepting the
|
||||
Public Domain "license" you can re-license your copy using whatever
|
||||
license you like.
|
||||
|
||||
*/
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// End of content of file: LICENSE
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED
|
||||
# define JSON_FORWARD_AMALGAMATED_H_INCLUDED
|
||||
/// If defined, indicates that the source file is amalgamated
|
||||
/// to prevent private header inclusion.
|
||||
#define JSON_IS_AMALGAMATION
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// Beginning of content of file: include/json/config.h
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||
// Distributed under MIT license, or public domain if desired and
|
||||
// recognized in your jurisdiction.
|
||||
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
||||
|
||||
#ifndef JSON_CONFIG_H_INCLUDED
|
||||
#define JSON_CONFIG_H_INCLUDED
|
||||
#include <stddef.h>
|
||||
#include <stdint.h> //typedef int64_t, uint64_t
|
||||
#include <string> //typedef String
|
||||
|
||||
/// If defined, indicates that json library is embedded in CppTL library.
|
||||
//# define JSON_IN_CPPTL 1
|
||||
|
||||
/// If defined, indicates that json may leverage CppTL library
|
||||
//# define JSON_USE_CPPTL 1
|
||||
/// If defined, indicates that cpptl vector based map should be used instead of
|
||||
/// std::map
|
||||
/// as Value container.
|
||||
//# define JSON_USE_CPPTL_SMALLMAP 1
|
||||
|
||||
// If non-zero, the library uses exceptions to report bad input instead of C
|
||||
// assertion macros. The default is to use exceptions.
|
||||
#ifndef JSON_USE_EXCEPTION
|
||||
#define JSON_USE_EXCEPTION 1
|
||||
#endif
|
||||
|
||||
/// If defined, indicates that the source file is amalgamated
|
||||
/// to prevent private header inclusion.
|
||||
/// Remarks: it is automatically defined in the generated amalgamated header.
|
||||
// #define JSON_IS_AMALGAMATION
|
||||
|
||||
#ifdef JSON_IN_CPPTL
|
||||
#include <cpptl/config.h>
|
||||
#ifndef JSON_USE_CPPTL
|
||||
#define JSON_USE_CPPTL 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef JSON_IN_CPPTL
|
||||
#define JSON_API CPPTL_API
|
||||
#elif defined(JSON_DLL_BUILD)
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#define JSON_API __declspec(dllexport)
|
||||
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
|
||||
#endif // if defined(_MSC_VER)
|
||||
#elif defined(JSON_DLL)
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#define JSON_API __declspec(dllimport)
|
||||
#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
|
||||
#endif // if defined(_MSC_VER)
|
||||
#endif // ifdef JSON_IN_CPPTL
|
||||
#if !defined(JSON_API)
|
||||
#define JSON_API
|
||||
#endif
|
||||
|
||||
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
|
||||
// integer
|
||||
// Storages, and 64 bits integer support is disabled.
|
||||
// #define JSON_NO_INT64 1
|
||||
|
||||
#if defined(_MSC_VER) // MSVC
|
||||
#if _MSC_VER <= 1200 // MSVC 6
|
||||
// Microsoft Visual Studio 6 only support conversion from __int64 to double
|
||||
// (no conversion from unsigned __int64).
|
||||
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
|
||||
// Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
|
||||
// characters in the debug information)
|
||||
// All projects I've ever seen with VS6 were using this globally (not bothering
|
||||
// with pragma push/pop).
|
||||
#pragma warning(disable : 4786)
|
||||
#endif // MSVC 6
|
||||
|
||||
#if _MSC_VER >= 1500 // MSVC 2008
|
||||
/// Indicates that the following function is deprecated.
|
||||
#define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
|
||||
#endif
|
||||
|
||||
#endif // defined(_MSC_VER)
|
||||
|
||||
// In c++11 the override keyword allows you to explicitly define that a function
|
||||
// is intended to override the base-class version. This makes the code more
|
||||
// manageable and fixes a set of common hard-to-find bugs.
|
||||
#if __cplusplus >= 201103L
|
||||
#define JSONCPP_OVERRIDE override
|
||||
#define JSONCPP_NOEXCEPT noexcept
|
||||
#define JSONCPP_OP_EXPLICIT explicit
|
||||
#elif defined(_MSC_VER) && _MSC_VER > 1600 && _MSC_VER < 1900
|
||||
#define JSONCPP_OVERRIDE override
|
||||
#define JSONCPP_NOEXCEPT throw()
|
||||
#if _MSC_VER >= 1800 // MSVC 2013
|
||||
#define JSONCPP_OP_EXPLICIT explicit
|
||||
#else
|
||||
#define JSONCPP_OP_EXPLICIT
|
||||
#endif
|
||||
#elif defined(_MSC_VER) && _MSC_VER >= 1900
|
||||
#define JSONCPP_OVERRIDE override
|
||||
#define JSONCPP_NOEXCEPT noexcept
|
||||
#define JSONCPP_OP_EXPLICIT explicit
|
||||
#else
|
||||
#define JSONCPP_OVERRIDE
|
||||
#define JSONCPP_NOEXCEPT throw()
|
||||
#define JSONCPP_OP_EXPLICIT
|
||||
#endif
|
||||
|
||||
#ifndef JSON_HAS_RVALUE_REFERENCES
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010
|
||||
#define JSON_HAS_RVALUE_REFERENCES 1
|
||||
#endif // MSVC >= 2010
|
||||
|
||||
#ifdef __clang__
|
||||
#if __has_feature(cxx_rvalue_references)
|
||||
#define JSON_HAS_RVALUE_REFERENCES 1
|
||||
#endif // has_feature
|
||||
|
||||
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
|
||||
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
|
||||
#define JSON_HAS_RVALUE_REFERENCES 1
|
||||
#endif // GXX_EXPERIMENTAL
|
||||
|
||||
#endif // __clang__ || __GNUC__
|
||||
|
||||
#endif // not defined JSON_HAS_RVALUE_REFERENCES
|
||||
|
||||
#ifndef JSON_HAS_RVALUE_REFERENCES
|
||||
#define JSON_HAS_RVALUE_REFERENCES 0
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
#if __has_extension(attribute_deprecated_with_message)
|
||||
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
#endif
|
||||
#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
|
||||
#define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
#elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
|
||||
#define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
|
||||
#endif // GNUC version
|
||||
#endif // __clang__ || __GNUC__
|
||||
|
||||
#if !defined(JSONCPP_DEPRECATED)
|
||||
#define JSONCPP_DEPRECATED(message)
|
||||
#endif // if !defined(JSONCPP_DEPRECATED)
|
||||
|
||||
#if __GNUC__ >= 6
|
||||
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
|
||||
#endif
|
||||
|
||||
#if !defined(JSON_IS_AMALGAMATION)
|
||||
|
||||
#include "version.h"
|
||||
|
||||
#if JSONCPP_USING_SECURE_MEMORY
|
||||
#include "allocator.h" //typedef Allocator
|
||||
#endif
|
||||
|
||||
#endif // if !defined(JSON_IS_AMALGAMATION)
|
||||
|
||||
namespace Json {
|
||||
typedef int Int;
|
||||
typedef unsigned int UInt;
|
||||
#if defined(JSON_NO_INT64)
|
||||
typedef int LargestInt;
|
||||
typedef unsigned int LargestUInt;
|
||||
#undef JSON_HAS_INT64
|
||||
#else // if defined(JSON_NO_INT64)
|
||||
// For Microsoft Visual use specific types as long long is not supported
|
||||
#if defined(_MSC_VER) // Microsoft Visual Studio
|
||||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 UInt64;
|
||||
#else // if defined(_MSC_VER) // Other platforms, use long long
|
||||
typedef int64_t Int64;
|
||||
typedef uint64_t UInt64;
|
||||
#endif // if defined(_MSC_VER)
|
||||
typedef Int64 LargestInt;
|
||||
typedef UInt64 LargestUInt;
|
||||
#define JSON_HAS_INT64
|
||||
#endif // if defined(JSON_NO_INT64)
|
||||
#if JSONCPP_USING_SECURE_MEMORY
|
||||
#define JSONCPP_STRING \
|
||||
std::basic_string<char, std::char_traits<char>, Json::SecureAllocator<char> >
|
||||
#define JSONCPP_OSTRINGSTREAM \
|
||||
std::basic_ostringstream<char, std::char_traits<char>, \
|
||||
Json::SecureAllocator<char> >
|
||||
#define JSONCPP_OSTREAM std::basic_ostream<char, std::char_traits<char> >
|
||||
#define JSONCPP_ISTRINGSTREAM \
|
||||
std::basic_istringstream<char, std::char_traits<char>, \
|
||||
Json::SecureAllocator<char> >
|
||||
#define JSONCPP_ISTREAM std::istream
|
||||
#else
|
||||
#define JSONCPP_STRING std::string
|
||||
#define JSONCPP_OSTRINGSTREAM std::ostringstream
|
||||
#define JSONCPP_OSTREAM std::ostream
|
||||
#define JSONCPP_ISTRINGSTREAM std::istringstream
|
||||
#define JSONCPP_ISTREAM std::istream
|
||||
#endif // if JSONCPP_USING_SECURE_MEMORY
|
||||
} // end namespace Json
|
||||
|
||||
#endif // JSON_CONFIG_H_INCLUDED
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// End of content of file: include/json/config.h
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// Beginning of content of file: include/json/forwards.h
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
|
||||
// Distributed under MIT license, or public domain if desired and
|
||||
// recognized in your jurisdiction.
|
||||
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
||||
|
||||
#ifndef JSON_FORWARDS_H_INCLUDED
|
||||
#define JSON_FORWARDS_H_INCLUDED
|
||||
|
||||
#if !defined(JSON_IS_AMALGAMATION)
|
||||
#include "config.h"
|
||||
#endif // if !defined(JSON_IS_AMALGAMATION)
|
||||
|
||||
namespace Json {
|
||||
|
||||
// writer.h
|
||||
class FastWriter;
|
||||
class StyledWriter;
|
||||
|
||||
// reader.h
|
||||
class Reader;
|
||||
|
||||
// features.h
|
||||
class Features;
|
||||
|
||||
// value.h
|
||||
typedef unsigned int ArrayIndex;
|
||||
class StaticString;
|
||||
class Path;
|
||||
class PathArgument;
|
||||
class Value;
|
||||
class ValueIteratorBase;
|
||||
class ValueIterator;
|
||||
class ValueConstIterator;
|
||||
|
||||
} // namespace Json
|
||||
|
||||
#endif // JSON_FORWARDS_H_INCLUDED
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
// End of content of file: include/json/forwards.h
|
||||
// //////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif //ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:50:00
|
||||
* @LastEditTime: 2025-09-11 18:42:03
|
||||
* @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 "ConfigBase.h"
|
||||
#include "ConfigInstance.h"
|
||||
#include "ConfigManager.h"
|
||||
|
||||
std::shared_ptr<ConfigBase> ConfigBase::GetInstance()
|
||||
{
|
||||
std::shared_ptr<ConfigBase> pInstance = std::make_shared<ConfigInstance>();
|
||||
return pInstance;
|
||||
}
|
||||
bool compareBylay(const RegionConfigST &a, const RegionConfigST &b)
|
||||
{
|
||||
return a.basicInfo.lay < b.basicInfo.lay;
|
||||
}
|
||||
ConfigManagerBase *ConfigManagerBase::m_pInstance = nullptr;
|
||||
ConfigManagerBase *ConfigManagerBase::GetInstance()
|
||||
{
|
||||
if (!m_pInstance)
|
||||
{
|
||||
m_pInstance = new ConfigManager();
|
||||
}
|
||||
return m_pInstance;
|
||||
}
|
||||
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:50:00
|
||||
* @LastEditTime: 2025-09-13 18:52:55
|
||||
* @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 "ConfigInstance.h"
|
||||
|
||||
ConfigInstance::ConfigInstance()
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
m_nCurIdx = 0;
|
||||
}
|
||||
|
||||
ConfigInstance::~ConfigInstance()
|
||||
{
|
||||
}
|
||||
|
||||
int ConfigInstance::GetConfigIdx()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_GetIdx);
|
||||
int reidx = m_nCurIdx;
|
||||
if (reidx < 0)
|
||||
{
|
||||
reidx = 0;
|
||||
}
|
||||
m_nCurIdx++;
|
||||
if (m_nCurIdx >= MAX_USER_COUNT)
|
||||
{
|
||||
m_nCurIdx = MAX_USER_COUNT - 1;
|
||||
}
|
||||
|
||||
return reidx;
|
||||
}
|
||||
|
||||
bool ConfigInstance::GetConfigUpdataStatus(int nConfigType, int nidx)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_status);
|
||||
|
||||
if (nConfigType >= 0 && nConfigType < ConfigType_Count && nidx >= 0 && nidx < MAX_USER_COUNT)
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
bool status = m_USER_ConfigUpdataStatusList[nConfigType][nidx];
|
||||
m_USER_ConfigUpdataStatusList[nConfigType][nidx] = false;
|
||||
return status;
|
||||
}
|
||||
m_ErrorValue = ERROR_Type_ConfigType;
|
||||
return false;
|
||||
}
|
||||
|
||||
int ConfigInstance::GetConfig(int nConfigType, void *pconfig)
|
||||
{
|
||||
if (nConfigType >= 0 && nConfigType < ConfigType_Count)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_ConfigType;
|
||||
return m_ErrorValue;
|
||||
}
|
||||
AnalysisyConfigST *p = (AnalysisyConfigST *)pconfig;
|
||||
CheckConfigST *p1 = (CheckConfigST *)pconfig;
|
||||
ImageInfo *pimg = (ImageInfo *)pconfig;
|
||||
switch (nConfigType)
|
||||
{
|
||||
case ConfigType_Analysisy_Common_XL:
|
||||
p->copy(m_AnalysisyConfig);
|
||||
break;
|
||||
case ConfigType_Check_XL:
|
||||
p1->copy(m_CheckConfig);
|
||||
break;
|
||||
case ConfigType_Image_In:
|
||||
pimg->copy(m_CheckConfig.Srcimg_in);
|
||||
break;
|
||||
case ConfigType_Image_out:
|
||||
pimg->copy(m_CheckConfig.resultimg_out);
|
||||
break;
|
||||
}
|
||||
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ConfigInstance::UpdateConfig(void *pconfig, int nConfigType)
|
||||
{
|
||||
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ConfigInstance::UpdateJSONConfig(void *pconfig, int nConfigType)
|
||||
{
|
||||
if (pconfig == NULL)
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_JsonNull;
|
||||
return m_ErrorValue;
|
||||
}
|
||||
if (nConfigType < 0 || nConfigType >= ConfigType_Count)
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_ConfigType;
|
||||
return m_ErrorValue;
|
||||
}
|
||||
|
||||
Json::Value *pJsonConfig = (Json::Value *)pconfig;
|
||||
switch (nConfigType)
|
||||
{
|
||||
case ConfigType_Analysisy_Common_XL:
|
||||
Updata_analysis(*pJsonConfig);
|
||||
/* code */
|
||||
break;
|
||||
case ConfigType_Check_XL:
|
||||
/* code */
|
||||
Updata_Check(*pJsonConfig);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// getchar();
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string ConfigInstance::GetVersion()
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string ConfigInstance::GetErrorInfo()
|
||||
{
|
||||
return ERROR_TYPE_Names[m_ErrorValue];
|
||||
}
|
||||
|
||||
int ConfigInstance::Updata_analysis(Json::Value json_value)
|
||||
{
|
||||
|
||||
// std::cout << json_value << std::endl;
|
||||
CommonParamJson configJson;
|
||||
configJson.toObjectFromValue(json_value);
|
||||
CommonParamST config;
|
||||
configJson.GetConfig(config);
|
||||
|
||||
// printf("------config.skuName %s \n", config.skuName.c_str());
|
||||
|
||||
// 解析成对应的 参数
|
||||
CommonParamToCheckConfigJson tp;
|
||||
tp.toObjectFromValue(config.value);
|
||||
|
||||
tp.GetConfig(m_AnalysisyConfig.commonCheckConfig);
|
||||
m_AnalysisyConfig.strSkuName = config.skuName;
|
||||
|
||||
int img_W = 0;
|
||||
int img_H = 0;
|
||||
|
||||
// for (int i = 0; i < m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.size(); i++)
|
||||
// {
|
||||
// if (i == 0)
|
||||
// {
|
||||
// img_W = m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.at(i).nodebasicConfog.img_width;
|
||||
// img_H = m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.at(i).nodebasicConfog.img_height;
|
||||
// }
|
||||
// m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.at(i).ToMaskImg();
|
||||
// std::string strpath = "mask_" + std::to_string(i) + ".jpg";
|
||||
// if (!m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.at(i).mask.empty())
|
||||
// {
|
||||
// cv::imwrite(strpath, m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.at(i).mask);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 解析成对应的 参数
|
||||
ChannelFuntonConfigJson jxjason;
|
||||
jxjason.toObjectFromValue(config.value);
|
||||
|
||||
jxjason.GetConfig(m_AnalysisyConfig.checkFunction);
|
||||
for (int i = 0; i < m_AnalysisyConfig.checkFunction.channelFunctionArr.size(); i++)
|
||||
{
|
||||
m_AnalysisyConfig.checkFunction.channelFunctionArr.at(i).function.f_ShieldRegion.ToMaskImg(img_W, img_H);
|
||||
m_AnalysisyConfig.checkFunction.channelFunctionArr.at(i).function.f_EdgeROI.ToMaskImg(img_W, img_H);
|
||||
m_AnalysisyConfig.checkFunction.channelFunctionArr.at(i).function.f_Image_Align.ToMaskImg(img_W, img_H);
|
||||
}
|
||||
|
||||
BaseFuntonConfigJson basefjason;
|
||||
basefjason.toObjectFromValue(config.value);
|
||||
|
||||
basefjason.GetConfig(m_AnalysisyConfig.baseFunction);
|
||||
|
||||
// m_AnalysisyConfig.checkFunction.print("------------ChannelFunction---------------");
|
||||
// getchar();
|
||||
|
||||
// 更新所有状态
|
||||
SetStatus(ConfigType_Analysisy_Common_XL);
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ConfigInstance::Updata_Check(Json::Value json_value)
|
||||
{
|
||||
std::cout << json_value << std::endl;
|
||||
|
||||
// 解析成对应的 参数
|
||||
CheckConfigJson tp;
|
||||
tp.toObjectFromValue(json_value);
|
||||
tp.GetConfig(m_CheckConfig);
|
||||
// 更新所有状态
|
||||
SetStatus(ConfigType_Check_XL);
|
||||
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ConfigInstance::SetStatus(int nConfigType)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_status);
|
||||
for (int i = 0; i < MAX_USER_COUNT; i++)
|
||||
{
|
||||
m_USER_ConfigUpdataStatusList[nConfigType][i] = true;
|
||||
}
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,222 @@
|
||||
/*
|
||||
* @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",
|
||||
"aotudian",
|
||||
"other",
|
||||
"line",
|
||||
"zangwu",
|
||||
"edge",
|
||||
"ymhs",
|
||||
"dianzhuang",
|
||||
"posun",
|
||||
"xianwei",
|
||||
"shuizi",
|
||||
"danban",
|
||||
"fuchen",
|
||||
};
|
||||
std::vector<std::string> QX_Result_Code =
|
||||
{
|
||||
"P0000",
|
||||
"MA507",
|
||||
"MA508",
|
||||
"MA506",
|
||||
"MA504",
|
||||
"MA503",
|
||||
"MA502",
|
||||
"MA505",
|
||||
"MA501",
|
||||
"P0001",
|
||||
"P0002",
|
||||
"P0003",
|
||||
"P0004",
|
||||
};
|
||||
|
||||
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);
|
||||
bool bFileName = false;
|
||||
// std::regex pattern(R"(param_[0-9]\.json)");
|
||||
std::regex pattern(R"(param_(\d+|left|right)\.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))
|
||||
{
|
||||
bFileName = true;
|
||||
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;
|
||||
}
|
||||
auto it = Config_instances_.find(p.commonCheckConfig.baseConfig.strCamearName);
|
||||
if (it != Config_instances_.end() && it->second) {
|
||||
LoadParamConfig(it->second, entry.path());
|
||||
} else {
|
||||
Config_instances_[p.commonCheckConfig.baseConfig.strCamearName] = temConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "config error 2: " << m_strConfigRootPath << std::endl;
|
||||
}
|
||||
}
|
||||
if(!bFileName){
|
||||
cout << "Error >>>> no param_x.json file !!!!!!!!!!!!\n";
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int ConfigManager::GetConfig(int nConfigType, void *pconfig)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
#include "Define.h"
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
#include "JsonCoversion.h"
|
||||
|
||||
JsonCoversion::JsonCoversion()
|
||||
{
|
||||
//ctor
|
||||
}
|
||||
|
||||
JsonCoversion::~JsonCoversion()
|
||||
{
|
||||
//dtor
|
||||
}
|
||||
string JsonCoversion::toJson()
|
||||
{
|
||||
toJsonValue();
|
||||
|
||||
std::unique_ptr<Json::StreamWriter> jsonWriter(writerBuilder.newStreamWriter());
|
||||
std::ostringstream os;
|
||||
std::string jsonStr;
|
||||
jsonWriter->write(root,&os);
|
||||
jsonStr = os.str();
|
||||
return jsonStr;
|
||||
}
|
||||
|
||||
void JsonCoversion::toObject(string & strBuf)
|
||||
{
|
||||
std::unique_ptr<Json::CharReader> const jsonReader(readerBuilder.newCharReader());
|
||||
|
||||
JSONCPP_STRING errs;
|
||||
bool res = jsonReader->parse(strBuf.c_str(), strBuf.c_str()+strBuf.length(), &root, &errs);
|
||||
if (!res || !errs.empty())
|
||||
{
|
||||
std::cout << "parseJson err. " << errs << std::endl;
|
||||
}
|
||||
toObjectFromValue(root);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,50 @@
|
||||
#版本限定
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
|
||||
set(ModuleName "ExtractImageModule")
|
||||
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/default_variabes.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/cpp_c_flags.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/cmake/print_archs.cmake)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(TURBOJPEG REQUIRED libturbojpeg)
|
||||
|
||||
MESSAGE(STATUS "TURBOJPEG_INCLUDE_DIRS dir " ${TURBOJPEG_INCLUDE_DIRS})
|
||||
|
||||
include_directories(${TURBOJPEG_INCLUDE_DIRS})
|
||||
link_directories(${TURBOJPEG_LIBRARY_DIRS})
|
||||
#头文件
|
||||
include_directories(
|
||||
/usr/local/include
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
link_directories(
|
||||
/usr/local/lib/
|
||||
)
|
||||
# 用set设置变量不能使用*.cpp
|
||||
file(GLOB SRC_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
add_library(ExtractImage SHARED ${SRC_LISTS})
|
||||
|
||||
target_link_libraries(ExtractImage
|
||||
${OpenCV_LIBS}
|
||||
${TURBOJPEG_LIBRARIES}
|
||||
)
|
||||
set(ModuleName "")
|
||||
|
||||
#add_subdirectory(example)
|
||||
|
||||
# make install 安装到/usr/local下
|
||||
# 自定义安装前缀
|
||||
set(CMAKE_INSTALL_PREFIX /usr/local/polet CACHE PATH "Install path prefix" FORCE)
|
||||
set(HEADER_FILES include/ExtractBase.h)
|
||||
# 安装动态库
|
||||
install(TARGETS ExtractImage
|
||||
LIBRARY DESTINATION lib # 安装到 CMAKE_INSTALL_PREFIX/lib
|
||||
ARCHIVE DESTINATION lib/static
|
||||
RUNTIME DESTINATION bin
|
||||
PUBLIC_HEADER DESTINATION include) # 安装到 CMAKE_INSTALL_PREFIX/include
|
||||
# 安装头文件
|
||||
install(FILES ${HEADER_FILES} DESTINATION include)
|
||||
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2022-04-20 15:50:00
|
||||
* @LastEditTime: 2022-09-26 16:27:27
|
||||
* @LastEditors: sueRimn
|
||||
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/src/CamDeal.cpp
|
||||
*/
|
||||
#include "ExtractBase.h"
|
||||
#include "ExtractInstance.h"
|
||||
|
||||
ExtractBase* ExtractBase::GetInstance()
|
||||
{
|
||||
return (ExtractBase*)new ExtractInstance();
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
if(CMAKE_BUILD_TYPE MATCHES "(Release|RELEASE|release)")
|
||||
# release mode
|
||||
set(CMAKE_BUILD_TYPE "release")
|
||||
else()
|
||||
set(CMAKE_BUILD_TYPE "debug")
|
||||
# debug mode
|
||||
if(NOT (${CMAKE_C_FLAGS} MATCHES "-g"))
|
||||
add_compile_options(-g)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
||||
endif()
|
||||
if(NOT (${CMAKE_CXX_FLAGS} MATCHES "-g"))
|
||||
add_compile_options(-g)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
|
||||
endif()
|
||||
endif()
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#++++++add c++11 standard and c99 standard
|
||||
if(NOT (${CMAKE_C_FLAGS} MATCHES "-std="))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
||||
endif()
|
||||
|
||||
if(NOT (${CMAKE_CXX_FLAGS} MATCHES "-std="))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
||||
endif()
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#++++++add path of link library
|
||||
if(NOT (${CMAKE_C_FLAGS} MATCHES "-Wl,-rpath,"))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-rpath,.:lib/:lib/${BUILD_ARCH}/:../lib/${BUILD_ARCH}/:../lib/${BUILD_ARCH}/HK/:../lib/${BUILD_ARCH}/HK/HCNetSDKCom")
|
||||
endif()
|
||||
|
||||
if(NOT (${CMAKE_CXX_FLAGS} MATCHES "-Wl,-rpath,"))
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-rpath,.:lib/:lib/${BUILD_ARCH}/:../lib/${BUILD_ARCH}/:../lib/${BUILD_ARCH}/HK/:../lib/${BUILD_ARCH}/HK/HCNetSDKCom")
|
||||
endif()
|
||||
#---------------------------------------------------------------------------------------------------
|
||||
|
||||
# message(STATUS "CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS}")
|
||||
@ -0,0 +1,15 @@
|
||||
if(NOT DEFINED ModuleName OR ModuleName EQUAL "")
|
||||
set(ModuleName "DefaultModule")
|
||||
endif()
|
||||
|
||||
# BUILD_ARCH:x86_64 aarch64 参考 gcc -v 结果的 Target
|
||||
if(NOT DEFINED BUILD_ARCH)
|
||||
set(BUILD_ARCH x86_64 CACHE STRING "Arch of this project")
|
||||
endif()
|
||||
|
||||
if(NOT "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" STREQUAL "${CMAKE_BINARY_DIR}/../lib/${BUILD_ARCH}/")
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${BUILD_ARCH}/)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/${BUILD_ARCH}/)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/)
|
||||
endif()
|
||||
link_directories(${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
|
||||
@ -0,0 +1,2 @@
|
||||
message(STATUS "build <${ModuleName}>")
|
||||
message(STATUS " ARCH type:${BUILD_ARCH} Mode:${CMAKE_BUILD_TYPE}")
|
||||
@ -0,0 +1,42 @@
|
||||
cmake_minimum_required (VERSION 3.5)
|
||||
find_package( OpenCV REQUIRED )
|
||||
|
||||
message(STATUS "oPENCV Library status:")
|
||||
message(STATUS ">version:${OpenCV_VERSION}")
|
||||
message(STATUS "Include:${OpenCV_INCLUDE_DIRS}")
|
||||
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations")
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/AlgorithmModule/include
|
||||
${PROJECT_SOURCE_DIR}/ConfigModule/include
|
||||
${PROJECT_SOURCE_DIR}/ExtractImageModule/include
|
||||
)
|
||||
|
||||
link_directories(
|
||||
/usr/local/lib/
|
||||
/usr/local/cuda/lib64
|
||||
)
|
||||
file(GLOB SRC_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
add_executable("test_CellAOI" ${SRC_LISTS})
|
||||
|
||||
target_link_libraries("test_CellAOI"
|
||||
pthread
|
||||
z
|
||||
nvinfer
|
||||
TY_Check
|
||||
Config
|
||||
ExtractImage
|
||||
#/usr/local/cuda-12.1/targets/x86_64-linux/lib/libcudart.so
|
||||
${OpenCV_LIBS}
|
||||
)
|
||||
# 设置该目标的RPATH
|
||||
set_target_properties("test_CellAOI" PROPERTIES
|
||||
BUILD_RPATH "\$ORIGIN"
|
||||
)
|
||||
set(ModuleName "")
|
||||
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: sueRimn
|
||||
* @Date: 2022-03-16 17:09:11
|
||||
* @LastEditors: sueRimn
|
||||
* @LastEditTime: 2022-09-23 17:43:15
|
||||
*/
|
||||
|
||||
#ifndef _CheckDefine_HPP_
|
||||
#define _CheckDefine_HPP_
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#define SRC_IMAGE_WIDTH 14192
|
||||
#define SRC_IMAGE_HEIGHT 10640
|
||||
|
||||
#define SRC_IMAGE_SIZE 1*SRC_IMAGE_WIDTH *SRC_IMAGE_HEIGHT
|
||||
|
||||
#define AI_BATCH_SIZE 1
|
||||
|
||||
|
||||
enum ERRORDEFINE
|
||||
{
|
||||
RESULT_OK,
|
||||
ERROR_CHECK_IMG_NULL, // 检测图片为空
|
||||
ERROR_CHECK_RESOURCE_NULL, // 检测资源为空
|
||||
ERROR_PRECHECK_IMG_NULL, // 预检测图片 异常
|
||||
|
||||
};
|
||||
// 检测控制参数
|
||||
struct CheckControlConfigSt
|
||||
{
|
||||
CheckControlConfigSt()
|
||||
{
|
||||
}
|
||||
};
|
||||
// 系统运行控制参数
|
||||
struct SystmeControlConfigST
|
||||
{
|
||||
CheckControlConfigSt checkControlConfig; //// 检测控制参数
|
||||
|
||||
SystmeControlConfigST()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_CORELOGICFACTORY_HPP_
|
||||
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* @Author: xiewenji 527774126@qq.com
|
||||
* @Date: 2025-07-25 09:14:25
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-09-11 18:00:27
|
||||
* @FilePath: /BOE_CELL_ET/AlgorithmModule/example/Image_ReadAndChange.h
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
/*
|
||||
//图片基本处理
|
||||
*/
|
||||
#ifndef Image_ReadAndChange_H_
|
||||
#define Image_ReadAndChange_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include "CheckDefine.h"
|
||||
#include "ImgCheckConfig.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
// 图片读取的通道
|
||||
class Image_ReadChannel
|
||||
{
|
||||
public:
|
||||
struct ReadImageName
|
||||
{
|
||||
std::string strDetChannle;
|
||||
std::vector<std::string> strImgNameList;
|
||||
|
||||
ReadImageName()
|
||||
{
|
||||
strImgNameList.clear();
|
||||
strDetChannle = "";
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
/* data */
|
||||
public:
|
||||
Image_ReadChannel(/* args */);
|
||||
~Image_ReadChannel();
|
||||
|
||||
bool containsChinese(const std::string &str);
|
||||
|
||||
int ReadJsonConfig(std::string json_path); // 加载检测图片名称配置参数
|
||||
|
||||
bool CompareIgnoreCase(const std::string &str1, const std::string &str2);
|
||||
|
||||
std::string strDetName(std::string strImageName);
|
||||
|
||||
private:
|
||||
std::vector<ReadImageName> m_ChannelNameList;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,35 @@
|
||||
#include "JsonCoversion.h"
|
||||
|
||||
JsonCoversion::JsonCoversion()
|
||||
{
|
||||
//ctor
|
||||
}
|
||||
|
||||
JsonCoversion::~JsonCoversion()
|
||||
{
|
||||
//dtor
|
||||
}
|
||||
string JsonCoversion::toJson()
|
||||
{
|
||||
toJsonValue();
|
||||
|
||||
std::unique_ptr<Json::StreamWriter> jsonWriter(writerBuilder.newStreamWriter());
|
||||
std::ostringstream os;
|
||||
std::string jsonStr;
|
||||
jsonWriter->write(root,&os);
|
||||
jsonStr = os.str();
|
||||
return jsonStr;
|
||||
}
|
||||
|
||||
void JsonCoversion::toObject(string & strBuf)
|
||||
{
|
||||
std::unique_ptr<Json::CharReader> const jsonReader(readerBuilder.newCharReader());
|
||||
|
||||
JSONCPP_STRING errs;
|
||||
bool res = jsonReader->parse(strBuf.c_str(), strBuf.c_str()+strBuf.length(), &root, &errs);
|
||||
if (!res || !errs.empty())
|
||||
{
|
||||
std::cout << "parseJson err. " << errs << std::endl;
|
||||
}
|
||||
toObjectFromValue(root);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
#ifndef JsonCoversion_H
|
||||
#define JsonCoversion_H
|
||||
#include<iostream>
|
||||
#include<memory>
|
||||
#include<string>
|
||||
#include "json/json.h"
|
||||
using namespace std;
|
||||
|
||||
class JsonCoversion
|
||||
{
|
||||
protected:
|
||||
Json::Value root;
|
||||
|
||||
// Json::FastWriter writer; //弃用 改用StreamWriterBuilder
|
||||
Json::StreamWriterBuilder writerBuilder;
|
||||
|
||||
// Json::Reader reader; //弃用 改用CharReaderBuilder
|
||||
Json::CharReaderBuilder readerBuilder;
|
||||
public:
|
||||
JsonCoversion();
|
||||
virtual ~JsonCoversion();
|
||||
protected:
|
||||
public:
|
||||
string toJson();
|
||||
void toObject(string & strBuf);
|
||||
protected:
|
||||
virtual Json::Value toJsonValue() = 0;
|
||||
virtual void toObjectFromValue(Json::Value root) = 0;
|
||||
};
|
||||
|
||||
#endif // JsonCoversion_H
|
||||
@ -0,0 +1,287 @@
|
||||
#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::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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
m_extract.pimage_ReadChannel = pimage_ReadChannel;
|
||||
m_extract.m_product_Camera_List.clear();
|
||||
int re = m_extract.Read_Image_List(strPath, strproduct);
|
||||
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 Read_Image::Read_Image_List(std::string strPath_left, std::string strPath_right, std::string strproduct)
|
||||
{
|
||||
m_extract.pimage_ReadChannel = pimage_ReadChannel;
|
||||
m_extract.m_product_Camera_List.clear();
|
||||
int re = m_extract.Read_Image_List(strPath_left, strPath_right, strproduct);
|
||||
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::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;
|
||||
}
|
||||
fs::path p = fs::path(strPath);
|
||||
std::string filenameWithoutExt = p.stem().string();
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
fs::path p = fs::path(strPath);
|
||||
std::string filename = p.stem();
|
||||
if (filename.find("TA") != std::string::npos)
|
||||
return "TA";
|
||||
else if (filename.find("CA") != std::string::npos)
|
||||
return "CA";
|
||||
|
||||
// std::cout << "完整路径: " << p << std::endl;
|
||||
// std::cout << "文件名: " << p.filename() << std::endl;
|
||||
// std::cout << "不带后缀的文件名: " << p.stem() << std::endl;
|
||||
// std::cout << "后缀: " << p.extension() << std::endl;
|
||||
// getchar();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
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 lastDir = p.parent_path().filename();
|
||||
|
||||
std::string name = lastDir.string();
|
||||
if (name.length()<7)
|
||||
{
|
||||
lastDir = p.parent_path().parent_path().filename();
|
||||
name = lastDir.string();
|
||||
}
|
||||
|
||||
// std::cout << name << std::endl;
|
||||
if (name.empty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
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();
|
||||
if (filename.find("TAA") != std::string::npos)
|
||||
strchannelName = "TA";
|
||||
else if (filename.find("TAB") != std::string::npos)
|
||||
strchannelName = "TA";
|
||||
else if (filename.find("CAA") != std::string::npos)
|
||||
strchannelName = "CA";
|
||||
else if (filename.find("CAB") != std::string::npos)
|
||||
strchannelName = "CA";
|
||||
else if (filename.find("CA") != std::string::npos)
|
||||
strchannelName = "CA";
|
||||
else if (filename.find("TA") != std::string::npos)
|
||||
strchannelName = "TA";
|
||||
return strchannelName;
|
||||
}
|
||||
int Extract_ALL::Read_Image_List(std::string strPath, std::string strproduct)
|
||||
{
|
||||
std::string strSearchImgPath = strPath + "/*.ytimage";
|
||||
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
|
||||
|
||||
// strSearchImgPath = strPath + "/*.png";
|
||||
// Read_Camera_Product_Image(strSearchImgPath, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Extract_ALL::Read_Image_List(std::string strPath_left, std::string strPath_right, std::string strproduct)
|
||||
{
|
||||
std::string strSearchImgPath = strPath_left + "/*.ytimage";
|
||||
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
|
||||
strSearchImgPath = strPath_right + "/*.ytimage";
|
||||
Read_Camera_Product_Image(strSearchImgPath, 0, strproduct);
|
||||
|
||||
// strSearchImgPath = strPath + "/*.png";
|
||||
// Read_Camera_Product_Image(strSearchImgPath, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,185 @@
|
||||
|
||||
#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\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
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue