commit
ed9bca34db
@ -0,0 +1,6 @@
|
||||
/build
|
||||
/lib
|
||||
/include
|
||||
/data
|
||||
/SaveImg
|
||||
.vscode/launch.json
|
||||
@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**",
|
||||
"/usr/local/include/opencv4"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "gnu++14",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"thread": "cpp",
|
||||
"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",
|
||||
"complex": "cpp",
|
||||
"condition_variable": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"exception": "cpp",
|
||||
"algorithm": "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",
|
||||
"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",
|
||||
"cinttypes": "cpp",
|
||||
"typeindex": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"variant": "cpp",
|
||||
"bit": "cpp",
|
||||
"codecvt": "cpp",
|
||||
"filesystem": "cpp"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
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}")
|
||||
|
||||
|
||||
if(CHECK_WORK_Value STREQUAL "POL_ET")
|
||||
set(PROJECT_NAME "test_POL_ET")
|
||||
elseif(CHECK_WORK_Value STREQUAL "CELL_ET")
|
||||
set(PROJECT_NAME "test_CELL_ET")
|
||||
elseif(CHECK_WORK_Value STREQUAL "FOG_ET")
|
||||
set(PROJECT_NAME "test_FOG_ET")
|
||||
else()
|
||||
set(PROJECT_NAME "test_POL_ET")
|
||||
endif()
|
||||
|
||||
# 设置程序名称
|
||||
project(${PROJECT_NAME})
|
||||
set(ModuleName "${PROJECT_NAME}")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations")
|
||||
|
||||
include_directories(
|
||||
/usr/local/include
|
||||
#/usr/local/cuda-12.1/targets/x86_64-linux/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/ConfigModule/include
|
||||
)
|
||||
|
||||
link_directories(
|
||||
/usr/local/lib/
|
||||
)
|
||||
file(GLOB SRC_LISTS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SRC_LISTS})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
pthread
|
||||
z
|
||||
nvinfer
|
||||
TY_Check
|
||||
Config
|
||||
#/usr/local/cuda-12.1/targets/x86_64-linux/lib/libcudart.so
|
||||
${OpenCV_LIBS}
|
||||
)
|
||||
# 设置该目标的RPATH
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
BUILD_RPATH "\$ORIGIN"
|
||||
)
|
||||
set(ModuleName "")
|
||||
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* @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>
|
||||
#include "BlobBase.h"
|
||||
|
||||
#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,59 @@
|
||||
|
||||
#ifndef _CONFIGDEAL_HPP_
|
||||
#define _CONFIGDEAL_HPP_
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
using namespace std;
|
||||
|
||||
#define CONFIGLEN 256
|
||||
#define CheckData_CONFIG_File "../DataConfig/CheckData_Config.ini"
|
||||
|
||||
enum INI_RES
|
||||
{
|
||||
INI_SUCCESS, //成功
|
||||
INI_ERROR, //普通错误
|
||||
INI_OPENFILE_ERROR, //打开文件失败
|
||||
INI_NO_ATTR //无对应的键值
|
||||
};
|
||||
|
||||
// 子键索引 子键值
|
||||
typedef map<std::string, std::string> KEYMAP;
|
||||
// 主键索引 主键值
|
||||
typedef map<std::string, KEYMAP> MAINKEYMAP;
|
||||
// config 文件的基本操作类
|
||||
|
||||
class CIni
|
||||
{
|
||||
public:
|
||||
// 构造函数
|
||||
CIni();
|
||||
|
||||
// 析够函数
|
||||
virtual ~CIni();
|
||||
public:
|
||||
//获取整形的键值
|
||||
int GetInt(const char* mAttr, const char* cAttr);
|
||||
//获取键值的字符串
|
||||
char *GetStr(const char* mAttr, const char* cAttr);
|
||||
// 打开config 文件
|
||||
INI_RES OpenFile(const char* pathName, const char* type);
|
||||
// 关闭config 文件
|
||||
INI_RES CloseFile();
|
||||
protected:
|
||||
// 读取config文件
|
||||
INI_RES GetKey(const char* mAttr, const char* cAttr, char* value);
|
||||
protected:
|
||||
// 被打开的文件局柄
|
||||
FILE* m_fp;
|
||||
char m_szKey[CONFIGLEN];
|
||||
MAINKEYMAP m_Map;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#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-07-26 10:51:45
|
||||
* @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,166 @@
|
||||
/*
|
||||
* @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 "ImgBasicDeal.h"
|
||||
ImgBasicDeal::ImgBasicDeal()
|
||||
{
|
||||
|
||||
// DrawBlobErrorCorleList[ERROR_TYPE_OK] = cv::Scalar(128, 128, 128);
|
||||
// DrawBlobErrorCorleList[ERROR_TYPE_yc] = cv::Scalar(255, 0, 0);
|
||||
}
|
||||
|
||||
ImgBasicDeal::~ImgBasicDeal()
|
||||
{
|
||||
}
|
||||
|
||||
int ImgBasicDeal::DrawResult(cv::Mat &image_draw, CheckResult result)
|
||||
{
|
||||
|
||||
// if (resultimg.channels() == 1)
|
||||
// {
|
||||
// cv::cvtColor(resultimg, image_draw, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// image_draw = resultimg.clone();
|
||||
// }
|
||||
// printf("result.blobResult.blobNum %d\n", result.blobResult.blobNum);
|
||||
// for (int i = 0; i < result.blobResult.blobNum; i++)
|
||||
// {
|
||||
// // if (blobs.Pass[i])
|
||||
// {
|
||||
// auto enType = result.blobResult.bloblist[i].UserErrorType;
|
||||
// if (result.blobResult.bloblist[i].UserErrorType == 0)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// cv::Rect roi = result.blobResult.bloblist[i].blob_ResizeImg;
|
||||
|
||||
// cv::Point pc;
|
||||
// pc.x = roi.x + roi.width * 0.5;
|
||||
// pc.y = roi.y + roi.height * 0.5;
|
||||
// int rw = roi.width * 0.5;
|
||||
// int rh = roi.height * 0.5;
|
||||
// int r = std::sqrt(rw * rw + rh * rh) * 1.1 + 8;
|
||||
|
||||
// cv::circle(image_draw, pc, r, DrawBlobErrorCorleList[result.blobResult.bloblist[i].UserErrorType]);
|
||||
|
||||
// // 设置绘制文本的相关参数
|
||||
// std::string text = std::to_string(result.blobResult.bloblist[i].UserErrorType) + " A: " + std::to_string(result.blobResult.bloblist[i].JudgArea) + " E: " + std::to_string(result.blobResult.bloblist[i].energy);
|
||||
|
||||
// int baseline;
|
||||
// // 获取文本框的长宽
|
||||
// cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);
|
||||
// // 将文本框居中绘制
|
||||
// cv::Point origin = CalcTextPosition(pc, r, text_size, image_draw.size(), (ERROR_TYPE_)enType);
|
||||
// cv::putText(image_draw, text, origin, font_face, font_scale, cv::Scalar(255, 0, 0), thickness, 1, 0);
|
||||
// }
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
cv::Point ImgBasicDeal::CalcTextPosition(cv::Point pt, int radius, cv::Size text_size, cv::Size image_size, ERROR_TYPE_ type)
|
||||
{
|
||||
cv::Point dst;
|
||||
int y_offset = 0;
|
||||
// switch (type)
|
||||
// {
|
||||
// case ERROR_TYPE_OK:
|
||||
// y_offset = 20;
|
||||
// break;
|
||||
// case ERROR_TYPE_yc:
|
||||
// y_offset = 40;
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
dst.y = (pt.y - y_offset > text_size.height) ? pt.y - y_offset : pt.y + y_offset;
|
||||
if (dst.y >= image_size.height)
|
||||
{
|
||||
dst.y = image_size.height - 1;
|
||||
}
|
||||
dst.x = (pt.x + radius + text_size.width > image_size.width) ? pt.x - text_size.width - radius : pt.x + radius;
|
||||
if (dst.x < 0)
|
||||
{
|
||||
dst.x = 0;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
int ImgBasicDeal::DrawResult_small(cv::Mat &image_draw, int i, int j, CheckResult result)
|
||||
{
|
||||
|
||||
// cv::cvtColor(result.SamllImgList[i][j].img, image_draw, cv::COLOR_GRAY2RGB); // 彩色 可选项
|
||||
// for (int k = 0; k < result.SamllImgList[i][j].qxIndexArr.size(); k++)
|
||||
// {
|
||||
// int idx = result.SamllImgList[i][j].qxIndexArr.at(k);
|
||||
// {
|
||||
|
||||
// float energy;
|
||||
// float hj;
|
||||
// cv::Rect roi = result.qxiImageResult.at(idx).SmallImgroi;
|
||||
|
||||
// cv::Point pc;
|
||||
// pc.x = roi.x + roi.width * 0.5;
|
||||
// pc.y = roi.y + roi.height * 0.5;
|
||||
// int rw = roi.width * 0.5;
|
||||
// int rh = roi.height * 0.5;
|
||||
// int r = std::sqrt(rw * rw + rh * rh) * 1.5 + 12;
|
||||
|
||||
// cv::Scalar dcolor = cv::Scalar(0, 0, 255);
|
||||
|
||||
// if (result.qxiImageResult.at(idx).type == 0)
|
||||
// {
|
||||
// dcolor = cv::Scalar(0, 255, 0);
|
||||
// }
|
||||
|
||||
// cv::circle(image_draw, pc, r, dcolor);
|
||||
|
||||
// // 设置绘制文本的相关参数
|
||||
// char text[1024] = {0};
|
||||
// sprintf(text, "A:%.2f E:%.0f", result.qxiImageResult.at(idx).area, result.qxiImageResult.at(idx).energy);
|
||||
|
||||
// int baseline;
|
||||
// int font_face = cv::FONT_HERSHEY_SIMPLEX;
|
||||
// double font_scale = 0.5;
|
||||
// int thickness = 1;
|
||||
// // 获取文本框的长宽
|
||||
// cv::Size text_size = cv::getTextSize(text, font_face, font_scale, thickness, &baseline);
|
||||
|
||||
// // 将文本框居中绘制
|
||||
// cv::Point origin = cv::Point(roi.x, roi.y - 10);
|
||||
// if (origin.x + text_size.width > image_draw.cols)
|
||||
|
||||
// {
|
||||
// origin.x = image_draw.cols - text_size.width;
|
||||
// }
|
||||
|
||||
// if (origin.y < 10)
|
||||
|
||||
// {
|
||||
// origin.y = 10;
|
||||
// }
|
||||
|
||||
// cv::putText(image_draw, text, origin, font_face, font_scale, cv::Scalar(255, 0, 0), thickness, 1, 0);
|
||||
// }
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ImgBasicDeal::DrawPointList(cv::Mat &image_draw, std::vector<cv::Point> plist)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ImgBasicDeal::preDealImg(cv::Mat &srcimg, cv::Mat &image_resize, bool bfilpSrcImg)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
/*
|
||||
//图片基本处理
|
||||
*/
|
||||
#ifndef ImgBasicDeal_H_
|
||||
#define ImgBasicDeal_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include "CheckDefine.h"
|
||||
#include "ImgCheckConfig.h"
|
||||
using namespace std;
|
||||
|
||||
class ImgBasicDeal
|
||||
{
|
||||
|
||||
public:
|
||||
ImgBasicDeal();
|
||||
~ImgBasicDeal();
|
||||
|
||||
/// @brief 画结果信息到图片上
|
||||
/// @return
|
||||
int DrawResult(cv::Mat &image_draw, CheckResult result);
|
||||
/// @brief 对图像预处理
|
||||
/// @param srcimg 原始图 输出 原始图或镜像图
|
||||
/// @param resizeimg 裁剪resize到 固定大小的图片
|
||||
/// @param bfilpSrcimg 是否镜像原始图
|
||||
/// @return
|
||||
int DrawResult_small(cv::Mat &image_draw, int i, int j, CheckResult result);
|
||||
int preDealImg(cv::Mat &srcimg, cv::Mat &image_resize, bool bfilpSrcImg = true);
|
||||
int DrawPointList(cv::Mat &image_draw, std::vector<cv::Point> plist);
|
||||
cv::Point CalcTextPosition(cv::Point pt, int radius, cv::Size text_size, cv::Size image_size, ERROR_TYPE_ type);
|
||||
public:
|
||||
int font_face = cv::FONT_HERSHEY_SIMPLEX;
|
||||
double font_scale = 0.5;
|
||||
int thickness = 1;
|
||||
|
||||
cv::Scalar Color_Brightness_roi = cv::Scalar(0, 255, 0);
|
||||
cv::Scalar Color_Brightness_text = cv::Scalar(0, 255, 0);
|
||||
cv::Scalar DrawBlobErrorCorleList[ERROR_TYPE_COUNT];
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#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,470 @@
|
||||
#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::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, 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)
|
||||
{
|
||||
m_extract_CELL_ET.pimage_ReadChannel = pimage_ReadChannel;
|
||||
m_extract_CELL_ET.m_product_Camera_List.clear();
|
||||
int re = m_extract_CELL_ET.Read_Image_List(strPath);
|
||||
if (re != 0)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
m_product_Camera_List.clear();
|
||||
m_product_Camera_List.assign(m_extract_CELL_ET.m_product_Camera_List.begin(), m_extract_CELL_ET.m_product_Camera_List.end());
|
||||
|
||||
for (int i = 0; i < m_extract_CELL_ET.m_product_Camera_List.size(); i++)
|
||||
{
|
||||
m_extract_CELL_ET.m_product_Camera_List[i]->print();
|
||||
}
|
||||
|
||||
// m_extract_BD.m_product_Camera_List.clear();
|
||||
// int re = m_extract_BD.Read_Image_List(strPath);
|
||||
// if (re != 0)
|
||||
// {
|
||||
// return re;
|
||||
// }
|
||||
// m_product_Camera_List.clear();
|
||||
// m_product_Camera_List.assign(m_extract_BD.m_product_Camera_List.begin(), m_extract_BD.m_product_Camera_List.end());
|
||||
|
||||
// for (int i = 0; i < m_extract_BD.m_product_Camera_List.size(); i++)
|
||||
// {
|
||||
// m_extract_BD.m_product_Camera_List[i]->print();
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Extract_CELL_ET::Extract_Info(std::string strPath, 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 (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_CELL_ET::Extract_Camera_Name(std::string strPath, int userflag)
|
||||
{
|
||||
if (userflag == 1)
|
||||
{
|
||||
|
||||
std::string prefix = "_0_";
|
||||
bool bleft = false;
|
||||
size_t pos1 = strPath.rfind(prefix);
|
||||
|
||||
if (pos1 != std::string::npos)
|
||||
{
|
||||
bleft = true;
|
||||
}
|
||||
|
||||
std::string prefix1 = "工位左";
|
||||
bool bleft1 = false;
|
||||
size_t pos2 = strPath.rfind(prefix1);
|
||||
|
||||
if (pos2 != std::string::npos)
|
||||
{
|
||||
bleft1 = true;
|
||||
}
|
||||
if (bleft || bleft1)
|
||||
{
|
||||
return "left";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string prefix = "_1_";
|
||||
bool bright = false;
|
||||
size_t pos1 = strPath.rfind(prefix);
|
||||
|
||||
if (pos1 != std::string::npos)
|
||||
{
|
||||
bright = true;
|
||||
}
|
||||
std::string prefix1 = "工位右";
|
||||
bool bright1 = false;
|
||||
size_t pos2 = strPath.rfind(prefix1);
|
||||
|
||||
if (pos2 != std::string::npos)
|
||||
{
|
||||
bright1 = true;
|
||||
}
|
||||
|
||||
if (bright || bright1)
|
||||
{
|
||||
return "right";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fs::path p = fs::path(strPath);
|
||||
bool bleft = dirPathContains(p, "left");
|
||||
bool bleft1 = dirPathContains(p, "shard_left");
|
||||
if (bleft || bleft1)
|
||||
{
|
||||
return "left";
|
||||
}
|
||||
else
|
||||
{
|
||||
bool bright = dirPathContains(p, "right");
|
||||
bool bright1 = dirPathContains(p, "shard_right");
|
||||
if (bright || bright1)
|
||||
{
|
||||
return "right";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string Extract_CELL_ET::Extract_Product_Name(std::string strPath, int userflag)
|
||||
{
|
||||
|
||||
if (userflag == 0)
|
||||
{
|
||||
/* code */
|
||||
|
||||
// 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.empty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string prefix = "__DB__";
|
||||
|
||||
if (name.rfind(prefix, 0) == 0)
|
||||
{ // 判断是否以 "__DB__" 开头
|
||||
std::string result = name.substr(prefix.length());
|
||||
std::cout << "Product name: " << result << std::endl;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
std::cout << "Product name error: " << name << std::endl;
|
||||
}
|
||||
}
|
||||
else if (userflag == 1)
|
||||
{
|
||||
fs::path p = fs::path(strPath);
|
||||
fs::path lastDir = p.parent_path().filename();
|
||||
|
||||
std::string name = lastDir.string();
|
||||
if (name.empty() || name != "OriginalImage")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
fs::path lastDir123 = p.parent_path().parent_path().filename();
|
||||
|
||||
std::string sproduct = lastDir123.string();
|
||||
// std::cout << "Product name error: " << sproduct << std::endl;
|
||||
|
||||
size_t lastUnderscore = sproduct.find('_');
|
||||
if (lastUnderscore == std::string::npos)
|
||||
return "";
|
||||
|
||||
std::string strImageproduct = sproduct.substr(0, lastUnderscore);
|
||||
|
||||
// printf("strImageChannel %s\n", strImageproduct.c_str());
|
||||
|
||||
return strImageproduct;
|
||||
}
|
||||
|
||||
// // 独特判断
|
||||
// if (name.find("__DB__") != std::string::npos)
|
||||
// {
|
||||
// }
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string Extract_CELL_ET::Extract_Channel_Name(std::string strPath, int userflag)
|
||||
{
|
||||
std::string strchannelName = "";
|
||||
if (userflag == 1)
|
||||
{
|
||||
fs::path p = fs::path(strPath);
|
||||
std::string filenameWithoutExt = p.stem().string();
|
||||
std::cout << "提取的内容: " << filenameWithoutExt << std::endl;
|
||||
|
||||
|
||||
if (pimage_ReadChannel)
|
||||
{
|
||||
strchannelName = pimage_ReadChannel->strDetName(filenameWithoutExt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fs::path p = fs::path(strPath);
|
||||
std::string filenameWithoutExt = p.stem().string();
|
||||
// std::cout << "提取的内容: " << filenameWithoutExt << std::endl;
|
||||
|
||||
std::string strexName = "";
|
||||
size_t pos = filenameWithoutExt.find('^');
|
||||
if (pos != std::string::npos && pos + 1 < filenameWithoutExt.size())
|
||||
{
|
||||
strexName = filenameWithoutExt.substr(pos + 1);
|
||||
std::cout << "提取到的字符串: " << strexName << std::endl;
|
||||
}
|
||||
if (pimage_ReadChannel)
|
||||
{
|
||||
strchannelName = pimage_ReadChannel->strDetName(strexName);
|
||||
}
|
||||
}
|
||||
|
||||
return strchannelName;
|
||||
}
|
||||
int Extract_CELL_ET::Read_Image_List(std::string strPath)
|
||||
{
|
||||
std::string strSearchImgPath = strPath + "/*.tif";
|
||||
Read_Camera_Product_Image(strSearchImgPath, 0);
|
||||
|
||||
strSearchImgPath = strPath + "/*.png";
|
||||
Read_Camera_Product_Image(strSearchImgPath, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int Extract_BD::Extract_Info(std::string strPath, int userflag)
|
||||
{
|
||||
std::cout << strPath << std::endl;
|
||||
// 1、获取 产品名称
|
||||
std::string strProductName = Extract_Product_Name(strPath);
|
||||
if (strProductName.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::shared_ptr<Product_File_Info> pProduct = GetProduct(strProductName);
|
||||
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);
|
||||
if (strCameraName.empty())
|
||||
{
|
||||
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);
|
||||
if (strChannelName.empty())
|
||||
{
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
std::string Extract_BD::Extract_Camera_Name(std::string strPath, int userflag)
|
||||
{
|
||||
fs::path p = fs::path(strPath);
|
||||
|
||||
return "";
|
||||
}
|
||||
std::string Extract_BD::Extract_Product_Name(std::string strPath, int userflag)
|
||||
{
|
||||
fs::path p = fs::path(strPath);
|
||||
fs::path lastDir = p.parent_path().filename();
|
||||
|
||||
std::string name = lastDir.string();
|
||||
if (name.empty())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t pos = name.rfind('-'); // 找最后一个 '-'
|
||||
if (pos != std::string::npos && pos + 1 < name.size())
|
||||
{
|
||||
return name.substr(pos + 1);
|
||||
}
|
||||
return ""; // 没有找到 '-' 或后面没有字符
|
||||
}
|
||||
std::string Extract_BD::Extract_Channel_Name(std::string strPath, int userflag)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
int Extract_BD::Read_Image_List(std::string strPath)
|
||||
{
|
||||
std::string strSearchImgPath = strPath + "/*.jpg";
|
||||
Read_Camera_Product_Image(strSearchImgPath, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,192 @@
|
||||
|
||||
#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,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) = 0;
|
||||
int Read_Product_Image(std::string strPath);
|
||||
int Read_Camera_Product_Image(std::string strPath,int userflag) ;
|
||||
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_CELL_ET : public Extract_Name_Base
|
||||
{
|
||||
public:
|
||||
int Extract_Info(std::string strPath,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);
|
||||
};
|
||||
class Extract_BD : public Extract_Name_Base
|
||||
{
|
||||
public:
|
||||
int Extract_Info(std::string strPath,int userflag );
|
||||
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);
|
||||
};
|
||||
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);
|
||||
|
||||
Extract_CELL_ET m_extract_CELL_ET;
|
||||
Extract_BD m_extract_BD;
|
||||
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
@ -0,0 +1,704 @@
|
||||
|
||||
#ifndef _deal_HPP_
|
||||
#define _deal_HPP_
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <mutex>
|
||||
#include <unistd.h>
|
||||
#include "ImgBasicDeal.h"
|
||||
#include "SystemCommonDefine.h"
|
||||
#include "ImgCheckBase.h"
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "ImgBasicDeal.h"
|
||||
#include "ConfigBase.h"
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <string>
|
||||
#include "Image_ReadAndChange.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include "Read_Image.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
enum Thread_Status_
|
||||
{
|
||||
Thread_Status_IDE,
|
||||
Thread_Status_READY,
|
||||
Thread_Status_BUSY,
|
||||
Thread_Status_COMMPLET,
|
||||
};
|
||||
enum Thread_ReadImg_Status_
|
||||
{
|
||||
ReadImg_Status_IDE,
|
||||
ReadImg_Status_Read,
|
||||
ReadImg_Status_COMMPLET,
|
||||
};
|
||||
|
||||
// 各种线程处理状态信息
|
||||
enum DET_Status_Type_
|
||||
{
|
||||
Status_Type_ReadAndDet, // 读取图和处理
|
||||
Status_Type_PullPath, // 读取图片路径
|
||||
Status_Type_Count,
|
||||
};
|
||||
|
||||
enum Mutex_Type_
|
||||
{
|
||||
Mutex_Type_ReadImgThread, // 读图线程
|
||||
Mutex_Type_DetStatus,
|
||||
Mutex_Type_DetResult,
|
||||
Mutex_Type_Count,
|
||||
};
|
||||
// 读线程,处理类型。
|
||||
enum READ_THREAD_TYPE_
|
||||
{
|
||||
READ_THREAD_TYPE_NULL,
|
||||
READ_THREAD_TYPE_READIMG, // 读图
|
||||
READ_THREAD_Detect, // 检测模式
|
||||
READ_THREAD_TYPE_COUNT,
|
||||
};
|
||||
|
||||
// 线程运行模式
|
||||
enum THREAD_RUN_TYPE
|
||||
{
|
||||
THREAD_RUN_Only_ReadImg, // 仅读图
|
||||
THREAD_RUN_ALL, // 所有
|
||||
};
|
||||
|
||||
#define READ_IMG_THREAD_NUM 12
|
||||
#define Save_IMG_THREAD_NUM 5
|
||||
|
||||
using namespace std;
|
||||
enum RUNTYPE_
|
||||
{
|
||||
RUNTYPE_RUN_Pre_BigImg,
|
||||
RUNTYPE_RUN_Pre_BigImg_Cam2,
|
||||
RUNTYPE_RUN_File_BigImg,
|
||||
RUNTYPE_RUN_File_CEEL_ET,
|
||||
RUNTYPE_RUN_File_BigImg_WHJC_Date,
|
||||
RUNTYPE_RUN_File_BigImg_WHJC_EDGE_TEST,
|
||||
RUNTYPE_RUN_File_BigImg_WHJC_EDGE_AI_TEST,
|
||||
RUNTYPE_RUN_Ong_BigImg_WHJC_EDGE_TEST,
|
||||
RUNTYPE_RUN_File_BigImg_WHJC_ZF_TEST,
|
||||
RUNTYPE_RUN_File_MarkLine_Test,
|
||||
RUNTYPE_RUN_Align,
|
||||
};
|
||||
|
||||
struct JC_IMAGE_INFO_
|
||||
{
|
||||
enum Status_
|
||||
{
|
||||
STATUS_Image_IDE,
|
||||
STATUS_Image_READ,
|
||||
STATUS_Image_COMMPLET,
|
||||
STATUS_Det_Start,
|
||||
};
|
||||
std::string strProductID; // 产品ID
|
||||
std::string strCamID; // 相机名称
|
||||
std::string strchannelName; // 通道名称
|
||||
std::string strPath; // 完整路径
|
||||
std::string strName; // 图片名称
|
||||
cv::Mat img; // 图像数据
|
||||
Status_ status; // 状态
|
||||
long readImg_start; // 读取开始时间
|
||||
long readImg_end; // 读取结束时间
|
||||
|
||||
// 构造函数,调用 Init 初始化
|
||||
JC_IMAGE_INFO_()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// 初始化函数,重置所有成员变量
|
||||
void Init()
|
||||
{
|
||||
strProductID = "";
|
||||
strCamID = "";
|
||||
strchannelName = "";
|
||||
strPath = "";
|
||||
strName = "";
|
||||
img.release(); // 释放图像内存
|
||||
status = STATUS_Image_IDE;
|
||||
readImg_start = 0;
|
||||
readImg_end = 0;
|
||||
}
|
||||
|
||||
// 拷贝函数,将传入的结构体内容复制到当前对象
|
||||
void copy(JC_IMAGE_INFO_ tem)
|
||||
{
|
||||
this->strProductID = tem.strProductID;
|
||||
this->strCamID = tem.strCamID;
|
||||
this->strchannelName = tem.strchannelName;
|
||||
this->strPath = tem.strPath;
|
||||
this->strName = tem.strName;
|
||||
if (!tem.img.empty())
|
||||
{
|
||||
this->img = tem.img.clone(); // 深拷贝图像数据
|
||||
}
|
||||
this->status = tem.status;
|
||||
this->readImg_start = tem.readImg_start;
|
||||
this->readImg_end = tem.readImg_end;
|
||||
}
|
||||
|
||||
// 打印信息函数(可选)
|
||||
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 << "Status: " << status << std::endl;
|
||||
std::cout << "Read Start Time: " << readImg_start << std::endl;
|
||||
std::cout << "Read End Time: " << readImg_end << std::endl;
|
||||
}
|
||||
};
|
||||
struct Det_single_img_Result_Info
|
||||
{
|
||||
int result;
|
||||
std::string name;
|
||||
std::string qx_name;
|
||||
Det_single_img_Result_Info()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
name = "";
|
||||
result = 0;
|
||||
qx_name = "NO";
|
||||
}
|
||||
};
|
||||
struct Det_One_Result_Info
|
||||
{
|
||||
int result;
|
||||
long time_s;
|
||||
long time_e;
|
||||
std::string Product_ID;
|
||||
std::vector<Det_single_img_Result_Info> img_result_list;
|
||||
Det_One_Result_Info()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
Product_ID = "";
|
||||
time_s = 0;
|
||||
time_e = 0;
|
||||
result = 0;
|
||||
img_result_list.erase(img_result_list.begin(), img_result_list.end());
|
||||
img_result_list.clear();
|
||||
}
|
||||
std::string print()
|
||||
{
|
||||
std::string str = "";
|
||||
// printf("%s:result %d | ", Product_ID.c_str(), result);
|
||||
char buffer[64];
|
||||
sprintf(buffer, "%s:result %d time %ld | ", Product_ID.c_str(), result, time_e - time_s);
|
||||
std::string st1 = buffer;
|
||||
str += st1;
|
||||
for (size_t i = 0; i < img_result_list.size(); i++)
|
||||
{
|
||||
str += img_result_list.at(i).name + " " + img_result_list.at(i).qx_name + " | ";
|
||||
}
|
||||
// str += str;
|
||||
|
||||
return str;
|
||||
// printf("%s\n", str.c_str());
|
||||
}
|
||||
};
|
||||
struct Det_File_qx_Info
|
||||
{
|
||||
std::string qx_name;
|
||||
int num;
|
||||
Det_File_qx_Info()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
qx_name = "";
|
||||
num = 0;
|
||||
}
|
||||
};
|
||||
// 套图检测 统计结果信息
|
||||
struct Det_File_Result_Info
|
||||
{
|
||||
int det_num_all;
|
||||
int det_num_ok;
|
||||
int det_num_ng;
|
||||
int det_num_error;
|
||||
float sumtime_S;
|
||||
long startTime_S;
|
||||
float mean_time;
|
||||
std::vector<Det_One_Result_Info> one_result_list;
|
||||
std::vector<std::string> strlist;
|
||||
std::vector<Det_File_qx_Info> qx_result_list;
|
||||
Det_File_Result_Info()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
det_num_all = 0;
|
||||
det_num_ok = 0;
|
||||
det_num_ng = 0;
|
||||
det_num_error = 0;
|
||||
sumtime_S = 0;
|
||||
startTime_S = 0;
|
||||
mean_time = 0;
|
||||
one_result_list.erase(one_result_list.begin(), one_result_list.end());
|
||||
one_result_list.clear();
|
||||
strlist.erase(strlist.begin(), strlist.end());
|
||||
strlist.clear();
|
||||
qx_result_list.erase(qx_result_list.begin(), qx_result_list.end());
|
||||
qx_result_list.clear();
|
||||
}
|
||||
void updata(std::string productid, std::string imgname, int nresult, long t)
|
||||
{
|
||||
sumtime_S = t - startTime_S;
|
||||
sumtime_S /= 1000;
|
||||
if (det_num_all > 0)
|
||||
{
|
||||
mean_time = sumtime_S / det_num_all;
|
||||
}
|
||||
|
||||
for (int i = 0; i < one_result_list.size(); i++)
|
||||
{
|
||||
if (one_result_list.at(i).Product_ID == productid)
|
||||
{
|
||||
// if (one_result_list.at(i).result < 0)
|
||||
// {
|
||||
// one_result_list.at(i).result = 0;
|
||||
// }
|
||||
one_result_list.at(i).time_e = t;
|
||||
|
||||
for (size_t j = 0; j < one_result_list.at(i).img_result_list.size(); j++)
|
||||
{
|
||||
if (one_result_list.at(i).img_result_list.at(j).name == imgname)
|
||||
{
|
||||
one_result_list.at(i).img_result_list.at(j).result = nresult;
|
||||
if (nresult == 0)
|
||||
{
|
||||
one_result_list.at(i).img_result_list.at(j).qx_name = "OK";
|
||||
}
|
||||
else if (nresult > 0)
|
||||
{
|
||||
one_result_list.at(i).img_result_list.at(j).qx_name = "NG";
|
||||
if (one_result_list.at(i).result == 0)
|
||||
{
|
||||
one_result_list.at(i).result = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
one_result_list.at(i).img_result_list.at(j).qx_name = "ER";
|
||||
one_result_list.at(i).result = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void update_qx(std::string qx_name, int num)
|
||||
{
|
||||
for (int i = 0; i < qx_result_list.size(); i++)
|
||||
{
|
||||
if (qx_result_list.at(i).qx_name == qx_name)
|
||||
{
|
||||
qx_result_list.at(i).num += num;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Det_File_qx_Info tem;
|
||||
tem.qx_name = qx_name;
|
||||
tem.num = num;
|
||||
qx_result_list.push_back(tem);
|
||||
}
|
||||
void print(bool show = true)
|
||||
{
|
||||
|
||||
strlist.erase(strlist.begin(), strlist.end());
|
||||
strlist.clear();
|
||||
det_num_ok = 0;
|
||||
det_num_ng = 0;
|
||||
det_num_error = 0;
|
||||
std::string str = "";
|
||||
str = "*****************************************************************************";
|
||||
strlist.push_back(str);
|
||||
|
||||
str = "*****************************detect result***********************************";
|
||||
strlist.push_back(str);
|
||||
|
||||
float fok = 0;
|
||||
float fng = 0;
|
||||
float ferror = 0;
|
||||
// printf("one_result_list.size() %d \n", one_result_list.size());
|
||||
for (int i = 0; i < one_result_list.size(); i++)
|
||||
{
|
||||
if (one_result_list.at(i).result == 0)
|
||||
{
|
||||
det_num_ok++;
|
||||
}
|
||||
else if (one_result_list.at(i).result > 0)
|
||||
{
|
||||
det_num_ng++;
|
||||
}
|
||||
else
|
||||
{
|
||||
det_num_error++;
|
||||
}
|
||||
}
|
||||
if (det_num_all > 0)
|
||||
{
|
||||
fok = det_num_ok * 1.0f / det_num_all * 100;
|
||||
fng = det_num_ng * 1.0f / det_num_all * 100;
|
||||
ferror = det_num_error * 1.0f / det_num_all * 100;
|
||||
}
|
||||
char buffer[64];
|
||||
sprintf(buffer, "ALL:%d OK:%d %.1f%% NG:%d %.1f%% Error:%d %.1f%%", det_num_all, det_num_ok, fok, det_num_ng, fng, det_num_error, ferror);
|
||||
std::string st1 = buffer;
|
||||
strlist.push_back(st1);
|
||||
sprintf(buffer, "Use time %f s mean time %f s", sumtime_S, mean_time);
|
||||
std::string st2 = buffer;
|
||||
|
||||
strlist.push_back(st2);
|
||||
// printf("%s\n", st1.c_str());
|
||||
// printf("------------------------------------------------------------------------------\n");
|
||||
str = "------------------------------------------------------------------------------";
|
||||
strlist.push_back(str);
|
||||
|
||||
{
|
||||
int qx_all_num = 0;
|
||||
for (size_t i = 0; i < qx_result_list.size(); i++)
|
||||
{
|
||||
qx_all_num += qx_result_list.at(i).num;
|
||||
}
|
||||
for (size_t i = 0; i < qx_result_list.size(); i++)
|
||||
{
|
||||
float fr = qx_result_list.at(i).num * 1.0 / qx_all_num * 100;
|
||||
std::string str_qx = "";
|
||||
// printf("len %d \n", qx_result_list.at(i).qx_name.length());
|
||||
for (int k = 0; k < (20 - qx_result_list.at(i).qx_name.length()); k++)
|
||||
{
|
||||
str_qx += " ";
|
||||
}
|
||||
str_qx += qx_result_list.at(i).qx_name;
|
||||
char buffer123[64];
|
||||
sprintf(buffer123, ":%d %.1f%% ", qx_result_list.at(i).num, fr);
|
||||
std::string st1 = buffer123;
|
||||
str_qx += st1;
|
||||
int nlen = fr;
|
||||
|
||||
for (int j = 0; j < nlen; j++)
|
||||
{
|
||||
str_qx += "|";
|
||||
}
|
||||
strlist.push_back(str_qx);
|
||||
}
|
||||
}
|
||||
|
||||
str = "------------------------------------------------------------------------------";
|
||||
strlist.push_back(str);
|
||||
|
||||
for (int i = 0; i < one_result_list.size(); i++)
|
||||
{
|
||||
st1 = one_result_list.at(i).print();
|
||||
strlist.push_back(st1);
|
||||
}
|
||||
str = "*****************************************************************************";
|
||||
strlist.push_back(str);
|
||||
// printf("*****************************************************************************\n");
|
||||
if (show)
|
||||
{
|
||||
for (size_t i = 0; i < strlist.size(); i++)
|
||||
{
|
||||
printf("%s\n", strlist.at(i).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
struct IMG_BASE_INFO_
|
||||
{
|
||||
std::string strPath;
|
||||
std::string strChannel;
|
||||
std::string strImgSN;
|
||||
IMG_BASE_INFO_()
|
||||
{
|
||||
strPath = "";
|
||||
strImgSN = "";
|
||||
strChannel = "";
|
||||
}
|
||||
};
|
||||
struct ReadImgInfo
|
||||
{
|
||||
std::string strPath;
|
||||
std::string strChannel;
|
||||
int stype;
|
||||
int status;
|
||||
std::string strImgSN;
|
||||
int idx;
|
||||
int sumNUm;
|
||||
cv::Rect cutRoi;
|
||||
std::vector<IMG_BASE_INFO_> imglist;
|
||||
ReadImgInfo()
|
||||
{
|
||||
strPath = "";
|
||||
strImgSN = "";
|
||||
stype = 0;
|
||||
status = 0;
|
||||
idx = 0;
|
||||
imglist.clear();
|
||||
cutRoi = cv::Rect(0, 0, 0, 0);
|
||||
sumNUm = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct AI_Det_Path
|
||||
{
|
||||
std::string strPath_CutImg;
|
||||
std::string strPath_AIMask;
|
||||
/* data */
|
||||
};
|
||||
struct AI_Det_Channel_
|
||||
{
|
||||
std::string strChannel;
|
||||
AI_Det_Path path;
|
||||
/* data */
|
||||
};
|
||||
struct Json_Det_Path
|
||||
{
|
||||
std::string strPath_CutImg;
|
||||
std::string strPath_Json;
|
||||
/* data */
|
||||
};
|
||||
struct READ_IMG_INFO
|
||||
{
|
||||
std::string strpath= "";
|
||||
std::string strproduct = "";
|
||||
};
|
||||
class deal
|
||||
{
|
||||
public:
|
||||
// 构造函数
|
||||
deal();
|
||||
~deal();
|
||||
int start();
|
||||
|
||||
private:
|
||||
// 检测参数
|
||||
int LoadCheckImgConfig();
|
||||
|
||||
// 初始化检测分析线程类
|
||||
int InitCheckAnalysisy();
|
||||
int InitConfig();
|
||||
// 初始化 检查存图路径
|
||||
int InitSaveImgPath();
|
||||
|
||||
int LoadCheckConfig();
|
||||
// 分析参数
|
||||
int LoadAnalysisConfig();
|
||||
// 开启线程
|
||||
int StartThread(THREAD_RUN_TYPE type);
|
||||
// 停止线程
|
||||
int StopThread();
|
||||
|
||||
int preCheck();
|
||||
std::string readTestImg();
|
||||
int readTestImg(READ_IMG_INFO& read);
|
||||
// 重复检测
|
||||
int repeatCheck();
|
||||
int saveImg(std::string strpath, std::shared_ptr<CheckResult> result);
|
||||
int writeLog(std::string strSavePath, std::vector<std::string> logList);
|
||||
int WriteJsonString(std::string strSavePath, std::string strjson);
|
||||
|
||||
int DelImg_Cell_ET();
|
||||
int Det_OneProduct_Cell_ET(std::shared_ptr<Product_File_Info> product, int Idx);
|
||||
|
||||
// 获取图片路径
|
||||
int GetDetImageInfo(std::string strProductID, std::string strSearchImg, std::vector<JC_IMAGE_INFO_> &jcImageInfoList);
|
||||
// 解析图片的信息 -- cell et
|
||||
int GetImgInfo_POL_ET(std::string strImgPath, JC_IMAGE_INFO_ *pImageInfo);
|
||||
|
||||
int GetImgInfo_POL_ET_PNG(std::string strImgPath, JC_IMAGE_INFO_ *pImageInfo);
|
||||
|
||||
int Det_Edge_Test_OneImg();
|
||||
|
||||
// 功能测试
|
||||
int Det_Funtion_Test();
|
||||
// 边缘测试
|
||||
int Det_Funtion_Edge();
|
||||
|
||||
// 测试mark线
|
||||
int Det_Funtion_MarkLine();
|
||||
|
||||
int LoadSingleImgList(std::string strSearchPath, std::string strChannle, std::vector<std::string> &imgList);
|
||||
|
||||
// 随机绘制错误
|
||||
int RandDrawImg(cv::Mat srcimg, cv::Mat &randErrorImg);
|
||||
|
||||
int LoadOfflineCheckImg(std::string strImgPath);
|
||||
int LoadImgPath_JCSN(std::string strImgPath);
|
||||
bool isValidString(const std::string &str);
|
||||
|
||||
int LoadProductID(std::string strImgPath);
|
||||
|
||||
int set_cpu_id(const std::vector<int> &cpu_set_vec);
|
||||
void GetDealResultToQueu();
|
||||
// 加载系统配置文件
|
||||
bool ReadSystemConfig(const std::string &strPath);
|
||||
int GetJcImageInfo(std::string strpath, std::vector<JC_IMAGE_INFO_> &jcImageInfoList);
|
||||
|
||||
int ReadTestImgaData();
|
||||
// 处理前,初始化部分数据
|
||||
int InitDetData();
|
||||
// 检测结果 插入结果队列
|
||||
int InsertDetResult(ReadImgInfo tem);
|
||||
int GetUpMaskImg(cv::Mat inImg, cv::Rect roi, cv::Mat &maskimg);
|
||||
|
||||
// 送图去检测
|
||||
int SendImgToCheck(std::shared_ptr<JC_IMAGE_INFO_> pDetImageInfo, IN_IMG_Status_ status);
|
||||
|
||||
private:
|
||||
// 处理调度线程
|
||||
std::shared_ptr<std::thread> ptr_DealImgthread;
|
||||
|
||||
void DealImg();
|
||||
|
||||
std::vector<std::string> extractAllDirectories(const std::string &path);
|
||||
|
||||
// 结果处理线程
|
||||
// std::shared_ptr<std::thread> ptr_Resultthread;
|
||||
std::vector<std::shared_ptr<std::thread>> ptr_ResultthreadList;
|
||||
void ResultThread(int id);
|
||||
|
||||
// 结果拷贝线程
|
||||
std::shared_ptr<std::thread> ptr_GetResultthread;
|
||||
|
||||
void GetResultThread();
|
||||
|
||||
std::vector<std::shared_ptr<std::thread>> threadArray;
|
||||
|
||||
void ReadImgThread(int id);
|
||||
|
||||
void testimg(cv::Mat img);
|
||||
|
||||
int updataResltInfo(std::shared_ptr<CheckResult> result);
|
||||
|
||||
void slidingWindowAutoThreshold(const cv::Mat &src, cv::Mat &dst, int windowSize, int step, double C);
|
||||
|
||||
int testimgUP(cv::Mat img);
|
||||
int test_ZF(ReadImgInfo tem, int id);
|
||||
int SetStatus(int type, int status);
|
||||
int GetStatus(int type);
|
||||
bool IsStatus(int type, int status);
|
||||
|
||||
int SetStatus_List(int idx, Thread_Status_ status);
|
||||
int GetStatus_List(int idx);
|
||||
bool IsStatus_List(int idx, Thread_Status_ status);
|
||||
int setReadThreadStart();
|
||||
int GetReadImgCompleteThreadIdx(); // 获取读取完成后的idx
|
||||
bool IsALLComplete();
|
||||
int InitCPUIDX();
|
||||
|
||||
// 线程读图
|
||||
void Thread_ReadImg(int id);
|
||||
|
||||
int InsertReadImgInfo(std::shared_ptr<JC_IMAGE_INFO_> pImageInfo);
|
||||
int GetReadImgInfo(std::shared_ptr<JC_IMAGE_INFO_> &pImageInfo);
|
||||
|
||||
public:
|
||||
std::vector<cv::Mat> m_OffLineCheckImgList; // 离线检测图片列表
|
||||
std::vector<std::string> m_OffLineCheckImgNameList; // 离线检测图片列表
|
||||
std::vector<std::string> m_OffImageSNPathList; // 离线检测图片列表
|
||||
// std::vector<std::string> m_product_ID_List; // 离线检测图片列表
|
||||
|
||||
vector<std::shared_ptr<Product_File_Info>> m_product_Camera_List; // 产品相机列表
|
||||
|
||||
ALLImgCheckBase *m_pALLImgCheckAnalysisy;
|
||||
// ALLImgCheckBase *m_pResultJsonCheckAnalysisy;
|
||||
// ImgCheckAnalysisy m_ImgCheckAnalysisy[IMGCHECKANALYSISY_NUM];
|
||||
|
||||
std::vector<std::string> m_TestJC_ImageDate; // 离线检测图片列表
|
||||
std::string m_strCurDate;
|
||||
int m_nSystemCheckType;
|
||||
bool m_bExit;
|
||||
int nLastCheckAnalysisyThreadIdx;
|
||||
|
||||
RunInfoST m_RunConfig; // 检测基本参数
|
||||
|
||||
ImgBasicDeal m_imgBasicDeal;
|
||||
|
||||
std::mutex mutex_Result_list;
|
||||
std::queue<std::shared_ptr<CheckResult>> m_Result_list;
|
||||
|
||||
// 检测区域list
|
||||
std::vector<cv::Point> m_DetRoiMaskPointList;
|
||||
// 检测区域list
|
||||
std::vector<cv::Point> m_CoreMaskPointList;
|
||||
|
||||
int m_nTestAI;
|
||||
int m_nRunType;
|
||||
int m_nTestNum;
|
||||
std::string m_strCheckFilePath;
|
||||
std::string m_strSaveImgPath;
|
||||
|
||||
ConfigBase *m_pConfig;
|
||||
ConfigBase *m_pConfig_Cam2;
|
||||
SystemConfigParam m_system_param;
|
||||
int m_nCurUseCPUIDX;
|
||||
int m_nCamIdx;
|
||||
ImageInfo m_ImgInfo_src;
|
||||
ImageInfo m_ImgInfo_result;
|
||||
|
||||
int m_nSaveDetprocessImg;
|
||||
cv::Rect m_CutRoi;
|
||||
|
||||
int nn;
|
||||
int nddd;
|
||||
int kkd;
|
||||
int maxidx;
|
||||
|
||||
Det_File_Result_Info m_DetResult;
|
||||
std::vector<JC_IMAGE_INFO_> m_ImageInfoList;
|
||||
|
||||
std::queue<std::shared_ptr<JC_IMAGE_INFO_>> m_ReadImg_queue; // 读图队列
|
||||
|
||||
std::mutex mutex_ReadImgList;
|
||||
std::condition_variable cv_ReadImgList;
|
||||
|
||||
int m_nReadStausList[READ_IMG_THREAD_NUM];
|
||||
// 读图线程状态
|
||||
std::shared_ptr<JC_IMAGE_INFO_> m_ReadImgThread_Result[READ_IMG_THREAD_NUM];
|
||||
|
||||
READ_THREAD_TYPE_ m_nReadThread_type;
|
||||
bool m_nreadImg_Stop;
|
||||
std::mutex mutex_DetResult_;
|
||||
|
||||
std::queue<ReadImgInfo> m_DetImgQueue; // 存储生产者生产的数据
|
||||
std::mutex mtx_DetImgQueue; // 互斥量,保护共享资源
|
||||
std::mutex mtx_DetImgQueue_edge; // 互斥量,保护共享资源
|
||||
std::condition_variable cv; // 条件变量,用于线程间通信
|
||||
|
||||
std::mutex mtx_DetImgQueue_com; //
|
||||
int m_read_ImgNum;
|
||||
long m_readImgStarttime;
|
||||
|
||||
int m_DetStatusList[Status_Type_Count]; // 各种需要线程同步的状态信息
|
||||
std::mutex mtx_List[Mutex_Type_Count]; // 互斥量
|
||||
std::vector<ReadImgInfo> m_DetResultList;
|
||||
|
||||
CPU_ID_INFO_ m_CPUInfo[THREAD_CPU_Count];
|
||||
|
||||
Check_Work_Type m_check_Work_Type; // 系统运行模式
|
||||
Image_ReadChannel m_image_ReadChannel;
|
||||
};
|
||||
|
||||
#endif //_CORELOGICFACTORY_HPP_
|
||||
@ -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
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* @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 AICheck_H_
|
||||
#define AICheck_H_
|
||||
|
||||
// #define USE_TERNSORRT10_BIGMODEL
|
||||
|
||||
#define CUDA_API_PER_THREAD_DEFAULT_STREAM 1
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#ifdef USE_TERNSORRT10_BIGMODEL
|
||||
|
||||
#include "NvInfer.h"
|
||||
#include "cuda_runtime_api.h"
|
||||
using namespace nvinfer1;
|
||||
#else
|
||||
#include "argsParser.h"
|
||||
#include "buffers.h"
|
||||
#include "common.h"
|
||||
#include "logger.h"
|
||||
#include "NvCaffeParser.h"
|
||||
#include "NvInfer.h"
|
||||
#include "cuda_runtime_api.h"
|
||||
#endif
|
||||
using namespace std;
|
||||
|
||||
#define MAX_AI_BUFFER_SIZE 5
|
||||
|
||||
enum AIBufferType_
|
||||
{
|
||||
AIBufferType_NULL, // default
|
||||
AIBufferType_IN, // 输入
|
||||
AIBufferType_OUT, // 输出
|
||||
};
|
||||
struct AIBuffer
|
||||
{
|
||||
int ntype; // 数据类型 AIBufferType_
|
||||
int ndatalength; // 数据长度
|
||||
int ndataSize; // 数据字节大小 ndatalength*sizeof(float)
|
||||
int nuchardataSize; // 数据字节大小 ndatalength*sizeof(char)
|
||||
std::string strName; // 名称
|
||||
AIBuffer()
|
||||
{
|
||||
ntype = AIBufferType_NULL;
|
||||
ndatalength = 0;
|
||||
ndataSize = 0;
|
||||
nuchardataSize = 0;
|
||||
strName = "";
|
||||
}
|
||||
void copy(AIBuffer tem)
|
||||
{
|
||||
this->ntype = tem.ntype;
|
||||
this->ndatalength = tem.ndatalength;
|
||||
this->ndataSize = tem.ndataSize;
|
||||
this->nuchardataSize = tem.nuchardataSize;
|
||||
this->strName = tem.strName;
|
||||
}
|
||||
void print(std::string str = "")
|
||||
{
|
||||
printf("ntype %d strName %s ndatalength %d ndataSize %d nuchardataSize %d\n", ntype, strName.c_str(), ndatalength, ndataSize, nuchardataSize);
|
||||
}
|
||||
};
|
||||
|
||||
struct AIInitConfig
|
||||
{
|
||||
int nGpuIdx;
|
||||
AIBuffer bufferList[MAX_AI_BUFFER_SIZE];
|
||||
std::string engine_file_path;
|
||||
AIInitConfig()
|
||||
{
|
||||
nGpuIdx = -1;
|
||||
engine_file_path = "";
|
||||
}
|
||||
void copy(AIInitConfig tem)
|
||||
{
|
||||
this->nGpuIdx = tem.nGpuIdx;
|
||||
this->engine_file_path = tem.engine_file_path;
|
||||
for (int i = 0; i < MAX_AI_BUFFER_SIZE; i++)
|
||||
{
|
||||
this->bufferList[i].copy(tem.bufferList[i]);
|
||||
}
|
||||
}
|
||||
bool Checking()
|
||||
{
|
||||
if (nGpuIdx < 0 || nGpuIdx > 4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (engine_file_path.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 第一个不是 输入
|
||||
if (bufferList[0].ntype != AIBufferType_IN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 第二个是 空
|
||||
if (bufferList[1].ntype == AIBufferType_NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bhaveout = false;
|
||||
int npretype = AIBufferType_IN;
|
||||
for (int i = 1; i < MAX_AI_BUFFER_SIZE; i++)
|
||||
{
|
||||
// 前序是in
|
||||
if (npretype == AIBufferType_IN)
|
||||
{
|
||||
if (bufferList[i].ntype == AIBufferType_IN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (bufferList[i].ntype == AIBufferType_OUT)
|
||||
{
|
||||
npretype = AIBufferType_OUT;
|
||||
bhaveout = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (npretype == AIBufferType_OUT)
|
||||
{
|
||||
if (bufferList[i].ntype == AIBufferType_IN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (bufferList[i].ntype == AIBufferType_OUT)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
npretype = AIBufferType_NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bufferList[i].ntype == AIBufferType_IN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (bufferList[i].ntype == AIBufferType_OUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
npretype = AIBufferType_NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bhaveout)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void CalSize(int mulSzie)
|
||||
{
|
||||
for (int i = 0; i < MAX_AI_BUFFER_SIZE; i++)
|
||||
{
|
||||
if (bufferList[i].ntype == AIBufferType_NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bufferList[i].ndataSize = bufferList[i].ndatalength * mulSzie;
|
||||
bufferList[i].nuchardataSize = bufferList[i].ndatalength * sizeof(unsigned char);
|
||||
}
|
||||
}
|
||||
};
|
||||
class AI_defect
|
||||
{
|
||||
public:
|
||||
AI_defect();
|
||||
~AI_defect();
|
||||
int model_init(AIInitConfig config);
|
||||
|
||||
int model_Cuda_AI_In_1_Out_1(unsigned char *p_indata_0, unsigned char *p_outdata_1);
|
||||
int model_Cuda_AI_In_1_Out_1_float(unsigned char *p_indata_0, float *p_outdata_1);
|
||||
|
||||
private:
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
IRuntime *runtime;
|
||||
ICudaEngine *engine;
|
||||
IExecutionContext *context;
|
||||
void *buffers[MAX_AI_BUFFER_SIZE];
|
||||
void *ImgData[MAX_AI_BUFFER_SIZE]; // uchar
|
||||
const int BATCH_SIZE = 1;
|
||||
|
||||
bool m_bInitialized;
|
||||
|
||||
std::mutex g_mutex;
|
||||
AIInitConfig m_config;
|
||||
float* floatData[MAX_AI_BUFFER_SIZE];
|
||||
|
||||
int kk = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,66 @@
|
||||
/*
|
||||
//图片基本处理
|
||||
*/
|
||||
#ifndef AIClassify_H_
|
||||
#define AIClassify_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
using namespace std;
|
||||
|
||||
struct AI_PIECE_INFO
|
||||
{
|
||||
int num;
|
||||
int len;
|
||||
int abs_L;
|
||||
int long_num;
|
||||
int short_num;
|
||||
AI_PIECE_INFO()
|
||||
{
|
||||
num = 0;
|
||||
len = 0;
|
||||
abs_L = 0;
|
||||
long_num = 0;
|
||||
short_num = 0;
|
||||
}
|
||||
void print(std::string str)
|
||||
{
|
||||
printf("%s>> num %d len %d abs_L %d long_num %d short_num %d\n", str.c_str(), num, len, abs_L, long_num, short_num);
|
||||
}
|
||||
};
|
||||
struct AI_Classify_Info
|
||||
{
|
||||
int num; // 数量
|
||||
float score; // 得分
|
||||
float avgScore; // 平均得分
|
||||
AI_Classify_Info()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
num = 0;
|
||||
score = 0;
|
||||
avgScore = 0;
|
||||
}
|
||||
void print(std::string str)
|
||||
{
|
||||
printf("%s==== num %d score %f avgScore %f\n", str.c_str(), num, score, avgScore);
|
||||
}
|
||||
};
|
||||
|
||||
class AIClassify
|
||||
{
|
||||
|
||||
public:
|
||||
AIClassify();
|
||||
~AIClassify();
|
||||
// 分类
|
||||
int GetDetRoiList(const cv::Mat &src_Img, cv::Rect qx_roi, std::vector<cv::Rect> &samllRoiList);
|
||||
|
||||
private:
|
||||
cv::Rect GetCutRoi(cv::Rect roi, const cv::Mat &img);
|
||||
// 获取检测roi list
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,231 @@
|
||||
/*
|
||||
* @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 AICommonDefine_H_
|
||||
#define AICommonDefine_H_
|
||||
|
||||
// nf 输入图片尺寸
|
||||
#define AI_NF_IN_0_IMAGE_WIDTH 1024
|
||||
#define AI_NF_IN_0_IMAGE_HEIGHT 1024
|
||||
#define AI_NF_IN_0_IMAGE_CHANNEL 1
|
||||
#define AI_NF_IN_0_DATA_LENGTH AI_NF_IN_0_IMAGE_WIDTH *AI_NF_IN_0_IMAGE_HEIGHT *AI_NF_IN_0_IMAGE_CHANNEL
|
||||
#define AI_NF_IN_0_IMAGE_Name "0"
|
||||
// nf 输入图片尺寸
|
||||
#define AI_NF_out_0_IMAGE_WIDTH 512
|
||||
#define AI_NF_out_0_IMAGE_HEIGHT 512
|
||||
#define AI_NF_out_0_IMAGE_CHANNEL 1
|
||||
#define AI_NF_out_0_DATA_LENGTH AI_NF_out_0_IMAGE_WIDTH *AI_NF_out_0_IMAGE_HEIGHT *AI_NF_out_0_IMAGE_CHANNEL
|
||||
#define AI_NF_out_0_IMAGE_Name "491"
|
||||
// nf 输入图片尺寸
|
||||
#define AI_NF_out_1_IMAGE_WIDTH 512
|
||||
#define AI_NF_out_1_IMAGE_HEIGHT 512
|
||||
#define AI_NF_out_1_IMAGE_CHANNEL 1
|
||||
#define AI_NF_out_1_DATA_LENGTH AI_NF_out_1_IMAGE_WIDTH *AI_NF_out_1_IMAGE_HEIGHT *AI_NF_out_1_IMAGE_CHANNEL
|
||||
|
||||
// YS 输入图片尺寸
|
||||
#define AI_YX_IN_0_IMAGE_WIDTH 1024
|
||||
#define AI_YX_IN_0_IMAGE_HEIGHT 640
|
||||
#define AI_YX_IN_0_IMAGE_CHANNEL 1
|
||||
#define AI_YX_IN_0_DATA_LENGTH AI_YX_IN_0_IMAGE_WIDTH *AI_YX_IN_0_IMAGE_HEIGHT *AI_YX_IN_0_IMAGE_CHANNEL
|
||||
#define AI_YX_IN_0_IMAGE_Name "0"
|
||||
// nf 输入图片尺寸
|
||||
#define AI_YX_out_0_IMAGE_WIDTH 1024
|
||||
#define AI_YX_out_0_IMAGE_HEIGHT 640
|
||||
#define AI_YX_out_0_IMAGE_CHANNEL 1
|
||||
#define AI_YX_out_0_DATA_LENGTH AI_YX_out_0_IMAGE_WIDTH *AI_YX_out_0_IMAGE_HEIGHT *AI_YX_out_0_IMAGE_CHANNEL
|
||||
#define AI_YX_out_0_IMAGE_Name "480"
|
||||
#define USE_WHITEBACK_CLASS 1
|
||||
// 1023
|
||||
#define AI_Cls_IN_0_IMAGE_WIDTH 160
|
||||
#define AI_Cls_IN_0_IMAGE_HEIGHT 160
|
||||
#define AICls_IN_0_IMAGE_CHANNEL 3
|
||||
#define AI_Cls_IN_0_IMAGE_DATA_LENGTH AI_Cls_IN_0_IMAGE_WIDTH *AI_Cls_IN_0_IMAGE_HEIGHT *AICls_IN_0_IMAGE_CHANNEL
|
||||
#define AI_Cls_IN_0_IMAGE_Name "0"
|
||||
// #define AI_Cls_out_0_IMAGE_WIDTH 5 //5---9---20231118
|
||||
// #define AI_Cls_out_0_IMAGE_WIDTH 9 //5---9---20231118
|
||||
#define AI_Cls_out_0_IMAGE_WIDTH 16 // 9---10---20231126
|
||||
#define AI_Cls_out_0_IMAGE_HEIGHT 1
|
||||
#define AI_Cls_out_0_IMAGE_CHANNEL 1
|
||||
#define AI_Cls_out_0_IMAGE_DATA_LENGTH AI_Cls_out_0_IMAGE_WIDTH *AI_Cls_out_0_IMAGE_HEIGHT *AI_Cls_out_0_IMAGE_CHANNEL
|
||||
#define AI_Cls_out_0_IMAGE_Name "570"
|
||||
|
||||
#define AI_Cls_14_out_0_IMAGE_WIDTH 14 // 9---10---20231126
|
||||
#define AI_Cls_14_out_0_IMAGE_HEIGHT 1
|
||||
#define AI_Cls_14_out_0_IMAGE_CHANNEL 1
|
||||
#define AI_Cls_14_out_0_IMAGE_DATA_LENGTH AI_Cls_14_out_0_IMAGE_WIDTH *AI_Cls_14_out_0_IMAGE_HEIGHT *AI_Cls_14_out_0_IMAGE_CHANNEL
|
||||
#define AI_Cls_14_out_0_IMAGE_Name "570"
|
||||
// 1023
|
||||
|
||||
// YS 输入图片尺寸
|
||||
#define AI_ZF_IN_0_IMAGE_WIDTH 1280
|
||||
#define AI_ZF_IN_0_IMAGE_HEIGHT 800
|
||||
#define AI_ZF_IN_0_IMAGE_CHANNEL 1
|
||||
#define AI_ZF_IN_0_DATA_LENGTH AI_ZF_IN_0_IMAGE_WIDTH *AI_ZF_IN_0_IMAGE_HEIGHT *AI_ZF_IN_0_IMAGE_CHANNEL
|
||||
#define AI_ZF_IN_0_IMAGE_Name "0"
|
||||
// nf 输入ZF片尺寸
|
||||
#define AI_ZF_out_0_IMAGE_WIDTH 1280
|
||||
#define AI_ZF_out_0_IMAGE_HEIGHT 800
|
||||
#define AI_ZF_out_0_IMAGE_CHANNEL 1
|
||||
#define AI_ZF_out_0_DATA_LENGTH AI_ZF_out_0_IMAGE_WIDTH *AI_ZF_out_0_IMAGE_HEIGHT *AI_ZF_out_0_IMAGE_CHANNEL
|
||||
#define AI_ZF_out_0_IMAGE_Name "491"
|
||||
|
||||
#define str_AI_127Cell_Model_Path "/home/aidlux/BOE/UseModel/defect_L127.engine"
|
||||
// 127Cell 输入图片尺寸
|
||||
#define AI_127Cell_IN_0_IMAGE_WIDTH 1024
|
||||
#define AI_127Cell_IN_0_IMAGE_HEIGHT 1024
|
||||
#define AI_127Cell_IN_0_IMAGE_CHANNEL 1
|
||||
#define AI_127Cell_IN_0_DATA_LENGTH AI_127Cell_IN_0_IMAGE_WIDTH *AI_127Cell_IN_0_IMAGE_HEIGHT *AI_127Cell_IN_0_IMAGE_CHANNEL
|
||||
#define AI_127Cell_IN_0_IMAGE_Name "0"
|
||||
// nf 输入图片尺寸
|
||||
#define AI_127Cell_out_0_IMAGE_WIDTH 512
|
||||
#define AI_127Cell_out_0_IMAGE_HEIGHT 512
|
||||
#define AI_127Cell_out_0_IMAGE_CHANNEL 1
|
||||
#define AI_127Cell_out_0_DATA_LENGTH AI_127Cell_out_0_IMAGE_WIDTH *AI_127Cell_out_0_IMAGE_HEIGHT *AI_127Cell_out_0_IMAGE_CHANNEL
|
||||
#define AI_127Cell_out_0_IMAGE_Name "491"
|
||||
|
||||
#define str_AI_RE_POL_Model_Path "/home/aidlux/BOE/UseModel/BOE_POL_128x128.engine"
|
||||
#define str_AI_RE_AD_Model_Path "/home/aidlux/BOE/UseModel/BOE_AD_128x128.engine"
|
||||
// POL 二次计算面积 输入图片尺寸
|
||||
#define str_AI_RE_POL_IN_0_IMAGE_WIDTH 128
|
||||
#define str_AI_RE_POL_IN_0_IMAGE_HEIGHT 128
|
||||
#define str_AI_RE_POL_IN_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_RE_POL_IN_0_DATA_LENGTH str_AI_RE_POL_IN_0_IMAGE_WIDTH *str_AI_RE_POL_IN_0_IMAGE_HEIGHT *str_AI_RE_POL_IN_0_IMAGE_CHANNEL
|
||||
#define str_AI_RE_POL_IN_0_IMAGE_Name "0"
|
||||
// nf 输入图片尺寸
|
||||
#define str_AI_RE_POL_out_0_IMAGE_WIDTH 128
|
||||
#define str_AI_RE_POL_out_0_IMAGE_HEIGHT 128
|
||||
#define str_AI_RE_POL_out_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_RE_POL_out_0_DATA_LENGTH str_AI_RE_POL_out_0_IMAGE_WIDTH *str_AI_RE_POL_out_0_IMAGE_HEIGHT *str_AI_RE_POL_out_0_IMAGE_CHANNEL
|
||||
#define str_AI_RE_POL_out_0_IMAGE_Name "491"
|
||||
|
||||
// POL 二次计算面积 输入图片尺寸
|
||||
#define str_AI_RE_AD_IN_0_IMAGE_WIDTH 128
|
||||
#define str_AI_RE_AD_IN_0_IMAGE_HEIGHT 128
|
||||
#define str_AI_RE_AD_IN_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_RE_AD_IN_0_DATA_LENGTH str_AI_RE_AD_IN_0_IMAGE_WIDTH *str_AI_RE_AD_IN_0_IMAGE_HEIGHT *str_AI_RE_AD_IN_0_IMAGE_CHANNEL
|
||||
#define str_AI_RE_AD_IN_0_IMAGE_Name "0"
|
||||
// nf 输入图片尺寸
|
||||
#define str_AI_RE_AD_out_0_IMAGE_WIDTH 128
|
||||
#define str_AI_RE_AD_out_0_IMAGE_HEIGHT 128
|
||||
#define str_AI_RE_AD_out_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_RE_AD_out_0_DATA_LENGTH str_AI_RE_AD_out_0_IMAGE_WIDTH *str_AI_RE_AD_out_0_IMAGE_HEIGHT *str_AI_RE_AD_out_0_IMAGE_CHANNEL
|
||||
#define str_AI_RE_AD_out_0_IMAGE_Name "491"
|
||||
|
||||
// Edge 定位
|
||||
#define str_AI_EDGE_Big_Model_Path "/home/aidlux/BOE/UseModel/Edge_Big.engine"
|
||||
#define str_AI_EDGE_Small_Model_Path "/home/aidlux/BOE/UseModel/Edge_Small.engine"
|
||||
// POL 二次计算面积 输入图片尺寸
|
||||
#define str_AI_EDGE_Big_IN_0_IMAGE_WIDTH 1024
|
||||
#define str_AI_EDGE_Big_IN_0_IMAGE_HEIGHT 736
|
||||
#define str_AI_EDGE_Big_IN_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_EDGE_Big_IN_0_DATA_LENGTH str_AI_EDGE_Big_IN_0_IMAGE_WIDTH *str_AI_EDGE_Big_IN_0_IMAGE_HEIGHT *str_AI_EDGE_Big_IN_0_IMAGE_CHANNEL
|
||||
#define str_AI_EDGE_Big_IN_0_IMAGE_Name "image"
|
||||
// nf 输入图片尺寸
|
||||
#define str_AI_EDGE_Big_out_0_IMAGE_WIDTH 1024
|
||||
#define str_AI_EDGE_Big_out_0_IMAGE_HEIGHT 736
|
||||
#define str_AI_EDGE_Big_out_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_EDGE_Big_out_0_DATA_LENGTH str_AI_EDGE_Big_out_0_IMAGE_WIDTH *str_AI_EDGE_Big_out_0_IMAGE_HEIGHT *str_AI_EDGE_Big_out_0_IMAGE_CHANNEL
|
||||
#define str_AI_EDGE_Big_out_0_IMAGE_Name "mask"
|
||||
|
||||
// POL 二次计算面积 输入图片尺寸
|
||||
#define str_AI_EDGE_Small_IN_0_IMAGE_WIDTH 320
|
||||
#define str_AI_EDGE_Small_IN_0_IMAGE_HEIGHT 320
|
||||
#define str_AI_EDGE_Small_IN_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_EDGE_Small_IN_0_DATA_LENGTH str_AI_EDGE_Small_IN_0_IMAGE_WIDTH *str_AI_EDGE_Small_IN_0_IMAGE_HEIGHT *str_AI_EDGE_Small_IN_0_IMAGE_CHANNEL
|
||||
#define str_AI_EDGE_Small_IN_0_IMAGE_Name "image"
|
||||
// nf 输入图片尺寸
|
||||
#define str_AI_EDGE_Small_out_0_IMAGE_WIDTH 320
|
||||
#define str_AI_EDGE_Small_out_0_IMAGE_HEIGHT 320
|
||||
#define str_AI_EDGE_Small_out_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_EDGE_Small_out_0_DATA_LENGTH str_AI_EDGE_Small_out_0_IMAGE_WIDTH *str_AI_EDGE_Small_out_0_IMAGE_HEIGHT *str_AI_EDGE_Small_out_0_IMAGE_CHANNEL
|
||||
#define str_AI_EDGE_Small_out_0_IMAGE_Name "mask"
|
||||
|
||||
|
||||
|
||||
// 缺pol 检测
|
||||
#define str_AI_LOSSPOL_Model_Path "/home/aidlux/BOE/UseModel/BOE_LOSSPOL.engine"
|
||||
// 输入图片尺寸
|
||||
#define str_AI_LOSSPOL_IN_0_IMAGE_WIDTH 1024
|
||||
#define str_AI_LOSSPOL_IN_0_IMAGE_HEIGHT 640
|
||||
#define str_AI_LOSSPOL_IN_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_LOSSPOL_IN_0_DATA_LENGTH str_AI_LOSSPOL_IN_0_IMAGE_WIDTH *str_AI_LOSSPOL_IN_0_IMAGE_HEIGHT *str_AI_LOSSPOL_IN_0_IMAGE_CHANNEL
|
||||
|
||||
// nf 输入图片尺寸
|
||||
#define str_AI_LOSSPOL_out_0_IMAGE_WIDTH 1024
|
||||
#define str_AI_LOSSPOL_out_0_IMAGE_HEIGHT 640
|
||||
#define str_AI_LOSSPOL_out_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_LOSSPOL_out_0_DATA_LENGTH str_AI_LOSSPOL_out_0_IMAGE_WIDTH *str_AI_LOSSPOL_out_0_IMAGE_HEIGHT *str_AI_LOSSPOL_out_0_IMAGE_CHANNEL
|
||||
|
||||
|
||||
// Mark 检测
|
||||
#define str_AI_Mark_Model_Path "/home/aidlux/BOE/UseModel/defect_MARK_LINE.engine"
|
||||
// 输入图片尺寸
|
||||
#define str_AI_Mark_IN_0_IMAGE_WIDTH 512
|
||||
#define str_AI_Mark_IN_0_IMAGE_HEIGHT 512
|
||||
#define str_AI_Mark_IN_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_Mark_IN_0_DATA_LENGTH str_AI_Mark_IN_0_IMAGE_WIDTH *str_AI_Mark_IN_0_IMAGE_HEIGHT *str_AI_Mark_IN_0_IMAGE_CHANNEL
|
||||
|
||||
// nf 输入图片尺寸
|
||||
#define str_AI_Mark_out_0_IMAGE_WIDTH 512
|
||||
#define str_AI_Mark_out_0_IMAGE_HEIGHT 512
|
||||
#define str_AI_Mark_out_0_IMAGE_CHANNEL 1
|
||||
#define str_AI_Mark_out_0_DATA_LENGTH str_AI_Mark_out_0_IMAGE_WIDTH *str_AI_Mark_out_0_IMAGE_HEIGHT *str_AI_Mark_out_0_IMAGE_CHANNEL
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define QX_SAMLLIMG_WIDTH 160
|
||||
#define QX_SAMLLIMG_HEIGHT 160
|
||||
|
||||
// AI缺陷分类缺陷的种类
|
||||
enum AI_CLass_QX_NAME_
|
||||
{
|
||||
|
||||
AI_CLass_QX_NAME_ok_yisi, // 疑似
|
||||
AI_CLass_QX_NAME_yixian, // 异显
|
||||
AI_CLass_QX_NAME_POL_CEL, // 亮点
|
||||
AI_CLass_QX_NAME_zara, // ZARA
|
||||
AI_CLass_QX_NAME_ps, // PS
|
||||
AI_CLass_QX_NAME_line, // 线
|
||||
AI_CLass_QX_NAME_fangge_line, // 方格线
|
||||
AI_CLass_QX_NAME_qipao, // 气泡
|
||||
AI_CLass_QX_NAME_qing_huashang, // 轻划伤
|
||||
AI_CLass_QX_NAME_mtx, // MTX
|
||||
AI_CLass_QX_NAME_yisi_qianzangwu, // 疑似浅层脏污
|
||||
AI_CLass_QX_NAME_qing_zangwu, // 轻脏污
|
||||
AI_CLass_QX_NAME_zhong_zangwu, // 严重脏污
|
||||
AI_CLass_QX_NAME_andian, // 暗点
|
||||
AI_CLass_QX_NAME_huashang, // 划伤
|
||||
AI_CLass_QX_NAME_zf, // zf
|
||||
AI_CLass_QX_NAME_other, // 其他
|
||||
AI_CLass_QX_NAME_count,
|
||||
};
|
||||
// 缺陷项对应在参数中的名称
|
||||
static const std::string AI_CLass_QX_NAME_Names[] =
|
||||
{
|
||||
"ok_yisi",
|
||||
"yixian",
|
||||
"liangdian",
|
||||
"zara",
|
||||
"ps",
|
||||
"line",
|
||||
"fangge_line",
|
||||
"qipao",
|
||||
"qing_huashang",
|
||||
"mtx",
|
||||
"yisi_qianzangwu",
|
||||
"qing_zangwu",
|
||||
"zhong_zangwu",
|
||||
"andian",
|
||||
"huashang",
|
||||
"zf",
|
||||
"other"};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* @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 AIIMGDeal_H_
|
||||
#define AIIMGDeal_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "SingleGPU.h"
|
||||
#include "AICommonDefine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AI_IMG_deal
|
||||
{
|
||||
public:
|
||||
AI_IMG_deal();
|
||||
~AI_IMG_deal();
|
||||
|
||||
int Init(int nGpuIdx);
|
||||
|
||||
private:
|
||||
int m_nGpuIdx;
|
||||
|
||||
private:
|
||||
// new Data
|
||||
int NewData();
|
||||
|
||||
// Delete Data
|
||||
int DelteData();
|
||||
|
||||
public:
|
||||
// 初始化
|
||||
int Init_BOE(AIInitConfig config);
|
||||
int Init_127Cell(AIInitConfig config);
|
||||
int Init_BOE_Type2(AIInitConfig config);
|
||||
int Init_BOE_UP(AIInitConfig config);
|
||||
int Init_BOE_Chess(AIInitConfig config);
|
||||
int Init_YX_1(AIInitConfig config);
|
||||
int Init_YX_2(AIInitConfig config);
|
||||
int Init_Cls(AIInitConfig config, int ntype); // 1023
|
||||
int Init_zf(AIInitConfig config); // 1023
|
||||
int Init_RE_POL(AIInitConfig config); // 1023
|
||||
int Init_RE_AD(AIInitConfig config); // 1023
|
||||
int Init_Edge_Big(AIInitConfig config); // 1023
|
||||
int Init_Edge_Small(AIInitConfig config); // 1023
|
||||
int Init_LackPol(AIInitConfig config);
|
||||
int Init_MarkLine(AIInitConfig config);
|
||||
|
||||
// 检测
|
||||
int AICheck_BOE(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_BOE_Type2(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_BOE_Chess(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_BOE_UP(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_YX_1(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_YX_2(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_Cls(cv::Mat inImg, int ntype, float *fmaxScore); // 1023
|
||||
int AICheck_zf(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_127Cell(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_RE_POL(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_RE_AD(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_Edge_Big(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_Edge_Small(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_LackPol(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
int AICheck_MarkLine(cv::Mat inImg, cv::Mat &outImg_1);
|
||||
|
||||
private:
|
||||
cv::Mat F2M(float *data, int clannel, int w, int h);
|
||||
|
||||
cv::Mat InitMat(int channel, int w, int h);
|
||||
int F2softmaxId(float *data, int class_num, float *fmaxScore); // 1024dyy-add
|
||||
private:
|
||||
AI_SingleGPU *m_pAI_SingleGPU;
|
||||
|
||||
float *AI_DATA_Cls_OUT_0;
|
||||
float *AI_DATA_Cls_L0_OUT_0;
|
||||
|
||||
bool bInitSucc_127Cell;
|
||||
bool bInitSucc_re_Pol;
|
||||
bool bInitSucc_re_AD;
|
||||
bool bInitSucc_MarkLine;
|
||||
|
||||
bool bInitSucc_Edge_big;
|
||||
bool bInitSucc_Edge_Samll;
|
||||
bool bInitSucc_LackPol;
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,178 @@
|
||||
/*
|
||||
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
||||
*/
|
||||
#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"
|
||||
using namespace std;
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// 边缘搜索定位结果
|
||||
struct Edge_AI_Result
|
||||
{
|
||||
int nresult;
|
||||
cv::Mat mask;
|
||||
cv::Rect roi;
|
||||
cv::Mat DetMask_src; // 原图上产品区域
|
||||
|
||||
Edge_AI_Result()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
nresult = 0;
|
||||
roi = cv::Rect(0, 0, 0, 0);
|
||||
if (!mask.empty())
|
||||
{
|
||||
mask.release();
|
||||
}
|
||||
if (!DetMask_src.empty())
|
||||
{
|
||||
DetMask_src.release();
|
||||
}
|
||||
}
|
||||
};
|
||||
class AI_Edge_Algin
|
||||
{
|
||||
public:
|
||||
enum SaveProcessType
|
||||
{
|
||||
Save_Close, // 不保存
|
||||
Save_Filter, // 过滤的
|
||||
Save_ALL, // 全部
|
||||
};
|
||||
|
||||
/// @brief 检测过程的参数
|
||||
struct DetConfig
|
||||
{
|
||||
int ncamId; // 相机ID
|
||||
std::string strCamName; // 相机ID
|
||||
int nthresholdvalue; // 背景阈值
|
||||
int nAIErodesize; // 边缘腐蚀强度
|
||||
bool bSaveResultImg; // 保存结果图片
|
||||
SaveProcessType saveProcessImg; // 保存过程图片
|
||||
bool bUseDrawRoi_Check; // 是否用绘制的ROI进行校验
|
||||
cv::Rect drawRoi; // 绘制的 ROi;
|
||||
cv::Mat drawMask; // 绘制的maksk
|
||||
DetConfig()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
ncamId = 0;
|
||||
strCamName = "";
|
||||
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(/* args */);
|
||||
~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);
|
||||
|
||||
private:
|
||||
int InitModel_Big();
|
||||
int InitModel_Small();
|
||||
int Det_big(const cv::Mat &img, vector<Rect> &smallRoiList, cv::Rect &bigRoi, cv::Mat &big_mask);
|
||||
|
||||
private:
|
||||
bool m_bInitSucc; // 是否初始化成功
|
||||
|
||||
// 检测结果
|
||||
// std::shared_ptr<Edge_AI_Result> m_pCheckResult_Aling;
|
||||
|
||||
OtherDet_Config *m_pOtherDet_Config;
|
||||
DetConfig *m_pDetConfig;
|
||||
|
||||
AI_IMG_deal *m_pAIDeal;
|
||||
bool m_bInitialized;
|
||||
bool m_bModelSucc;
|
||||
|
||||
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,79 @@
|
||||
/*
|
||||
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
||||
*/
|
||||
#ifndef AI_Mark_Det_H_
|
||||
#define AI_Mark_Det_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "CheckUtil.hpp"
|
||||
#include "OtherDetect.h"
|
||||
#include "OtherDetBaseDefine.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "CheckConfigDefine.h"
|
||||
#include "ImageStorage.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// 二次分割求面积
|
||||
class AI_Mark_Det : public AIDetectBase
|
||||
{
|
||||
public:
|
||||
// 检测参数和结果
|
||||
struct DetConfigResult
|
||||
{
|
||||
|
||||
int ncamID;
|
||||
int nresult;
|
||||
cv::Rect searchroi;
|
||||
std::string strChannel;
|
||||
bool bsaveprocessimg;
|
||||
|
||||
cv::Rect markRoi;
|
||||
|
||||
DetConfigResult()
|
||||
{
|
||||
|
||||
nresult = -1;
|
||||
ncamID = 0;
|
||||
strChannel = "";
|
||||
searchroi = cv::Rect(0, 0, 0, 0);
|
||||
bsaveprocessimg = false;
|
||||
markRoi = cv::Rect(0, 0, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
AI_Mark_Det(/* args */);
|
||||
~AI_Mark_Det();
|
||||
int InitModel_ALL();
|
||||
int Detect(const cv::Mat &img, DetConfigResult *pDetConfig);
|
||||
|
||||
private:
|
||||
int InitModel();
|
||||
|
||||
cv::Rect GetCutRoi(cv::Rect &roi, const cv::Mat &img);
|
||||
|
||||
int Det_img(const cv::Mat &img, DetConfigResult *pDetConfig);
|
||||
|
||||
// 分析结果
|
||||
int Analysisy(const cv::Mat &maskImg, DetConfigResult *pDetConfig);
|
||||
|
||||
// 存储过程图片
|
||||
int SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, const cv::Mat &oldmask, DetConfigResult *pDetConfig);
|
||||
|
||||
private:
|
||||
bool m_bModelSucc;
|
||||
cv::Mat detimg123;
|
||||
ImageStorage *m_pImageStorage;
|
||||
|
||||
int m_Show_Area;
|
||||
float m_Show_Len;
|
||||
cv::Point m_Len_P1;
|
||||
cv::Point m_Len_P2;
|
||||
|
||||
private:
|
||||
/* data */
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,100 @@
|
||||
/*
|
||||
//实现对部分缺陷 需要进行 数量 和距离上分析的
|
||||
*/
|
||||
#ifndef AI_Second_Det_H_
|
||||
#define AI_Second_Det_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "CheckUtil.hpp"
|
||||
#include "OtherDetect.h"
|
||||
#include "OtherDetBaseDefine.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "CheckConfigDefine.h"
|
||||
#include "ImageStorage.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// 二次分割求面积
|
||||
class AI_SecondDet : public AIDetectBase
|
||||
{
|
||||
public:
|
||||
// 检测参数和结果
|
||||
struct DetConfigResult
|
||||
{
|
||||
Function_SecondDet *pfunction_secondDet;
|
||||
float fImgage_Scale_X;
|
||||
float fImgage_Scale_Y;
|
||||
float min_DetArea;
|
||||
cv::Rect qx_roi;
|
||||
int qx_type;
|
||||
std::string qx_name;
|
||||
int old_Area;
|
||||
float old_len;
|
||||
int new_Area;
|
||||
float new_len;
|
||||
int nresult;
|
||||
std::string strChannel;
|
||||
|
||||
DetConfigResult()
|
||||
{
|
||||
qx_roi = cv::Rect(0, 0, 0, 0);
|
||||
qx_type = 0;
|
||||
min_DetArea = 0;
|
||||
qx_name = "";
|
||||
old_Area = 0;
|
||||
old_len = 0;
|
||||
new_Area = 0;
|
||||
new_len = 0;
|
||||
nresult = 0;
|
||||
pfunction_secondDet = NULL;
|
||||
strChannel = "";
|
||||
fImgage_Scale_X = 0.0333;
|
||||
fImgage_Scale_Y = 0.0333;
|
||||
}
|
||||
void SetAreaAndLen(int oldArea, float oldLen)
|
||||
{
|
||||
old_Area = oldArea;
|
||||
old_len = oldLen;
|
||||
new_Area = old_Area;
|
||||
new_len = old_len;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
AI_SecondDet(/* args */);
|
||||
~AI_SecondDet();
|
||||
int InitModel_ALL();
|
||||
int Detect(const cv::Mat &img, const cv::Mat &mask, DetConfigResult *pDetConfig);
|
||||
|
||||
private:
|
||||
int InitModel_Re_POL();
|
||||
int InitModel_Re_AD();
|
||||
|
||||
cv::Rect GetCutRoi(cv::Rect &roi, const cv::Mat &img);
|
||||
|
||||
int Det_Pol(const cv::Mat &img, DetConfigResult *pDetConfig);
|
||||
int Det_AD(const cv::Mat &img, DetConfigResult *pDetConfig);
|
||||
|
||||
// 分析结果
|
||||
int Analysisy(const cv::Mat &maskImg, DetConfigResult *pDetConfig);
|
||||
|
||||
// 存储过程图片
|
||||
int SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, const cv::Mat &oldmask, DetConfigResult *pDetConfig);
|
||||
|
||||
private:
|
||||
bool m_bModelSucc_AD;
|
||||
bool m_bModelSucc_POL;
|
||||
cv::Mat detimg123;
|
||||
ImageStorage *m_pImageStorage;
|
||||
|
||||
int m_Show_Area;
|
||||
float m_Show_Len;
|
||||
cv::Point m_Len_P1;
|
||||
cv::Point m_Len_P2;
|
||||
|
||||
private:
|
||||
/* data */
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* @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 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 wrap_test_print();
|
||||
void Cuda_ucharToFloat(const unsigned char* input, float* output, int size);
|
||||
void Cuda_FloatTouchar(const float* input, unsigned char* output, int size);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,154 @@
|
||||
/*
|
||||
* @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 CameraCheckAnalysisy_H_
|
||||
#define CameraCheckAnalysisy_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <condition_variable>
|
||||
#include "Define_Base.h"
|
||||
#include "AICheck.h"
|
||||
#include "ImgCheckBase.h"
|
||||
#include "ImageDetBase.h"
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "ConfigBase.h"
|
||||
#include "CheckSODefine.hpp"
|
||||
#include "CheckConfigDefine.h"
|
||||
#include "EdgeDet.h"
|
||||
#include "ImageDetConfig.h"
|
||||
#include "Define_Product.hpp"
|
||||
#include "AI_Mark_Det.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
// 相机处理类
|
||||
class CameraCheckAnalysisy
|
||||
{
|
||||
|
||||
public:
|
||||
CameraCheckAnalysisy();
|
||||
~CameraCheckAnalysisy();
|
||||
|
||||
// 相机处理类 初始化
|
||||
int Init(Camera_IDX camera_ID);
|
||||
int StartCheck(std::shared_ptr<Camera_Check_Result> pCamera_Check_Result);
|
||||
|
||||
private:
|
||||
// 开启线程
|
||||
int StartThread();
|
||||
// 停止线程
|
||||
int StopThread();
|
||||
|
||||
// 初始化检测分析线程类
|
||||
int InitCheckAnalysisy();
|
||||
// 初始化其他
|
||||
int InitRun();
|
||||
// 设置新的检测参数
|
||||
int SetNewConfig();
|
||||
|
||||
int InitMarkLine();
|
||||
|
||||
// 处理每张图片
|
||||
int CheckImgRun();
|
||||
|
||||
int Run(); // 运行;
|
||||
int set_cpu_id(const std::vector<int> &cpu_set_vec);
|
||||
// 等待处理图片
|
||||
int WaitDetImg();
|
||||
// 增加日志
|
||||
int AddStrToLog_New(std::string str);
|
||||
|
||||
// 预处理图片
|
||||
int Detect_Pre();
|
||||
|
||||
// 处理每张图片
|
||||
int Detect_Images();
|
||||
|
||||
// 边缘处理
|
||||
int ImgEdge(cv::Mat img, bool bUseDraw, const cv::Mat ¶MaskImg, int thresholdvalue, int AIErodesize, bool bUseAIDet, cv::Mat &detMaskImg, cv::Rect &roi, int productIdx);
|
||||
|
||||
// 插入相机日志
|
||||
int InsertCameraLog();
|
||||
|
||||
ChannelCheckFunction *GetChannelFuntion(std::string strChannelName); // 获得 通道的检测功能
|
||||
|
||||
// 特征主定位
|
||||
int Feature_Align(const cv::Mat &detSrcImg, int nproductIdx, cv::Rect Det_CropRoi, ChannelCheckFunction *pFuntion_L255, const cv::Mat &detImg_mask, bool bsave = false, bool bsaveprocessimg = false);
|
||||
// 预处理 字符检测
|
||||
int preDet_ZF(std::shared_ptr<ImageDetconfig> p, std::shared_ptr<ImageDetResult> &pResult);
|
||||
|
||||
// 检测MarkLine
|
||||
int Det_MarkLine(const cv::Mat &detSrcImg, cv::Rect Det_CropRoi, Base_Function_MarkLine *pFuntion, cv::Mat &detImg_mask, cv::Rect &markRoi_x, cv::Rect &markRoi_y, bool bsaveprocessimg = false);
|
||||
|
||||
// 获取 检测核心库
|
||||
ImgCheckBase *GetDealResult(int idx = -1);
|
||||
|
||||
int GetAndAnalysisyCheckResult(std::shared_ptr<ImageDetResult> &pResult);
|
||||
|
||||
public:
|
||||
// 运行的基本参数
|
||||
RunInfoST m_RunConfig;
|
||||
// 检测参数模块
|
||||
ConfigBase *m_pConfig;
|
||||
PRINT_LOG_ m_PrintLog;
|
||||
|
||||
AI_Edge_Algin::DetConfig AI_detConfig;
|
||||
Align_Result m_align_Result;
|
||||
// 图片特征定位
|
||||
Image_Feature_Algin m_Image_Feature_Algin;
|
||||
// 检测分析参数
|
||||
AnalysisyConfigST m_AnalysisyConfig;
|
||||
ALLChannelCheckFunction *m_pChannelFuntion; // 画面检测功能
|
||||
BaseCheckFunction *m_pbaseCheckFunction; // 基础检测
|
||||
|
||||
std::shared_ptr<ImageDetResult> m_OneImg_Result_shareP;
|
||||
std::shared_ptr<ImageDetconfig> DetImgInfo_shareP;
|
||||
std::string m_strCameraName;
|
||||
|
||||
private:
|
||||
// 相机ID
|
||||
Camera_IDX m_camera_ID;
|
||||
int m_ncamera_idx;
|
||||
|
||||
int m_nErrorCode; // 错误代码
|
||||
bool m_bInitSucc; // 初始化状态
|
||||
bool m_bExit; // 是否退出检测
|
||||
int nLastCheckAnalysisyThreadIdx;
|
||||
// 图片处理线程
|
||||
std::shared_ptr<std::thread> ptr_thread_Run;
|
||||
|
||||
// 单相机的相关结果信息
|
||||
std::shared_ptr<Camera_Check_Result> m_pCamera_Check_Result;
|
||||
|
||||
bool m_bHaveImgeDet; // 是否有图片需要检查
|
||||
std::mutex mtx_WaiteImg; // 等待图片的锁
|
||||
std::condition_variable cond_WaiteImg; // 条件变量,是否有图片需要检查
|
||||
|
||||
private:
|
||||
// 检测核心库
|
||||
ImgCheckBase *m_pImgCheckAnalysisy[IMGCHECKANALYSISY_NUM];
|
||||
|
||||
AI_IMG_deal m_AIDeal;
|
||||
OtherDet_Config m_OtherDet_Config;
|
||||
// 边缘检测
|
||||
EdgeDet_New m_DetEdge;
|
||||
|
||||
AI_Mark_Det m_MarkDet; // Mark检测
|
||||
|
||||
CHECK_TEM_RESULT m_TemCheck;
|
||||
|
||||
private:
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: sueRimn
|
||||
* @Date: 2022-04-28 10:41:42
|
||||
* @LastEditors: sueRimn
|
||||
* @LastEditTime: 2022-04-28 15:32:49
|
||||
*/
|
||||
/*
|
||||
* 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 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 CalRoi2RoiPre(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 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);
|
||||
};
|
||||
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,46 @@
|
||||
/*
|
||||
//定义整个系统基础的 定义 信息
|
||||
*/
|
||||
#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 4
|
||||
// 最大 GPU 个数
|
||||
#define MAX_GPU_NUM 2
|
||||
|
||||
// 单个产品有几个相机拍摄
|
||||
#define MAX_Camera_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,68 @@
|
||||
/*
|
||||
//图片基本处理
|
||||
*/
|
||||
#ifndef DrawImgl_H_
|
||||
#define DrawImg_H_
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include "ImgCheckConfig.h"
|
||||
#include "JsonCoversion.h"
|
||||
#include <stdio.h>
|
||||
#include "ImageDetConfig.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class DrawImg
|
||||
{
|
||||
public:
|
||||
enum Draw_Type
|
||||
{
|
||||
Draw_Type_YS,
|
||||
Draw_Type_NG,
|
||||
Draw_Type_Other,
|
||||
};
|
||||
|
||||
public:
|
||||
DrawImg();
|
||||
~DrawImg();
|
||||
|
||||
int DrawResult(std::shared_ptr<CheckResult> &result);
|
||||
int DrawInfoImg(cv::Mat &img, cv::Rect roi, int blobidx, int type, float fArea, float fenerge, float fmaxv, float fhj, float flen, Draw_Type drayType, std::string strqx_error, std::string strqx_code, int qx_type, int qx_num, float mindis, bool bqxroi = false);
|
||||
int DrawInfoImg_Src(cv::Mat &img, cv::Rect roi, int blobidx, int type, float fArea, float fenerge, float fmaxv, float fhj, float flen, Draw_Type drayType, std::string strqx_error, std::string strqx_code, int qx_type, int qx_num, float mindis, bool bqxroi = false);
|
||||
int preDealImg(cv::Mat &srcimg, cv::Mat &image_resize, bool bfilpSrcImg = true);
|
||||
int DrawPointList(cv::Mat &image_draw, std::vector<cv::Point> plist);
|
||||
|
||||
bool bdraw(cv::Rect roi);
|
||||
|
||||
public:
|
||||
int font_face = cv::FONT_HERSHEY_SIMPLEX;
|
||||
double font_scale = 0.5;
|
||||
int thickness = 1;
|
||||
bool m_bstatus_ReJson;
|
||||
|
||||
cv::Scalar Color_Brightness_roi = cv::Scalar(0, 255, 0);
|
||||
cv::Scalar Color_Brightness_text = cv::Scalar(0, 255, 0);
|
||||
cv::Scalar DrawBlobErrorCorleList[ERROR_TYPE_COUNT];
|
||||
|
||||
std::vector<cv::Rect> m_drawList;
|
||||
|
||||
private:
|
||||
};
|
||||
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,60 @@
|
||||
/*
|
||||
//图片基本处理
|
||||
*/
|
||||
#ifndef EdgeDet_H_
|
||||
#define EdgeDet_H_
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "AI_Edge_Algin.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum LINE_SEARCH_DIRECTION_CONST
|
||||
{
|
||||
DIRECTION_POSITIVE = 1,
|
||||
DIRECTION_NEGATIVE = -1,
|
||||
};
|
||||
class EdgeDet_New
|
||||
{
|
||||
|
||||
public:
|
||||
EdgeDet_New();
|
||||
~EdgeDet_New();
|
||||
int InitRun();
|
||||
int InitModel();
|
||||
int GetImgEdge(cv::Mat img, cv::Rect &roi);
|
||||
int AIEdgeDete(const cv::Mat &img, AI_Edge_Algin::DetConfig *pdetConfig, cv::Mat &detMaskImg, cv::Rect &roi);
|
||||
|
||||
cv::Mat showimg;
|
||||
bool bshowimg;
|
||||
AI_IMG_deal m_AIDeal;
|
||||
OtherDet_Config m_OtherDet_Config;
|
||||
// std::shared_ptr<AI_Edge_Algin> m_pAI_Edge_Algin; // 边缘定位
|
||||
AI_Edge_Algin m_pAI_Edge_Algin;
|
||||
|
||||
cv::Mat detmask;
|
||||
|
||||
private:
|
||||
/// @brief
|
||||
/// @param img 搜到图片 单通道
|
||||
/// @param DirectSign 搜索方向 >0 正向,< 0 反向
|
||||
/// @param Gate 阈值
|
||||
/// @param BorW 搜索黑点 = 0还是白点 = 1
|
||||
/// @param roi 搜索范围
|
||||
/// @param StepCount 搜索点数
|
||||
/// @param Limit 最小满是阈值点个数算上搜索成功
|
||||
/// @return <0 搜索错误, >=0表示 搜索位置
|
||||
int UDNoiseEdgeDetect(cv::Mat img, int DirectSign, int Gate, int BorW, cv::Rect roi, int StepCount, int Limit);
|
||||
/// @brief
|
||||
/// @param img 搜到图片 单通道
|
||||
/// @param DirectSign 搜索方向 >0 正向,< 0 反向
|
||||
/// @param Gate 阈值
|
||||
/// @param BorW 搜索黑点 = 0还是白点 = 1
|
||||
/// @param roi 搜索范围
|
||||
/// @param StepCount 搜索点数
|
||||
/// @param Limit 最小满是阈值点个数算上搜索成功
|
||||
/// @return <0 搜索错误, >=0表示 搜索位置
|
||||
int LRNoiseEdgeDetect(cv::Mat img, int DirectSign, int Gate, int BorW, cv::Rect roi, int StepCount, int Limit);
|
||||
// int LRNoiseEdgeDetect(cv::Mat img,int DirectSign, int Gate,int BorW, int StartSearchSite, int Step, int StepCount, int top, int bottom, int Limit, int Depth, int MaxLimit);
|
||||
};
|
||||
|
||||
#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,652 @@
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: sueRimn
|
||||
* @Date: 2022-03-16 17:09:11
|
||||
* @LastEditors: xiewenji 527774126@qq.com
|
||||
* @LastEditTime: 2025-07-26 11:21:59
|
||||
*/
|
||||
/***********************************************/
|
||||
/************ ***************/
|
||||
/************金佰利检测算法参数定义**************/
|
||||
/************ **************/
|
||||
/**********************************************/
|
||||
#ifndef _ImgCheckConfig_HPP_
|
||||
#define _ImgCheckConfig_HPP_
|
||||
#include <string>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#define RESULT_VERSION 26
|
||||
#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, // 0 疑是
|
||||
ERROR_TYPE_AD_YX, // 1 AD-异常显示
|
||||
ERROR_TYPE_Line_X, // 2 x line
|
||||
ERROR_TYPE_Line_Y, // 3 y line
|
||||
ERROR_TYPE_Line_fangge, // 3 y line
|
||||
ERROR_TYPE_Rubbing_Mura, // 4
|
||||
ERROR_TYPE_line_Broken, // 5 断线
|
||||
ERROR_TYPE_ZARA, // 6 ZARA
|
||||
ERROR_TYPE_MTX, // 7 MTX
|
||||
ERROR_TYPE_POL_Cell, // 8 异物
|
||||
ERROR_TYPE_LD, // 9 亮点
|
||||
ERROR_TYPE_AD, // 10 暗点
|
||||
ERROR_TYPE_BD, // 11 黑点
|
||||
ERROR_TYPE_WD, // 12 白点
|
||||
ERROR_TYPE_Scratch, // 13 划伤
|
||||
ERROR_TYPE_Weak_Bright_Mura, // 14 白GAP
|
||||
ERROR_TYPE_No_Label, // 15 缺POL
|
||||
ERROR_TYPE_PS, // 16 PS
|
||||
ERROR_TYPE_GRID_LINE, // 17 方格线
|
||||
ERROR_TYPE_STEAM_POCKET, // 19 气泡
|
||||
ERROR_TYPE_Dirty, // 19 脏污
|
||||
ERROR_TYPE_Other, // 19 other
|
||||
ERROR_TYPE_Cell_W, // 19 other
|
||||
ERROR_TYPE_Cell_B, // 19 other
|
||||
ERROR_TYPE_LackPol, // 缺失Pol
|
||||
ERROR_TYPE_CHESS,
|
||||
ERROR_TYPE_COUNT,
|
||||
};
|
||||
static const std::string QX_Result_Names[] =
|
||||
{
|
||||
"OK",
|
||||
"AD_YX",
|
||||
"X_Line",
|
||||
"Y_Line",
|
||||
"fangge",
|
||||
"Rubbing_Mura",
|
||||
"Broken_line",
|
||||
"ZARA",
|
||||
"MTX",
|
||||
"POL_Cell",
|
||||
"Bright_Point",
|
||||
"Dark_Point",
|
||||
"BLack_Point",
|
||||
"White_Point",
|
||||
"Scratch",
|
||||
"Weak_Bright_Mura",
|
||||
"No_Label",
|
||||
"Bright_Mura_Exe",
|
||||
"Sweak_Line_Dark",
|
||||
"STEAM_POCKET",
|
||||
"Dirty",
|
||||
"other",
|
||||
"Cell_W",
|
||||
"Cell_B",
|
||||
"LackPol",
|
||||
"Chess"};
|
||||
static const std::string QX_Result_Code[] =
|
||||
{
|
||||
"P1153",
|
||||
"P6873",
|
||||
"P3351",
|
||||
"P3452",
|
||||
"P3453",
|
||||
"P1550",
|
||||
"P3379",
|
||||
"P1153",
|
||||
"P1164",
|
||||
"P1101",
|
||||
"P1112",
|
||||
"P1111",
|
||||
"P1104",
|
||||
"P1103",
|
||||
"P1557",
|
||||
"P1654",
|
||||
"P2833",
|
||||
"P1549",
|
||||
"P1204",
|
||||
"P2534",
|
||||
"P2534",
|
||||
"P1101",
|
||||
"P1103",
|
||||
"P1104",
|
||||
"P8001",
|
||||
"P8002",
|
||||
};
|
||||
// 检测检测参数类型
|
||||
enum CHECK_CONFIG_TYPE_
|
||||
{
|
||||
CHECK_CONFIG_Run, // 运行参数
|
||||
CHECK_CONFIG_Module, // 参数模块
|
||||
CHECK_CONFIG_Module_Cam2, // 参数模块 相机2参数
|
||||
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_ZF,
|
||||
DET_MODE_YX,
|
||||
DET_MODE_UP,
|
||||
DET_MODE_Det,
|
||||
DET_MODE_MarkLine,
|
||||
DET_MODE_ReJson,
|
||||
};
|
||||
|
||||
#define MAX_REGION_NUM 20
|
||||
|
||||
// 一个检测项基本信息,包括图片序号,图片、开始时间
|
||||
struct shareImage
|
||||
{
|
||||
int Det_Mode; // 检测模式
|
||||
int Status;
|
||||
int camera_ID; // 相机ID
|
||||
std::string camera_Name; // 相机名称
|
||||
int img_id;
|
||||
cv::Mat img;
|
||||
cv::Mat other_channel_Result_mask; // 其他通道的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 img_channel; // 图片通道号
|
||||
int ninstruct; // 运行指令
|
||||
int nlogLevel; // 日志等级
|
||||
|
||||
std::string imgstr;
|
||||
std::string strImgName;
|
||||
std::string strImgProductID;
|
||||
std::string strImgType;
|
||||
std::string strChannel;
|
||||
int nImgBigIdx;
|
||||
int otherValue;
|
||||
int otherValue_1;
|
||||
std::string resultJson;
|
||||
bool bsaveProcessImg; // 保存处理图片
|
||||
|
||||
|
||||
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;
|
||||
strImgName = "";
|
||||
strImgProductID = "";
|
||||
strChannel = "";
|
||||
strImgType = "";
|
||||
nImgBigIdx = 0;
|
||||
cutRoi = cv::Rect(0, 0, 0, 0);
|
||||
otherValue = 0;
|
||||
ninstruct = 0;
|
||||
img_channel = 0;
|
||||
resultJson = "";
|
||||
camera_Name = "";
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// AI分析结果
|
||||
struct JudgeInfo
|
||||
{
|
||||
int result = 0;
|
||||
int positive = 0;
|
||||
int smudgy = 0;
|
||||
int abnormal = 0;
|
||||
int black = 0;
|
||||
int dot = 0;
|
||||
int other = 0;
|
||||
std::string RESULT = "OK";
|
||||
std::string POSITIVE = "OK"; // 正样本 4
|
||||
std::string SMUDGY = "OK"; // 脏污 3 R通道
|
||||
std::string ABNORMAL = "OK"; // zhansi 毛发 2 B通道
|
||||
std::string BLACK = "OK"; // 黑接头 1
|
||||
std::string DOT = "OK"; // 黑点 1
|
||||
std::string OTHER = "OK"; // 其他 1
|
||||
void Init()
|
||||
{
|
||||
result = 0;
|
||||
positive = 0;
|
||||
smudgy = 0;
|
||||
abnormal = 0;
|
||||
black = 0;
|
||||
dot = 0;
|
||||
other = 0;
|
||||
RESULT = "OK";
|
||||
POSITIVE = "OK";
|
||||
SMUDGY = "OK";
|
||||
ABNORMAL = "OK";
|
||||
BLACK = "OK";
|
||||
DOT = "OK";
|
||||
OTHER = "OK";
|
||||
}
|
||||
void copy(JudgeInfo tem)
|
||||
{
|
||||
this->result = tem.result;
|
||||
this->positive = tem.positive;
|
||||
this->smudgy = tem.smudgy;
|
||||
this->abnormal = tem.abnormal;
|
||||
this->black = tem.black;
|
||||
this->dot = tem.dot;
|
||||
this->RESULT = tem.RESULT;
|
||||
this->POSITIVE = tem.POSITIVE;
|
||||
this->SMUDGY = tem.SMUDGY;
|
||||
this->ABNORMAL = tem.ABNORMAL;
|
||||
this->BLACK = tem.BLACK;
|
||||
this->DOT = tem.DOT;
|
||||
}
|
||||
};
|
||||
|
||||
// 检测结果基本信息
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
// 缺陷blob信息
|
||||
struct BLobST
|
||||
{
|
||||
cv::Rect blob;
|
||||
cv::Rect blob_ResizeImg;
|
||||
cv::Rect blob_SrcImg;
|
||||
int energy;
|
||||
int area;
|
||||
float JudgArea;
|
||||
int UserErrorType;
|
||||
BLobST()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
blob = cv::Rect(0, 0, 0, 0);
|
||||
blob_ResizeImg = cv::Rect(0, 0, 0, 0);
|
||||
blob_SrcImg = cv::Rect(0, 0, 0, 0);
|
||||
energy = 0;
|
||||
area = 0;
|
||||
JudgArea = 0;
|
||||
UserErrorType = ERROR_TYPE_OK;
|
||||
}
|
||||
void copy(BLobST tem)
|
||||
{
|
||||
this->blob = tem.blob;
|
||||
this->blob_ResizeImg = tem.blob_ResizeImg;
|
||||
this->blob_SrcImg = tem.blob_SrcImg;
|
||||
this->energy = tem.energy;
|
||||
this->area = tem.area;
|
||||
this->JudgArea = tem.JudgArea;
|
||||
this->UserErrorType = tem.UserErrorType;
|
||||
}
|
||||
};
|
||||
|
||||
// 缺陷blob信息
|
||||
struct BLobListST
|
||||
{
|
||||
BLobST bloblist[MAX_BLOB_NUM];
|
||||
int blobNum;
|
||||
BLobListST()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
blobNum = 0;
|
||||
for (int i = 0; i < MAX_BLOB_NUM; i++)
|
||||
{
|
||||
bloblist[i].Init();
|
||||
}
|
||||
}
|
||||
void copy(BLobListST tem)
|
||||
{
|
||||
this->blobNum = tem.blobNum;
|
||||
for (int i = 0; i < MAX_BLOB_NUM; i++)
|
||||
{
|
||||
this->bloblist[i].copy(tem.bloblist[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
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;
|
||||
}
|
||||
};
|
||||
#define MAX_SamllImg_xcount 13
|
||||
#define MAX_SamllImg_ycount 10
|
||||
|
||||
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 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;
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
// AI处理后的 结果信息,上传到队列中,做后续风险
|
||||
struct AI_REUSLTIMG
|
||||
{
|
||||
|
||||
cv::Mat defectImg; // 缺陷检测结果图片
|
||||
AI_REUSLTIMG()
|
||||
{
|
||||
if (!defectImg.empty())
|
||||
{
|
||||
defectImg.release();
|
||||
}
|
||||
}
|
||||
~AI_REUSLTIMG()
|
||||
{
|
||||
release();
|
||||
}
|
||||
void release()
|
||||
{
|
||||
|
||||
if (!defectImg.empty())
|
||||
{
|
||||
defectImg.release();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif //_CORELOGICFACTORY_HPP_
|
||||
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* @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 OtherDetBaseDefine_H_
|
||||
#define OtherDetBaseDefine_H_
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "AIImgDeal.h"
|
||||
#include "BlobBase.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct OtherDet_Config
|
||||
{
|
||||
int nDeviceId; // GPU 号
|
||||
int nUserValue;
|
||||
int nShowImg_Width;
|
||||
int nShowImg_Height;
|
||||
AI_IMG_deal *pAIDeal;
|
||||
CHECK_TEM_RESULT *pTemCheck;
|
||||
|
||||
OtherDet_Config()
|
||||
{
|
||||
pAIDeal = NULL;
|
||||
pTemCheck = NULL;
|
||||
nDeviceId = 0;
|
||||
nUserValue = 0;
|
||||
nShowImg_Width = 100;
|
||||
nShowImg_Height = 100;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,74 @@
|
||||
/*
|
||||
//其他类的检测
|
||||
*/
|
||||
#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;
|
||||
AI_IMG_deal *m_pAIDeal;
|
||||
CHECK_TEM_RESULT *m_pTemCheck;
|
||||
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,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;
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,515 @@
|
||||
/*
|
||||
* FileName:CoreLogicFactory.cpp
|
||||
* Version:V1.0
|
||||
* Description:
|
||||
* Created On:Mon Sep 10 11:13:16 UTC 2018
|
||||
* Modified date:
|
||||
* Author:Sky
|
||||
*/
|
||||
#include "AICheck.h"
|
||||
#include "CUDA_Det.cuh"
|
||||
|
||||
#ifdef USE_TERNSORRT10_BIGMODEL
|
||||
#include <cassert> // 添加头文件
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include "CheckUtil.hpp"
|
||||
#define CHECK(status) \
|
||||
do \
|
||||
{ \
|
||||
auto ret = (status); \
|
||||
if (ret != 0) \
|
||||
{ \
|
||||
std::cerr << "Cuda failure: " << ret << std::endl; \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
class Logger : public ILogger
|
||||
{
|
||||
void log(Severity severity, const char *msg) noexcept override
|
||||
{
|
||||
// suppress info-level messages
|
||||
if (severity <= Severity::kWARNING)
|
||||
std::cout << msg << std::endl;
|
||||
}
|
||||
} logger;
|
||||
|
||||
static Logger gLogger;
|
||||
#else
|
||||
|
||||
#endif
|
||||
int g_falage = 0;
|
||||
AI_defect::AI_defect()
|
||||
{
|
||||
m_bInitialized = false;
|
||||
}
|
||||
|
||||
AI_defect::~AI_defect()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
void AI_defect::destroy()
|
||||
{
|
||||
for (int i = 0; i < MAX_AI_BUFFER_SIZE; i++)
|
||||
{
|
||||
if (m_config.bufferList[i].ntype == AIBufferType_NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
cudaFree(buffers[i]);
|
||||
cudaFree(ImgData[i]);
|
||||
if (floatData)
|
||||
{
|
||||
free(floatData);
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the engine
|
||||
#ifdef USE_TERNSORRT10_BIGMODEL
|
||||
#else
|
||||
context->destroy();
|
||||
engine->destroy();
|
||||
runtime->destroy();
|
||||
#endif
|
||||
}
|
||||
#ifdef USE_TERNSORRT10_BIGMODEL
|
||||
|
||||
int AI_defect::model_init(AIInitConfig config)
|
||||
{
|
||||
|
||||
if (m_bInitialized)
|
||||
{
|
||||
printf("AI_defect::model_init succ \n");
|
||||
return 0;
|
||||
}
|
||||
if (config.bufferList[0].strName == "")
|
||||
{
|
||||
// getchar();
|
||||
/* code */
|
||||
}
|
||||
|
||||
m_bInitialized = false;
|
||||
printf("-- AI Init nGpuIdx %d model file %s \n", config.nGpuIdx, config.engine_file_path.c_str());
|
||||
if (config.nGpuIdx < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!config.Checking())
|
||||
{
|
||||
printf("Checking error \n");
|
||||
return 1;
|
||||
}
|
||||
m_config.copy(config);
|
||||
m_config.CalSize(sizeof(float));
|
||||
|
||||
cudaSetDevice(m_config.nGpuIdx);
|
||||
char *trtModelStream{nullptr};
|
||||
size_t size{0};
|
||||
|
||||
std::ifstream file(m_config.engine_file_path, std::ios::binary);
|
||||
if (!file)
|
||||
{
|
||||
std::cerr << "Error opening engine file!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (file.good())
|
||||
{
|
||||
std::cout << "load engine success" << std::endl;
|
||||
file.seekg(0, file.end);
|
||||
size = file.tellg();
|
||||
file.seekg(0, file.beg);
|
||||
|
||||
trtModelStream = new char[size];
|
||||
assert(trtModelStream);
|
||||
|
||||
file.read(trtModelStream, size);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("------------Model file open error--********* \n");
|
||||
return 1;
|
||||
}
|
||||
printf("model_init 1 \n");
|
||||
runtime = createInferRuntime(gLogger);
|
||||
if (!runtime)
|
||||
{
|
||||
std::cerr << "Failed to create runtime!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
printf("model_init 2 \n");
|
||||
engine = runtime->deserializeCudaEngine(trtModelStream, size);
|
||||
if (!engine)
|
||||
{
|
||||
std::cerr << "Failed to create engine!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
printf("model_init 3 \n");
|
||||
// // Create execution context
|
||||
context = engine->createExecutionContext();
|
||||
if (!context)
|
||||
{
|
||||
std::cerr << "Failed to create execution context!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
delete[] trtModelStream;
|
||||
printf("model_init 4 \n");
|
||||
// 初始化buffer
|
||||
for (int i = 0; i < MAX_AI_BUFFER_SIZE; i++)
|
||||
{
|
||||
if (m_config.bufferList[i].ntype == AIBufferType_NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
floatData[i] = (float *)malloc(m_config.bufferList[i].ndatalength * sizeof(float));
|
||||
cudaMalloc(&buffers[i], m_config.bufferList[i].ndataSize);
|
||||
{
|
||||
int nsize = m_config.bufferList[i].ndatalength * sizeof(unsigned char);
|
||||
cudaMalloc(&ImgData[i], nsize);
|
||||
}
|
||||
}
|
||||
m_bInitialized = true;
|
||||
return 0;
|
||||
}
|
||||
int AI_defect::model_Cuda_AI_In_1_Out_1(unsigned char *p_indata_0, unsigned char *p_outdata_1)
|
||||
{
|
||||
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
cudaSetDevice(m_config.nGpuIdx);
|
||||
cudaStream_t stream;
|
||||
CHECK(cudaStreamCreate(&stream));
|
||||
|
||||
// printf(">>>>>>>>>>>>>>>>>CUDA test m_config.nGpuIdx %d \n", m_config.nGpuIdx);
|
||||
|
||||
const ICudaEngine &engine_123 = context->getEngine();
|
||||
// printf("name %s \n", m_config.bufferList[0].strName.c_str());
|
||||
// auto s = engine_123.getTensorShape(m_config.bufferList[0].strName.c_str());
|
||||
// std::cout << "tensor dims: [";
|
||||
// for (int i = 0; i < s.nbDims; i++)
|
||||
// {
|
||||
// std::cout << s.d[i];
|
||||
// if (i < s.nbDims - 1)
|
||||
// std::cout << ", ";
|
||||
// }
|
||||
// std::cout << "]" << std::endl;
|
||||
|
||||
// {
|
||||
// printf("name %s \n", m_config.bufferList[1].strName.c_str());
|
||||
// auto s = engine_123.getTensorShape(m_config.bufferList[1].strName.c_str());
|
||||
// std::cout << "tensor dims: [";
|
||||
// for (int i = 0; i < s.nbDims; i++)
|
||||
// {
|
||||
// std::cout << s.d[i];
|
||||
// if (i < s.nbDims - 1)
|
||||
// std::cout << ", ";
|
||||
// }
|
||||
// std::cout << "]" << std::endl;
|
||||
// }
|
||||
long t1, t2, t3, t4, t5, t6, t7;
|
||||
// t1 = CheckUtil::getcurTime();
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[0].ndatalength; i++)
|
||||
{
|
||||
floatData[0][i] = p_indata_0[i];
|
||||
}
|
||||
cudaMemcpyAsync(buffers[0], floatData[0], m_config.bufferList[0].ndataSize, cudaMemcpyHostToDevice, stream);
|
||||
// wrap_test_print();
|
||||
|
||||
// 拷贝数据到显卡
|
||||
// if (kk == 0)
|
||||
// {
|
||||
// cudaMemcpyAsync(ImgData[0], p_indata_0, m_config.bufferList[0].nuchardataSize, cudaMemcpyHostToDevice, stream);
|
||||
// printf("set img************************** m_config.bufferList[0].nuchardataSize %d\n", m_config.bufferList[0].nuchardataSize);
|
||||
// kk++;
|
||||
// }
|
||||
|
||||
// t2 = CheckUtil::getcurTime();
|
||||
// // 在显存中 图片数据从 uchar 转到 float
|
||||
// Cuda_ucharToFloat((unsigned char *)ImgData[0], (float *)buffers[0], m_config.bufferList[0].ndatalength);
|
||||
// t3 = CheckUtil::getcurTime();
|
||||
// float *temsssssdata = new float[1024 * 1024];
|
||||
// cudaMemcpyAsync(temsssssdata, buffers[0], m_config.bufferList[0].ndataSize, cudaMemcpyDeviceToHost, stream);
|
||||
// for (int i = 0; i < 1024*1024; i = i + 800)
|
||||
// {
|
||||
|
||||
// printf("%d %d %f %d ", i,m_config.bufferList[0].ndatalength, temsssssdata[i],p_indata_0[i]);
|
||||
// }
|
||||
// delete [] temsssssdata;
|
||||
|
||||
std::string s1 = engine_123.getIOTensorName(0);
|
||||
std::string s2 = engine_123.getIOTensorName(1);
|
||||
context->setTensorAddress(s1.c_str(), buffers[0]);
|
||||
context->setTensorAddress(s2.c_str(), buffers[1]);
|
||||
|
||||
context->enqueueV3(stream);
|
||||
// t4 = CheckUtil::getcurTime();
|
||||
|
||||
// Cuda_FloatTouchar((float *)buffers[1], (unsigned char *)ImgData[1], m_config.bufferList[1].ndatalength);
|
||||
// cudaMemcpyAsync(p_outdata_1, ImgData[1], m_config.bufferList[1].nuchardataSize, cudaMemcpyDeviceToHost, stream);
|
||||
|
||||
// float *temdata = new float[m_config.bufferList[1].nuchardataSize];
|
||||
cudaMemcpyAsync(floatData[1], buffers[1], m_config.bufferList[1].ndataSize, cudaMemcpyDeviceToHost, stream);
|
||||
// printf("11m_config.bufferList[0].nuchardataSize %d\n", m_config.bufferList[1].nuchardataSize);
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[1].nuchardataSize; i++)
|
||||
{
|
||||
p_outdata_1[i] = floatData[1][i];
|
||||
}
|
||||
// for (int i = 512 * 512 - 1000; i < 512 * 512; i++)
|
||||
// {
|
||||
// if (p_outdata_1[i] != 0)
|
||||
// {
|
||||
// printf("%d %d %f %d ", i, m_config.bufferList[1].nuchardataSize, temdata[i], p_outdata_1[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
// delete temsssssdata;
|
||||
// delete temdata;
|
||||
|
||||
// t5 = CheckUtil::getcurTime();
|
||||
cudaStreamSynchronize(stream);
|
||||
cudaStreamDestroy(stream);
|
||||
// t6 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("t2 -t1 %ld t3 -t2 %ld t4 -t3 %ld t5 -t4 %ld t6 -t5 %ld t6 -t1 %ld \n", t2 - t1, t3 - t2, t4 - t3, t5 - t4, t6 - t5, t6 - t1);
|
||||
|
||||
// getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_defect::model_Cuda_AI_In_1_Out_1_float(unsigned char *p_indata_0, float *p_outdata_1)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
cudaSetDevice(m_config.nGpuIdx);
|
||||
cudaStream_t stream;
|
||||
CHECK(cudaStreamCreate(&stream));
|
||||
|
||||
// printf(">>>>>>>>>>>>>>>>>CUDA test \n");
|
||||
|
||||
const ICudaEngine &engine_123 = context->getEngine();
|
||||
|
||||
// auto s = engine_123.getTensorShape(m_config.bufferList[0].strName.c_str());
|
||||
// std::cout << "tensor dims: [";
|
||||
// for (int i = 0; i < s.nbDims; i++)
|
||||
// {
|
||||
// std::cout << s.d[i];
|
||||
// if (i < s.nbDims - 1)
|
||||
// std::cout << ", ";
|
||||
// }
|
||||
// std::cout << "]" << std::endl;
|
||||
|
||||
// {
|
||||
// printf("name %s \n", m_config.bufferList[1].strName.c_str());
|
||||
// auto s = engine_123.getTensorShape(m_config.bufferList[1].strName.c_str());
|
||||
// std::cout << "tensor dims: [";
|
||||
// for (int i = 0; i < s.nbDims; i++)
|
||||
// {
|
||||
// std::cout << s.d[i];
|
||||
// if (i < s.nbDims - 1)
|
||||
// std::cout << ", ";
|
||||
// }
|
||||
// std::cout << "]" << std::endl;
|
||||
// }
|
||||
|
||||
// wrap_test_print();
|
||||
long t1, t2, t3, t4, t5, t6, t7;
|
||||
// t1 = CheckUtil::getcurTime();
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[0].ndatalength; i++)
|
||||
{
|
||||
floatData[0][i] = p_indata_0[i];
|
||||
}
|
||||
cudaMemcpyAsync(buffers[0], floatData[0], m_config.bufferList[0].ndataSize, cudaMemcpyHostToDevice, stream);
|
||||
// 拷贝数据到显卡
|
||||
// cudaMemcpyAsync(ImgData[0], p_indata_0, m_config.bufferList[0].nuchardataSize, cudaMemcpyHostToDevice, stream);
|
||||
// t2 = CheckUtil::getcurTime();
|
||||
// 在显存中 图片数据从 uchar 转到 float
|
||||
// Cuda_ucharToFloat((unsigned char *)ImgData[0], (float *)buffers[0], m_config.bufferList[0].ndatalength);
|
||||
// t3 = CheckUtil::getcurTime();
|
||||
|
||||
std::string s1 = engine_123.getIOTensorName(0);
|
||||
std::string s2 = engine_123.getIOTensorName(1);
|
||||
context->setTensorAddress(s1.c_str(), buffers[0]);
|
||||
context->setTensorAddress(s2.c_str(), buffers[1]);
|
||||
|
||||
context->enqueueV3(stream);
|
||||
// t4 = CheckUtil::getcurTime();
|
||||
|
||||
cudaMemcpyAsync(p_outdata_1, buffers[1], m_config.bufferList[1].ndataSize, cudaMemcpyDeviceToHost, stream);
|
||||
|
||||
// t5 = CheckUtil::getcurTime();
|
||||
cudaStreamSynchronize(stream);
|
||||
cudaStreamDestroy(stream);
|
||||
// t6 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("t2 -t1 %ld t3 -t2 %ld t4 -t3 %ld t5 -t4 %ld t6 -t5 %ld t6 -t1 %ld \n", t2 - t1, t3 - t2, t4 - t3, t5 - t4, t6 - t5, t6 - t1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
int AI_defect::model_init(AIInitConfig config)
|
||||
{
|
||||
if (m_bInitialized)
|
||||
{
|
||||
printf("AI_defect::model_init succ \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_bInitialized = false;
|
||||
printf("-- AI Init nGpuIdx %d model file %s \n", config.nGpuIdx, config.engine_file_path.c_str());
|
||||
if (config.nGpuIdx < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!config.Checking())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
m_config.copy(config);
|
||||
m_config.CalSize(sizeof(float));
|
||||
|
||||
cudaSetDevice(m_config.nGpuIdx);
|
||||
char *trtModelStream{nullptr};
|
||||
size_t size{0};
|
||||
|
||||
std::ifstream file(m_config.engine_file_path, std::ios::binary);
|
||||
if (file.good())
|
||||
{
|
||||
file.seekg(0, file.end);
|
||||
size = file.tellg();
|
||||
file.seekg(0, file.beg);
|
||||
trtModelStream = new char[size];
|
||||
assert(trtModelStream);
|
||||
file.read(trtModelStream, size);
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("------------Model file open error--********* \n");
|
||||
return 1;
|
||||
}
|
||||
sample::Logger m_logger;
|
||||
runtime = createInferRuntime(m_logger);
|
||||
assert(runtime != nullptr);
|
||||
|
||||
engine = runtime->deserializeCudaEngine(trtModelStream, size, nullptr);
|
||||
assert(engine != nullptr);
|
||||
|
||||
context = engine->createExecutionContext();
|
||||
assert(context != nullptr);
|
||||
delete[] trtModelStream;
|
||||
|
||||
for (int i = 0; i < MAX_AI_BUFFER_SIZE; i++)
|
||||
{
|
||||
if (m_config.bufferList[i].ntype == AIBufferType_NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
floatData[i] = (float *)malloc(m_config.bufferList[i].ndatalength * sizeof(float));
|
||||
cudaMalloc(&buffers[i], m_config.bufferList[i].ndataSize);
|
||||
{
|
||||
int nsize = m_config.bufferList[i].ndatalength * sizeof(unsigned char);
|
||||
cudaMalloc(&ImgData[i], nsize);
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
m_bInitialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_defect::model_Cuda_AI_In_1_Out_1(unsigned char *p_indata_0, unsigned char *p_outdata_1)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
cudaSetDevice(m_config.nGpuIdx);
|
||||
cudaStream_t stream;
|
||||
cudaStreamCreate(&stream);
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[0].ndatalength; i++)
|
||||
{
|
||||
floatData[0][i] = p_indata_0[i];
|
||||
}
|
||||
cudaMemcpyAsync(buffers[0], floatData[0], m_config.bufferList[0].ndataSize, cudaMemcpyHostToDevice, stream);
|
||||
|
||||
// // 拷贝数据到显卡
|
||||
// cudaMemcpyAsync(ImgData[0], p_indata_0, m_config.bufferList[0].nuchardataSize, cudaMemcpyHostToDevice, stream);
|
||||
// // t2 = CheckUtil::getcurTime();
|
||||
// // 在显存中 图片数据从 uchar 转到 float
|
||||
// Cuda_ucharToFloat((unsigned char *)ImgData[0], (float *)buffers[0], m_config.bufferList[0].ndatalength);
|
||||
// t3 = CheckUtil::getcurTime();
|
||||
|
||||
context->enqueueV2(buffers, stream, nullptr);
|
||||
// t4 = CheckUtil::getcurTime();
|
||||
|
||||
cudaMemcpyAsync(floatData[1], buffers[1], m_config.bufferList[1].ndataSize, cudaMemcpyDeviceToHost, stream);
|
||||
// printf("11m_config.bufferList[0].nuchardataSize %d\n", m_config.bufferList[1].nuchardataSize);
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[1].nuchardataSize; i++)
|
||||
{
|
||||
p_outdata_1[i] = floatData[1][i];
|
||||
}
|
||||
|
||||
// Cuda_FloatTouchar((float *)buffers[1], (unsigned char *)ImgData[1], m_config.bufferList[1].ndatalength);
|
||||
// cudaMemcpyAsync(p_outdata_1, ImgData[1], m_config.bufferList[1].nuchardataSize, cudaMemcpyDeviceToHost, stream);
|
||||
|
||||
// t5 = CheckUtil::getcurTime();
|
||||
cudaStreamSynchronize(stream);
|
||||
cudaStreamDestroy(stream);
|
||||
// t6 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("t2 -t1 %ld t3 -t2 %ld t4 -t3 %ld t5 -t4 %ld t6 -t5 %ld t6 -t1 %ld \n", t2 - t1, t3 - t2, t4 - t3, t5 - t4, t6 - t5, t6 - t1);
|
||||
|
||||
// getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_defect::model_Cuda_AI_In_1_Out_1_float(unsigned char *p_indata_0, float *p_outdata_1)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
cudaSetDevice(m_config.nGpuIdx);
|
||||
cudaStream_t stream;
|
||||
cudaStreamCreate(&stream);
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[0].ndatalength; i++)
|
||||
{
|
||||
floatData[0][i] = p_indata_0[i];
|
||||
}
|
||||
cudaMemcpyAsync(buffers[0], floatData[0], m_config.bufferList[0].ndataSize, cudaMemcpyHostToDevice, stream);
|
||||
|
||||
// // 拷贝数据到显卡
|
||||
// cudaMemcpyAsync(ImgData[0], p_indata_0, m_config.bufferList[0].nuchardataSize, cudaMemcpyHostToDevice, stream);
|
||||
// // t2 = CheckUtil::getcurTime();
|
||||
// // 在显存中 图片数据从 uchar 转到 float
|
||||
// Cuda_ucharToFloat((unsigned char *)ImgData[0], (float *)buffers[0], m_config.bufferList[0].ndatalength);
|
||||
// t3 = CheckUtil::getcurTime();
|
||||
|
||||
context->enqueueV2(buffers, stream, nullptr);
|
||||
|
||||
cudaMemcpyAsync(floatData[1], buffers[1], m_config.bufferList[1].ndataSize, cudaMemcpyDeviceToHost, stream);
|
||||
// printf("11m_config.bufferList[0].nuchardataSize %d\n", m_config.bufferList[1].nuchardataSize);
|
||||
|
||||
for (int i = 0; i < m_config.bufferList[1].nuchardataSize; i++)
|
||||
{
|
||||
p_outdata_1[i] = floatData[1][i];
|
||||
}
|
||||
|
||||
// t4 = CheckUtil::getcurTime();
|
||||
// cudaMemcpyAsync(p_outdata_1, buffers[1], m_config.bufferList[1].ndataSize, cudaMemcpyDeviceToHost, stream);
|
||||
|
||||
// t5 = CheckUtil::getcurTime();
|
||||
cudaStreamSynchronize(stream);
|
||||
cudaStreamDestroy(stream);
|
||||
// t6 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("t2 -t1 %ld t3 -t2 %ld t4 -t3 %ld t5 -t4 %ld t6 -t5 %ld t6 -t1 %ld \n", t2 - t1, t3 - t2, t4 - t3, t5 - t4, t6 - t5, t6 - t1);
|
||||
|
||||
// getchar();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,359 @@
|
||||
|
||||
#include "AIClassify.h"
|
||||
#include "AICommonDefine.h"
|
||||
bool compare_Piece(const AI_PIECE_INFO &a, const AI_PIECE_INFO &b)
|
||||
{
|
||||
return a.abs_L < b.abs_L;
|
||||
}
|
||||
AIClassify::AIClassify()
|
||||
{
|
||||
}
|
||||
|
||||
AIClassify::~AIClassify()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
cv::Rect AIClassify::GetCutRoi(cv::Rect roi, const cv::Mat &img)
|
||||
{
|
||||
|
||||
cv::Rect cutroi;
|
||||
int pc_x = roi.x + roi.width * 0.5;
|
||||
int pc_y = roi.y + roi.height * 0.5;
|
||||
bool bresize = false;
|
||||
if (roi.width < QX_SAMLLIMG_WIDTH && roi.height < QX_SAMLLIMG_HEIGHT)
|
||||
{
|
||||
cutroi.width = QX_SAMLLIMG_WIDTH;
|
||||
cutroi.x = pc_x - QX_SAMLLIMG_WIDTH * 0.5;
|
||||
cutroi.height = QX_SAMLLIMG_HEIGHT;
|
||||
cutroi.y = pc_y - QX_SAMLLIMG_HEIGHT * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 宽 高
|
||||
if (roi.width > roi.height)
|
||||
{
|
||||
cutroi.width = roi.width + 20;
|
||||
cutroi.x = roi.x - 10;
|
||||
|
||||
float fsx = QX_SAMLLIMG_HEIGHT * 1.0f / QX_SAMLLIMG_WIDTH;
|
||||
cutroi.height = cutroi.width * fsx;
|
||||
cutroi.y = pc_y - cutroi.height * 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
cutroi.height = roi.height + 20;
|
||||
cutroi.y = roi.y - 10;
|
||||
|
||||
float fsy = QX_SAMLLIMG_WIDTH * 1.0f / QX_SAMLLIMG_HEIGHT;
|
||||
cutroi.width = cutroi.height * fsy;
|
||||
cutroi.x = pc_x - cutroi.width * 0.5;
|
||||
}
|
||||
|
||||
bresize = true;
|
||||
}
|
||||
|
||||
if (cutroi.x < 0)
|
||||
{
|
||||
cutroi.x = 0;
|
||||
}
|
||||
if (cutroi.y < 0)
|
||||
{
|
||||
cutroi.y = 0;
|
||||
}
|
||||
if (cutroi.x + cutroi.width >= img.cols)
|
||||
{
|
||||
cutroi.x = img.cols - cutroi.width;
|
||||
if (cutroi.x < 0)
|
||||
{
|
||||
cutroi.x = 0;
|
||||
if (cutroi.x + cutroi.width >= img.cols)
|
||||
{
|
||||
cutroi.width = img.cols;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cutroi.y + cutroi.height >= img.rows)
|
||||
{
|
||||
cutroi.y = img.rows - cutroi.height;
|
||||
if (cutroi.y < 0)
|
||||
{
|
||||
cutroi.y = 0;
|
||||
if (cutroi.y + cutroi.height >= img.rows)
|
||||
{
|
||||
cutroi.height = img.rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cutroi;
|
||||
}
|
||||
int AIClassify::GetDetRoiList(const cv::Mat &src_Img, cv::Rect qx_roi, std::vector<cv::Rect> &samllRoiList)
|
||||
{
|
||||
|
||||
// qx_roi.x = 10;
|
||||
// qx_roi.y = src_Img.rows - 10;
|
||||
// qx_roi.width = src_Img.rows - 150;
|
||||
// qx_roi.height = 8;
|
||||
|
||||
int Min_SizeWH = 160;
|
||||
int Max_sizeWH = 400;
|
||||
// 块之间重叠度
|
||||
int overlap = 100;
|
||||
// 单边的块数最多
|
||||
int Edge_Piece_single_Num = 7;
|
||||
// 总的块数最多支持 9个。
|
||||
int Edge_Piece_Sum_Num = 9;
|
||||
|
||||
int qx_w = qx_roi.width;
|
||||
int qx_h = qx_roi.height;
|
||||
// 长边、短边
|
||||
int long_side = qx_w;
|
||||
int short_side = qx_h;
|
||||
if (qx_w >= qx_h)
|
||||
{
|
||||
long_side = qx_w;
|
||||
short_side = qx_h;
|
||||
}
|
||||
else
|
||||
{
|
||||
long_side = qx_h;
|
||||
short_side = qx_w;
|
||||
}
|
||||
//printf("img %d %d qx %d %d \n", src_Img.cols, src_Img.rows, long_side, short_side);
|
||||
std::vector<AI_PIECE_INFO> pieceList;
|
||||
if (long_side <= Min_SizeWH)
|
||||
{
|
||||
AI_PIECE_INFO tem;
|
||||
tem.len = long_side;
|
||||
tem.num = 1;
|
||||
tem.long_num = 1;
|
||||
tem.short_num = 1;
|
||||
tem.abs_L = 0;
|
||||
|
||||
pieceList.push_back(tem);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// 1、从长边开始计算
|
||||
for (int i = 1; i <= Edge_Piece_single_Num; i++)
|
||||
{
|
||||
int piece_len = std::ceil(long_side * 1.0f / i);
|
||||
int piece_overlap_len = std::ceil(piece_len + (i - 1) / i * overlap);
|
||||
int long_Piece_Num = i;
|
||||
int short_Piece_Num = std::ceil(short_side * 1.0f / piece_overlap_len);
|
||||
int sum_Piece_Num = long_Piece_Num * short_Piece_Num;
|
||||
|
||||
//printf("piece size %d %d long Num %d short Num %d sum %d \n", piece_len, piece_overlap_len, long_Piece_Num, short_Piece_Num, sum_Piece_Num);
|
||||
if (sum_Piece_Num > Edge_Piece_Sum_Num)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
AI_PIECE_INFO tem;
|
||||
tem.len = piece_overlap_len;
|
||||
tem.num = sum_Piece_Num;
|
||||
tem.long_num = long_Piece_Num;
|
||||
tem.short_num = short_Piece_Num;
|
||||
tem.abs_L = std::abs(piece_overlap_len - Max_sizeWH);
|
||||
|
||||
pieceList.push_back(tem);
|
||||
}
|
||||
}
|
||||
std::sort(pieceList.begin(), pieceList.end(), compare_Piece);
|
||||
|
||||
// for (int i = 0; i < pieceList.size(); i++)
|
||||
// {
|
||||
// pieceList.at(i).print(std::to_string(i));
|
||||
// }
|
||||
if (pieceList.size() <= 0)
|
||||
{
|
||||
printf("Select Roi fail\n");
|
||||
return 1;
|
||||
}
|
||||
AI_PIECE_INFO selectPiece;
|
||||
selectPiece.len = pieceList.at(0).len;
|
||||
selectPiece.num = pieceList.at(0).num;
|
||||
selectPiece.long_num = pieceList.at(0).long_num;
|
||||
selectPiece.short_num = pieceList.at(0).short_num;
|
||||
selectPiece.abs_L = pieceList.at(0).abs_L;
|
||||
//selectPiece.print("select");
|
||||
|
||||
int W_Piece_Num = selectPiece.long_num;
|
||||
int H_Piece_Num = selectPiece.short_num;
|
||||
if (qx_w >= qx_h)
|
||||
{
|
||||
W_Piece_Num = selectPiece.long_num;
|
||||
H_Piece_Num = selectPiece.short_num;
|
||||
}
|
||||
else
|
||||
{
|
||||
W_Piece_Num = selectPiece.short_num;
|
||||
H_Piece_Num = selectPiece.long_num;
|
||||
}
|
||||
int Piece_len = selectPiece.len;
|
||||
if (Piece_len < Min_SizeWH)
|
||||
{
|
||||
Piece_len = Min_SizeWH;
|
||||
}
|
||||
|
||||
/////////////////、计算宽度方向 块的个数 和 重叠 ///////////////////////
|
||||
// 块的个数
|
||||
int nBlocknum_x = W_Piece_Num;
|
||||
|
||||
int use_MinOverlap_Width = 0;
|
||||
// 计算重叠率
|
||||
if (nBlocknum_x > 1)
|
||||
{
|
||||
// 有多个块,要判断 块的重叠是否满足要求
|
||||
int nSumLen_x = nBlocknum_x * Piece_len; //
|
||||
float fOverlap_x = (nSumLen_x - qx_w) * 1.0f / (nBlocknum_x - 1);
|
||||
use_MinOverlap_Width = int(fOverlap_x);
|
||||
}
|
||||
|
||||
/////////////////、计算高度方向 块的个数 和 重叠 ///////////////////////
|
||||
|
||||
// 块的个数
|
||||
int nBlocknum_y = H_Piece_Num;
|
||||
|
||||
int use_MinOverlap_Height = 0;
|
||||
// 计算重叠率
|
||||
if (nBlocknum_y > 1)
|
||||
{
|
||||
// 有多个块,要判断 块的重叠是否满足要求
|
||||
int nSumLen_y = nBlocknum_y * Piece_len; //
|
||||
float fOverlap_y = (nSumLen_y - qx_h) * 1.0f / (nBlocknum_y - 1);
|
||||
use_MinOverlap_Height = int(fOverlap_y);
|
||||
}
|
||||
|
||||
int start_x = qx_roi.x;
|
||||
int start_y = qx_roi.y;
|
||||
|
||||
int end_x = qx_roi.width + qx_roi.x;
|
||||
int end_y = qx_roi.height + qx_roi.y;
|
||||
|
||||
// 有效图片 宽 高
|
||||
int det_width = qx_roi.width;
|
||||
int det_height = qx_roi.height;
|
||||
|
||||
int AI_Img_width = Piece_len;
|
||||
int AI_Img_height = Piece_len;
|
||||
|
||||
if (nBlocknum_x == 1)
|
||||
{
|
||||
int sx = AI_Img_width - det_width;
|
||||
int sub_x = 0;
|
||||
if (sx > 0)
|
||||
{
|
||||
sub_x = sx / 2;
|
||||
}
|
||||
start_x -= sub_x;
|
||||
if (start_x < 0)
|
||||
{
|
||||
start_x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int cut_sy = qx_roi.y;
|
||||
int cut_ey = qx_roi.y + Piece_len;
|
||||
|
||||
if (nBlocknum_y == 1)
|
||||
{
|
||||
int sy = AI_Img_width - det_height;
|
||||
int sub_y = 0;
|
||||
if (sy > 0)
|
||||
{
|
||||
sub_y = sy / 2;
|
||||
}
|
||||
start_y -= sub_y;
|
||||
if (start_y < 0)
|
||||
{
|
||||
start_y = 0;
|
||||
}
|
||||
}
|
||||
cut_sy = start_y;
|
||||
cut_ey = start_y + AI_Img_height;
|
||||
if (cut_ey >= src_Img.rows)
|
||||
{
|
||||
cut_ey = src_Img.rows;
|
||||
cut_sy = cut_ey - AI_Img_height;
|
||||
}
|
||||
|
||||
for (int iy = 0; iy < nBlocknum_y; iy++)
|
||||
{
|
||||
int nleny = end_y - cut_ey;
|
||||
int cut_sx = start_x;
|
||||
int cut_ex = start_x + AI_Img_width;
|
||||
if (cut_ex >= src_Img.cols)
|
||||
{
|
||||
cut_ex = src_Img.cols;
|
||||
cut_sx = cut_ex - AI_Img_width;
|
||||
}
|
||||
|
||||
for (int ix = 0; ix < nBlocknum_x; ix++)
|
||||
{
|
||||
|
||||
cv::Rect roi;
|
||||
roi.x = cut_sx;
|
||||
roi.y = cut_sy;
|
||||
roi.width = AI_Img_width;
|
||||
roi.height = AI_Img_height;
|
||||
|
||||
samllRoiList.push_back(roi);
|
||||
|
||||
// 剩余长度
|
||||
int nlenx = end_x - cut_ex;
|
||||
if (nlenx > AI_Img_width)
|
||||
{
|
||||
cut_sx = cut_sx + AI_Img_width - use_MinOverlap_Width;
|
||||
cut_ex = cut_sx + AI_Img_width;
|
||||
}
|
||||
else
|
||||
{
|
||||
cut_sx = end_x - AI_Img_width;
|
||||
cut_ex = cut_sx + AI_Img_width;
|
||||
}
|
||||
}
|
||||
|
||||
if (nleny > AI_Img_height)
|
||||
{
|
||||
cut_sy = cut_sy + AI_Img_height - use_MinOverlap_Height;
|
||||
cut_ey = cut_sy + AI_Img_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
cut_sy = end_y - AI_Img_height;
|
||||
cut_ey = cut_sy + AI_Img_height;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是偶数个,则需要再加个一个。
|
||||
int sumblob = nBlocknum_y * nBlocknum_x;
|
||||
if (sumblob % 2 == 0)
|
||||
{
|
||||
|
||||
cv::Rect temRoi = GetCutRoi(qx_roi, src_Img);
|
||||
samllRoiList.push_back(temRoi);
|
||||
}
|
||||
|
||||
if (false)
|
||||
{
|
||||
cv::Mat showimg = src_Img.clone();
|
||||
if (showimg.channels() == 1)
|
||||
{
|
||||
cv::cvtColor(showimg, showimg, cv::COLOR_GRAY2BGR);
|
||||
}
|
||||
cv::rectangle(showimg, qx_roi, cv::Scalar(255, 255, 0), 5);
|
||||
for (size_t i = 0; i < samllRoiList.size(); i++)
|
||||
{
|
||||
cv::rectangle(showimg, samllRoiList.at(i), cv::Scalar(255, 0, 0));
|
||||
}
|
||||
static int idx = 0;
|
||||
cv::imwrite(std::to_string(idx++) + "tem_piece.png", showimg);
|
||||
}
|
||||
|
||||
// getchar();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,710 @@
|
||||
/*
|
||||
* FileName:CoreLogicFactory.cpp
|
||||
* Version:V1.0
|
||||
* Description:
|
||||
* Created On:Mon Sep 10 11:13:16 UTC 2018
|
||||
* Modified date:
|
||||
* Author:Sky
|
||||
*/
|
||||
#include "AIImgDeal.h"
|
||||
#include "CheckUtil.hpp"
|
||||
AI_IMG_deal::AI_IMG_deal()
|
||||
{
|
||||
|
||||
m_pAI_SingleGPU = NULL;
|
||||
|
||||
AI_DATA_Cls_OUT_0 = NULL;
|
||||
AI_DATA_Cls_L0_OUT_0 = NULL;
|
||||
bInitSucc_re_AD = false;
|
||||
bInitSucc_re_Pol = false;
|
||||
|
||||
bInitSucc_Edge_Samll = false;
|
||||
bInitSucc_Edge_big = false;
|
||||
bInitSucc_LackPol = false;
|
||||
bInitSucc_MarkLine = false;
|
||||
NewData();
|
||||
}
|
||||
|
||||
AI_IMG_deal::~AI_IMG_deal()
|
||||
{
|
||||
// cout << "单例对象销毁!" << endl;
|
||||
DelteData();
|
||||
}
|
||||
|
||||
// 根据gpu号初始化
|
||||
int AI_IMG_deal::Init(int nGpuIdx)
|
||||
{
|
||||
if (nGpuIdx < 0 || nGpuIdx >= MAX_GPU_NUMBER)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
m_nGpuIdx = nGpuIdx;
|
||||
|
||||
m_pAI_SingleGPU = AI_SingleGPU::GetInstance(nGpuIdx);
|
||||
cout << "AI_IMG_deal GPU:" << m_nGpuIdx << " create succ " << m_pAI_SingleGPU << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::NewData()
|
||||
{
|
||||
|
||||
if (AI_DATA_Cls_OUT_0 == NULL)
|
||||
{
|
||||
AI_DATA_Cls_OUT_0 = new float[AI_Cls_out_0_IMAGE_DATA_LENGTH];
|
||||
}
|
||||
if (AI_DATA_Cls_L0_OUT_0 == NULL)
|
||||
{
|
||||
AI_DATA_Cls_L0_OUT_0 = new float[AI_Cls_14_out_0_IMAGE_DATA_LENGTH];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::DelteData()
|
||||
{
|
||||
|
||||
if (AI_DATA_Cls_OUT_0)
|
||||
{
|
||||
delete[] AI_DATA_Cls_OUT_0;
|
||||
AI_DATA_Cls_OUT_0 = NULL;
|
||||
}
|
||||
if (AI_DATA_Cls_L0_OUT_0)
|
||||
{
|
||||
delete[] AI_DATA_Cls_L0_OUT_0;
|
||||
AI_DATA_Cls_L0_OUT_0 = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::Init_BOE(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_NF.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_NF error \n");
|
||||
}
|
||||
printf("Init_NF succ----------------------------%d \n", config.nGpuIdx);
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_127Cell(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_127Cell.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_127Cell error \n");
|
||||
bInitSucc_127Cell = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_127Cell = true;
|
||||
}
|
||||
printf("Init_127Cell succ----------------------------%d bInitSucc_127Cell %d\n", config.nGpuIdx, bInitSucc_127Cell);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::Init_BOE_Type2(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_Type2.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_BOE_Type2 error \n");
|
||||
}
|
||||
printf("Init_BOE_Type2 succ----------------------------%d \n", config.nGpuIdx);
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_BOE_UP(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_UP.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_BOE_UP error \n");
|
||||
}
|
||||
printf("Init_BOE_UP succ----------------------------%d \n", config.nGpuIdx);
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_BOE_Chess(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_Chess.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_BOE_Chess error \n");
|
||||
}
|
||||
printf("Init_BOE_Chess succ----------------------------%d \n", config.nGpuIdx);
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_YX_1(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_YX_1.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_YX_1 error \n");
|
||||
}
|
||||
printf("Init_YX_1 succ----------------------------%d \n", config.nGpuIdx);
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_YX_2(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_YX_2.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_YX_2 error \n");
|
||||
}
|
||||
printf("Init_YX_2 succ----------------------------%d \n", config.nGpuIdx);
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::Init_Cls(AIInitConfig config, int ntype)
|
||||
{
|
||||
int re = 0;
|
||||
if (ntype != 1 && ntype != 2)
|
||||
{
|
||||
re = m_pAI_SingleGPU->AI_defect_Cls.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_Cls error \n");
|
||||
}
|
||||
printf("Init_Cls succ------123---------------ntype%d-------%d \n", config.nGpuIdx, ntype);
|
||||
}
|
||||
|
||||
if (ntype == 1)
|
||||
{
|
||||
re = m_pAI_SingleGPU->AI_defect_Cls_L0.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_Cls error \n");
|
||||
}
|
||||
printf("Init_Cls succ-----------AI_defect_Cls_L0-----------------%d \n", config.nGpuIdx);
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_zf(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_zf.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_zf error \n");
|
||||
}
|
||||
|
||||
printf("Init_zf succ----------------------------%d \n", config.nGpuIdx);
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_RE_POL(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_RE_POL.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("AI_defect_RE_POL error \n");
|
||||
bInitSucc_re_Pol = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_re_Pol = true;
|
||||
}
|
||||
printf("AI_defect_RE_POL succ----------------------------%d AI_defect_RE_POL %d\n", config.nGpuIdx, bInitSucc_re_Pol);
|
||||
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_RE_AD(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_RE_AD.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("AI_defect_RE_AD error \n");
|
||||
bInitSucc_re_AD = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_re_AD = true;
|
||||
}
|
||||
printf("AI_defect_RE_AD succ---------------------------%d AI_defect_RE_AD %d\n", config.nGpuIdx, bInitSucc_re_AD);
|
||||
|
||||
return re;
|
||||
}
|
||||
int AI_IMG_deal::Init_Edge_Big(AIInitConfig config)
|
||||
{
|
||||
printf("Init_Edge_Big gpu %d \n", config.nGpuIdx);
|
||||
int re = m_pAI_SingleGPU->AI_defect_Edge_Big.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("AI_defect_Edge_Big error \n");
|
||||
bInitSucc_Edge_big = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_Edge_big = true;
|
||||
}
|
||||
printf("AI_defect_Edge_Big succ-------------------------gpu :%d reuslt : %d\n", config.nGpuIdx, bInitSucc_Edge_big);
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::Init_Edge_Small(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_Edge_Samll.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("AI_defect_Edge_Samll error \n");
|
||||
bInitSucc_Edge_Samll = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_Edge_Samll = true;
|
||||
}
|
||||
printf("AI_defect_Edge_Samll succ---------------------------gpu :%d reuslt : %d\n", config.nGpuIdx, bInitSucc_Edge_Samll);
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::Init_LackPol(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_LackPol.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("Init_LackPol error \n");
|
||||
bInitSucc_LackPol = false;
|
||||
return re;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_LackPol = true;
|
||||
}
|
||||
printf("bInitSucc_LackPol succ---------------------------gpu :%d reuslt: %d\n", config.nGpuIdx, bInitSucc_LackPol);
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::Init_MarkLine(AIInitConfig config)
|
||||
{
|
||||
int re = m_pAI_SingleGPU->AI_defect_MarkLine.model_init(config);
|
||||
if (0 != re)
|
||||
{
|
||||
printf("AI_defect_MarkLine error \n");
|
||||
bInitSucc_MarkLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitSucc_MarkLine = true;
|
||||
}
|
||||
printf("AI_defect_MarkLine succ----------------------------%d AI_defect_RE_POL %d\n", config.nGpuIdx, bInitSucc_MarkLine);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AI_IMG_deal::AICheck_BOE(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_NF_out_0_IMAGE_CHANNEL, AI_NF_out_0_IMAGE_WIDTH, AI_NF_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_NF.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_BOE_Type2(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_NF_out_0_IMAGE_CHANNEL, AI_NF_out_0_IMAGE_WIDTH, AI_NF_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_Type2.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_BOE_Chess(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_NF_out_0_IMAGE_CHANNEL, AI_NF_out_0_IMAGE_WIDTH, AI_NF_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_Chess.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_BOE_UP(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_NF_out_0_IMAGE_CHANNEL, AI_NF_out_0_IMAGE_WIDTH, AI_NF_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_UP.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_YX_1(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_YX_out_0_IMAGE_CHANNEL, AI_YX_out_0_IMAGE_WIDTH, AI_YX_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_YX_1.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_YX_2(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_YX_out_0_IMAGE_CHANNEL, AI_YX_out_0_IMAGE_WIDTH, AI_YX_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_YX_2.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_Cls(cv::Mat inImg, int ntype, float *fmaxScore)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
int cls_num = AI_Cls_out_0_IMAGE_DATA_LENGTH;
|
||||
if (ntype == 1)
|
||||
{
|
||||
cls_num = AI_Cls_14_out_0_IMAGE_DATA_LENGTH;
|
||||
}
|
||||
|
||||
int max_id = 0;
|
||||
if (ntype == 1)
|
||||
{
|
||||
m_pAI_SingleGPU->AI_defect_Cls_L0.model_Cuda_AI_In_1_Out_1_float(pindata, AI_DATA_Cls_L0_OUT_0);
|
||||
max_id = F2softmaxId(AI_DATA_Cls_L0_OUT_0, cls_num, fmaxScore);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pAI_SingleGPU->AI_defect_Cls.model_Cuda_AI_In_1_Out_1_float(pindata, AI_DATA_Cls_OUT_0);
|
||||
max_id = F2softmaxId(AI_DATA_Cls_OUT_0, cls_num, fmaxScore);
|
||||
}
|
||||
// printf("ccccccccc 2\n");
|
||||
// getchar();
|
||||
// std::cout<<"-----------------------------------------max_id="<<max_id<<std::endl;
|
||||
return max_id;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_zf(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_ZF_out_0_IMAGE_CHANNEL, AI_ZF_out_0_IMAGE_WIDTH, AI_ZF_out_0_IMAGE_HEIGHT);
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_zf.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
// printf("AI_defect_NF conver work sum %ld \n", t2 - t1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_127Cell(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
long t1, t2;
|
||||
t1 = CheckUtil::getcurTime();
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(AI_127Cell_out_0_IMAGE_CHANNEL, AI_127Cell_out_0_IMAGE_WIDTH, AI_127Cell_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_127Cell)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_127Cell.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
t2 = CheckUtil::getcurTime();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_RE_POL(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(str_AI_RE_POL_out_0_IMAGE_CHANNEL, str_AI_RE_POL_out_0_IMAGE_WIDTH, str_AI_RE_POL_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_re_Pol)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_RE_POL.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_RE_AD(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(str_AI_RE_AD_out_0_IMAGE_CHANNEL, str_AI_RE_AD_out_0_IMAGE_WIDTH, str_AI_RE_AD_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_re_AD)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_RE_AD.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_Edge_Big(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(str_AI_EDGE_Big_out_0_IMAGE_CHANNEL, str_AI_EDGE_Big_out_0_IMAGE_WIDTH, str_AI_EDGE_Big_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_Edge_big)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_Edge_Big.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_Edge_Small(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(str_AI_EDGE_Small_out_0_IMAGE_CHANNEL, str_AI_EDGE_Small_out_0_IMAGE_WIDTH, str_AI_EDGE_Small_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_Edge_Samll)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_Edge_Samll.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_LackPol(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(str_AI_LOSSPOL_out_0_IMAGE_CHANNEL, str_AI_LOSSPOL_out_0_IMAGE_WIDTH, str_AI_LOSSPOL_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_LackPol)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_LackPol.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_IMG_deal::AICheck_MarkLine(cv::Mat inImg, cv::Mat &outImg_1)
|
||||
{
|
||||
if (inImg.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uchar *pindata = inImg.ptr<uchar>(0);
|
||||
|
||||
outImg_1 = InitMat(str_AI_Mark_out_0_IMAGE_CHANNEL, str_AI_Mark_out_0_IMAGE_WIDTH, str_AI_Mark_out_0_IMAGE_HEIGHT);
|
||||
|
||||
if (!bInitSucc_MarkLine)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
uchar *poutImg_1 = outImg_1.ptr<uchar>(0);
|
||||
m_pAI_SingleGPU->AI_defect_MarkLine.model_Cuda_AI_In_1_Out_1(pindata, poutImg_1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv::Mat AI_IMG_deal::F2M(float *data, int clannel, int w, int h)
|
||||
{
|
||||
cv::Mat dst(h, w, 8 * (clannel - 1));
|
||||
uint8_t *dstp = (uint8_t *)dst.data;
|
||||
int length = w * h * clannel;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (data[i] > 255)
|
||||
{
|
||||
dstp[i] = 256 - data[i] / 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
dstp[i] = uint8_t(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return dst;
|
||||
}
|
||||
cv::Mat AI_IMG_deal::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 AI_IMG_deal::F2softmaxId(float *data, int class_num, float *fmaxScore)
|
||||
{
|
||||
|
||||
// std::cout<<"F2softmaxId()-class_num="<<class_num<<std::endl;
|
||||
|
||||
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,476 @@
|
||||
|
||||
#include "AI_Edge_Algin.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "AI_Mark_Det.h"
|
||||
|
||||
AI_Mark_Det::AI_Mark_Det()
|
||||
{
|
||||
m_bModelSucc = false;
|
||||
CheckUtil::CreateDir("/home/aidlux/BOE/MarkLine/");
|
||||
m_pImageStorage = ImageStorage::getInstance();
|
||||
m_Show_Area = 0;
|
||||
m_Show_Len = 0;
|
||||
m_Len_P1 = cv::Point(0, 0);
|
||||
m_Len_P2 = cv::Point(0, 0);
|
||||
}
|
||||
|
||||
AI_Mark_Det::~AI_Mark_Det()
|
||||
{
|
||||
}
|
||||
int AI_Mark_Det::InitModel_ALL()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
printf("Initialized error \n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
m_bModelSucc = false;
|
||||
|
||||
int re = 0;
|
||||
re = InitModel();
|
||||
if (re != 0)
|
||||
{
|
||||
printf("InitModel error \n");
|
||||
m_bModelSucc = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bModelSucc = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AI_Mark_Det::Detect(const cv::Mat &img, DetConfigResult *pDetConfig)
|
||||
{
|
||||
printf("AI_Mark_Det::Detect \n");
|
||||
cv::Rect searchroi = pDetConfig->searchroi;
|
||||
|
||||
if (searchroi.x < 0)
|
||||
{
|
||||
searchroi.x = 0;
|
||||
}
|
||||
if (searchroi.y < 0)
|
||||
{
|
||||
searchroi.y = 0;
|
||||
}
|
||||
if (searchroi.x + searchroi.width > img.cols)
|
||||
{
|
||||
searchroi.width = img.cols - searchroi.x;
|
||||
}
|
||||
if (searchroi.y + searchroi.width > img.rows)
|
||||
{
|
||||
searchroi.height = img.rows - searchroi.y;
|
||||
}
|
||||
|
||||
// 每个小矩形的大小
|
||||
int rectWidth = 512;
|
||||
int rectHeight = 512;
|
||||
// 重叠区域大小
|
||||
int overlap = 50;
|
||||
|
||||
// 计算步长
|
||||
int stepX = rectWidth - overlap;
|
||||
int stepY = rectHeight - overlap;
|
||||
|
||||
int x_start = searchroi.x;
|
||||
int x_end = searchroi.x + searchroi.width;
|
||||
int y_start = searchroi.y;
|
||||
int y_end = searchroi.y + searchroi.height;
|
||||
if (searchroi.width < 512)
|
||||
{
|
||||
int cx = searchroi.x + searchroi.width * 0.5;
|
||||
x_start = cx - rectWidth * 0.5;
|
||||
x_end = x_start + rectWidth;
|
||||
}
|
||||
if (searchroi.height < 512)
|
||||
{
|
||||
int cy = searchroi.y + searchroi.height * 0.5;
|
||||
y_start = cy - rectHeight * 0.5;
|
||||
y_end = y_start + rectHeight;
|
||||
}
|
||||
|
||||
if (x_start < 0)
|
||||
{
|
||||
x_start = 0;
|
||||
}
|
||||
if (y_start < 0)
|
||||
{
|
||||
y_start = 0;
|
||||
}
|
||||
if (y_start + searchroi.height > img.rows)
|
||||
{
|
||||
y_start = img.rows - searchroi.height;
|
||||
}
|
||||
if (x_start + searchroi.width > img.cols)
|
||||
{
|
||||
x_start = img.cols - searchroi.width;
|
||||
}
|
||||
|
||||
if (y_end > img.rows)
|
||||
{
|
||||
y_end = img.rows;
|
||||
}
|
||||
if (x_end > img.cols)
|
||||
{
|
||||
x_end = img.cols;
|
||||
}
|
||||
|
||||
// cv::Mat showImg;
|
||||
|
||||
// if (true)
|
||||
// {
|
||||
// cv::cvtColor(detSrcImg, showImg, cv::COLOR_GRAY2BGR);
|
||||
// }
|
||||
|
||||
int cut_y_s = y_start;
|
||||
int cut_y_e = cut_y_s + rectHeight;
|
||||
int cut_x_s = x_start;
|
||||
int cut_x_e = cut_x_s + rectWidth;
|
||||
|
||||
bool bb_y = false;
|
||||
bool bb_x = false;
|
||||
|
||||
int w = x_end - x_start;
|
||||
int h = y_end - y_start;
|
||||
if (w < 512)
|
||||
{
|
||||
if (x_start == 0)
|
||||
{
|
||||
x_end = x_start + 512;
|
||||
if (x_end > img.cols)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x_start = x_end - 512;
|
||||
if (x_start < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (h < 512)
|
||||
{
|
||||
if (y_start == 0)
|
||||
{
|
||||
y_end = y_start + 512;
|
||||
if (y_end > img.rows)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
y_start = y_end - 512;
|
||||
if (y_start < 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w = x_end - x_start;
|
||||
h = y_end - y_start;
|
||||
if (w < rectWidth)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (h < rectHeight)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
cv::Rect allroi(x_start, y_start, w, h);
|
||||
cv::Mat allmask = cv::Mat(h, w, CV_8UC1, cv::Scalar(0));
|
||||
|
||||
// printf("y_start %d y_end %d\n", y_start, y_end);
|
||||
// printf("x_start %d x_end %d\n", x_start, x_end);
|
||||
|
||||
static int ki = 0;
|
||||
//
|
||||
for (int y = y_start; y < y_end; y += stepY)
|
||||
{
|
||||
cut_y_s = y;
|
||||
cut_y_e = cut_y_s + rectHeight;
|
||||
if (cut_y_e > y_end)
|
||||
{
|
||||
cut_y_e = y_end;
|
||||
cut_y_s = y_end - rectHeight;
|
||||
bb_y = true;
|
||||
}
|
||||
bb_x = false;
|
||||
for (int x = x_start; x < x_end; x += stepX)
|
||||
{
|
||||
cut_x_s = x;
|
||||
cut_x_e = cut_x_s + rectWidth;
|
||||
if (cut_x_e > x_end)
|
||||
{
|
||||
cut_x_e = x_end;
|
||||
cut_x_s = x_end - rectWidth;
|
||||
bb_x = true;
|
||||
}
|
||||
|
||||
// 定义小矩形
|
||||
cv::Rect smallRect(cut_x_s, cut_y_s, rectWidth, rectHeight);
|
||||
cv::Rect maskrect = smallRect;
|
||||
maskrect.x -= x_start;
|
||||
maskrect.y -= y_start;
|
||||
|
||||
if (!CheckUtil::RoiInImg(smallRect, img))
|
||||
{
|
||||
// printf("img %d %d= \n", img.cols, img.rows);
|
||||
// CheckUtil::printROI(smallRect, "smallRect");
|
||||
continue;
|
||||
}
|
||||
cv::Mat outmask;
|
||||
|
||||
cv::Mat temdet = img(smallRect).clone();
|
||||
|
||||
if (m_bModelSucc)
|
||||
{
|
||||
int re = m_pAIDeal->AICheck_MarkLine(temdet, outmask);
|
||||
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "AI Model POL");
|
||||
// 推理是否成功
|
||||
if (re != 0)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AI_Mark_Det ", "Error POL AI Model Error");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AI_Mark_Det ", "Error POL AI Model Error");
|
||||
continue;
|
||||
}
|
||||
if (outmask.empty())
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AI_Mark_Det ", "Error POL AI Error");
|
||||
continue;
|
||||
}
|
||||
// printf("AI_Mark_Det::Detect ========3333============ \n");
|
||||
|
||||
// printf("img %d %d= \n", allmask.cols, allmask.rows);
|
||||
// CheckUtil::printROI(maskrect, "maskrect---");
|
||||
outmask.copyTo(allmask(maskrect), outmask);
|
||||
|
||||
if (pDetConfig->bsaveprocessimg)
|
||||
{
|
||||
std::string str12 = "/home/aidlux/BOE/MarkLine/" + std::to_string(pDetConfig->ncamID) + "_" + std::to_string(ki) + "_in.png";
|
||||
std::string strmask = "/home/aidlux/BOE/MarkLine/" + std::to_string(pDetConfig->ncamID) + "_" + std::to_string(ki) + "_in_mask.png";
|
||||
ki++;
|
||||
if (ki > 999999)
|
||||
{
|
||||
ki = 0;
|
||||
}
|
||||
cv::imwrite(str12, img(smallRect));
|
||||
cv::imwrite(strmask, outmask);
|
||||
}
|
||||
|
||||
if (bb_x)
|
||||
{
|
||||
break;
|
||||
/* code */
|
||||
}
|
||||
}
|
||||
if (bb_y)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool bf = false;
|
||||
cv::Rect markroi = CheckUtil::getLargestContourROI(allmask, bf);
|
||||
|
||||
if (bf)
|
||||
{
|
||||
pDetConfig->nresult = 0;
|
||||
pDetConfig->markRoi = markroi;
|
||||
|
||||
if (pDetConfig->bsaveprocessimg)
|
||||
{
|
||||
std::string str12 = "/home/aidlux/BOE/MarkLine/Check_big_" + std::to_string(pDetConfig->ncamID) + "_in.png";
|
||||
std::string strmask = "/home/aidlux/BOE/MarkLine/Check_big_" + std::to_string(pDetConfig->ncamID) + "_in_mask.png";
|
||||
// CheckUtil::printROI(allroi, "allroi");
|
||||
// printf("-------------------1111 33 img %d %d\n", img.cols, img.rows);
|
||||
cv::Mat detimg = img(allroi).clone();
|
||||
// printf("-------------------1111 33 \n");
|
||||
cv::rectangle(detimg, pDetConfig->markRoi, cv::Scalar(180), 3);
|
||||
// printf("-------------------1111 444\n");
|
||||
cv::imwrite(str12, detimg);
|
||||
cv::imwrite(strmask, allmask);
|
||||
}
|
||||
|
||||
pDetConfig->markRoi.x += x_start;
|
||||
pDetConfig->markRoi.y += y_start;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_Mark_Det::InitModel()
|
||||
{
|
||||
AIInitConfig config_nf;
|
||||
config_nf.nGpuIdx = m_pOtherDet_Config->nDeviceId;
|
||||
config_nf.engine_file_path = str_AI_Mark_Model_Path;
|
||||
config_nf.bufferList[0].ntype = AIBufferType_IN;
|
||||
config_nf.bufferList[0].ndatalength = str_AI_Mark_IN_0_DATA_LENGTH;
|
||||
config_nf.bufferList[0].strName = "0";
|
||||
|
||||
config_nf.bufferList[1].ntype = AIBufferType_OUT;
|
||||
config_nf.bufferList[1].ndatalength = str_AI_Mark_out_0_DATA_LENGTH;
|
||||
config_nf.bufferList[1].strName = "0";
|
||||
|
||||
return m_pAIDeal->Init_MarkLine(config_nf);
|
||||
}
|
||||
|
||||
cv::Rect AI_Mark_Det::GetCutRoi(cv::Rect &roi, const cv::Mat &img)
|
||||
{
|
||||
int Dst_Width = str_AI_RE_AD_IN_0_IMAGE_WIDTH;
|
||||
int Dst_Height = str_AI_RE_AD_IN_0_IMAGE_HEIGHT;
|
||||
cv::Rect cutroi = cv::Rect(0, 0, 0, 0);
|
||||
if (Dst_Width >= img.cols || Dst_Height >= img.rows)
|
||||
{
|
||||
return cutroi;
|
||||
}
|
||||
if (roi.width >= Dst_Width || roi.height >= Dst_Height)
|
||||
{
|
||||
return cutroi;
|
||||
}
|
||||
|
||||
int centerX = roi.x + roi.width / 2;
|
||||
int centerY = roi.y + roi.height / 2;
|
||||
|
||||
// 构造一个以中心为中心的 128x128 矩形
|
||||
int halfSize = Dst_Width / 2; // 128 / 2
|
||||
int newX = centerX - halfSize;
|
||||
int newY = centerY - halfSize;
|
||||
int newWidth = Dst_Width;
|
||||
int newHeight = Dst_Height;
|
||||
|
||||
// 检查矩形是否越界
|
||||
if (newX < 0)
|
||||
{
|
||||
newX = 0;
|
||||
}
|
||||
if (newY < 0)
|
||||
{
|
||||
newY = 0;
|
||||
}
|
||||
if (newX + newWidth > img.cols)
|
||||
{
|
||||
newX = img.cols - newWidth;
|
||||
}
|
||||
if (newY + newHeight > img.rows)
|
||||
{
|
||||
newY = img.rows - newHeight;
|
||||
}
|
||||
|
||||
// 创建新的矩形
|
||||
cv::Rect newRect(newX, newY, newWidth, newHeight);
|
||||
int add = 3;
|
||||
// 重新计算 roi 在新的矩形中的位置
|
||||
int newRoiX = roi.x - newRect.x - add;
|
||||
int newRoiY = roi.y - newRect.y - add;
|
||||
int newRoiWidth = roi.width + 2 * add;
|
||||
int newRoiHeight = roi.height + 2 * add;
|
||||
|
||||
// 确保新的 roi 在新的矩形内
|
||||
if (newRoiX < 0)
|
||||
{
|
||||
newRoiX = 0;
|
||||
}
|
||||
if (newRoiY < 0)
|
||||
{
|
||||
newRoiY = 0;
|
||||
}
|
||||
if (newRoiX + newRoiWidth > newRect.width)
|
||||
{
|
||||
newRoiWidth = newRect.width - newRoiX;
|
||||
}
|
||||
if (newRoiY + newRoiHeight > newRect.height)
|
||||
{
|
||||
newRoiHeight = newRect.height - newRoiY;
|
||||
}
|
||||
|
||||
// 更新 roi
|
||||
roi = cv::Rect(newRoiX, newRoiY, newRoiWidth, newRoiHeight);
|
||||
|
||||
// 返回新的矩形
|
||||
return newRect;
|
||||
}
|
||||
int AI_Mark_Det::Det_img(const cv::Mat &img, DetConfigResult *pDetConfig)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_Mark_Det::Analysisy(const cv::Mat &maskImg, DetConfigResult *pDetConfig)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_Mark_Det::SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, const cv::Mat &oldmask, DetConfigResult *pDetConfig)
|
||||
{
|
||||
|
||||
// if (inImg.empty() || outImg.empty())
|
||||
// {
|
||||
// return 1;
|
||||
// }
|
||||
// static int saveimgIdx_pol = 0;
|
||||
// static int saveimgIdx_ad = 0;
|
||||
// // 循环存储
|
||||
|
||||
// std::string str_Root = "/home/aidlux/BOE/Second/";
|
||||
// if (pDetConfig->qx_type == CONFIG_QX_NAME_POL_Cell)
|
||||
// {
|
||||
|
||||
// saveimgIdx_pol++;
|
||||
// if (saveimgIdx_pol > 1000)
|
||||
// {
|
||||
// saveimgIdx_pol = 0;
|
||||
// }
|
||||
// str_Root += "POL/POl_" + pDetConfig->strChannel + "_" + std::to_string(saveimgIdx_pol);
|
||||
// }
|
||||
// if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
// {
|
||||
|
||||
// saveimgIdx_ad++;
|
||||
// if (saveimgIdx_ad > 1000)
|
||||
// {
|
||||
// saveimgIdx_ad = 0;
|
||||
// }
|
||||
// str_Root += "AD/AD_" + pDetConfig->strChannel + "_" + std::to_string(saveimgIdx_ad);
|
||||
// }
|
||||
// std::string strIn = str_Root + +"_in.png";
|
||||
// int re = 0;
|
||||
// if (!inImg.empty())
|
||||
// {
|
||||
// re = m_pImageStorage->addImage(strIn, inImg);
|
||||
// }
|
||||
|
||||
// if (re == 0)
|
||||
// {
|
||||
// std::string strmask = str_Root + "_in_mask.png";
|
||||
// if (!outImg.empty())
|
||||
// {
|
||||
// m_pImageStorage->addImage(strmask, outImg, true); // 强制 存储
|
||||
// }
|
||||
|
||||
// std::string stroldmask = str_Root + "_old_mask.png";
|
||||
// if (!oldmask.empty())
|
||||
// {
|
||||
// m_pImageStorage->addImage(stroldmask, oldmask, true); // 强制 存储
|
||||
// }
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,649 @@
|
||||
|
||||
#include "AI_Edge_Algin.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
#include "AI_Second_Det.h"
|
||||
|
||||
AI_SecondDet::AI_SecondDet()
|
||||
{
|
||||
m_bModelSucc_AD = false;
|
||||
m_bModelSucc_POL = false;
|
||||
CheckUtil::CreateDir("/home/aidlux/BOE/Second/POL/");
|
||||
CheckUtil::CreateDir("/home/aidlux/BOE/Second/AD/");
|
||||
m_pImageStorage = ImageStorage::getInstance();
|
||||
m_Show_Area = 0;
|
||||
m_Show_Len = 0;
|
||||
m_Len_P1 = cv::Point(0, 0);
|
||||
m_Len_P2 = cv::Point(0, 0);
|
||||
}
|
||||
|
||||
AI_SecondDet::~AI_SecondDet()
|
||||
{
|
||||
}
|
||||
int AI_SecondDet::InitModel_ALL()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
printf("Initialized error \n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
m_bModelSucc_AD = false;
|
||||
m_bModelSucc_POL = false;
|
||||
int re = 0;
|
||||
re = InitModel_Re_POL();
|
||||
if (re != 0)
|
||||
{
|
||||
printf("InitModel_Re_POL error \n");
|
||||
m_bModelSucc_POL = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bModelSucc_POL = true;
|
||||
}
|
||||
re = InitModel_Re_AD();
|
||||
if (re != 0)
|
||||
{
|
||||
printf("InitModel_Re_AD error \n");
|
||||
m_bModelSucc_AD = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bModelSucc_AD = true;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int AI_SecondDet::Detect(const cv::Mat &img, const cv::Mat &mask, DetConfigResult *pDetConfig)
|
||||
{
|
||||
// 二次求面积长度 功能关闭
|
||||
if (!pDetConfig->pfunction_secondDet->bOpen)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "function colse");
|
||||
return 1;
|
||||
}
|
||||
// cv::Mat temimg = mask.clone();
|
||||
// cv::rectangle(temimg, pDetConfig->qx_roi, cv::Scalar(128, 0, 0));
|
||||
cv::Rect AIroi = GetCutRoi(pDetConfig->qx_roi, img);
|
||||
|
||||
if (AIroi.width <= 0 || AIroi.height <= 0)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "Error Size");
|
||||
return 1;
|
||||
}
|
||||
if (!CheckUtil::RoiInImg(AIroi, img))
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "Error ROI");
|
||||
return 1;
|
||||
}
|
||||
float min_set_param_area = 0;
|
||||
float max_set_param_area = 9999;
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_POL_Cell)
|
||||
{
|
||||
min_set_param_area = pDetConfig->pfunction_secondDet->pol_area_min;
|
||||
max_set_param_area = pDetConfig->pfunction_secondDet->pol_area_max;
|
||||
}
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
{
|
||||
min_set_param_area = pDetConfig->pfunction_secondDet->andian_area_min;
|
||||
max_set_param_area = pDetConfig->pfunction_secondDet->andian_area_max;
|
||||
}
|
||||
float oldarea_mm2 = pDetConfig->old_Area * pDetConfig->fImgage_Scale_X * pDetConfig->fImgage_Scale_Y;
|
||||
if (oldarea_mm2 < min_set_param_area || oldarea_mm2 > max_set_param_area)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "error Area %0.2f out[%0.2f %0.2f] ", oldarea_mm2, min_set_param_area, max_set_param_area);
|
||||
return 1;
|
||||
}
|
||||
if (oldarea_mm2 < pDetConfig->min_DetArea)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "Error Area %0.2f < det param %0.2f ", oldarea_mm2, pDetConfig->min_DetArea);
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "succ Area %0.2f >= min det param %0.2f and in [%0.2f %0.2f] ", oldarea_mm2, pDetConfig->min_DetArea, min_set_param_area, max_set_param_area);
|
||||
}
|
||||
|
||||
cv::Mat detimg = img(AIroi).clone();
|
||||
|
||||
cv::Mat outimg;
|
||||
int re12 = 0;
|
||||
//
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_POL_Cell)
|
||||
{
|
||||
if (pDetConfig->pfunction_secondDet->pol_saveProcessImg)
|
||||
{
|
||||
detimg123 = mask(AIroi).clone();
|
||||
}
|
||||
|
||||
re12 = Det_Pol(detimg, pDetConfig);
|
||||
}
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
{
|
||||
if (pDetConfig->pfunction_secondDet->andian_saveProcessImg)
|
||||
{
|
||||
detimg123 = mask(AIroi).clone();
|
||||
}
|
||||
re12 = Det_AD(detimg, pDetConfig);
|
||||
}
|
||||
if (re12 != 0)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE_POL /AD", "Error ");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_SecondDet::InitModel_Re_POL()
|
||||
{
|
||||
AIInitConfig config_nf;
|
||||
config_nf.nGpuIdx = m_pOtherDet_Config->nDeviceId;
|
||||
config_nf.engine_file_path = str_AI_RE_POL_Model_Path;
|
||||
config_nf.bufferList[0].ntype = AIBufferType_IN;
|
||||
config_nf.bufferList[0].ndatalength = str_AI_RE_POL_IN_0_DATA_LENGTH;
|
||||
config_nf.bufferList[0].strName = str_AI_RE_POL_IN_0_IMAGE_Name;
|
||||
|
||||
config_nf.bufferList[1].ntype = AIBufferType_OUT;
|
||||
config_nf.bufferList[1].ndatalength = str_AI_RE_POL_out_0_DATA_LENGTH;
|
||||
config_nf.bufferList[1].strName = str_AI_RE_POL_out_0_IMAGE_Name;
|
||||
|
||||
return m_pAIDeal->Init_RE_POL(config_nf);
|
||||
}
|
||||
int AI_SecondDet::InitModel_Re_AD()
|
||||
{
|
||||
AIInitConfig config_nf;
|
||||
config_nf.nGpuIdx = m_pOtherDet_Config->nDeviceId;
|
||||
config_nf.engine_file_path = str_AI_RE_AD_Model_Path;
|
||||
config_nf.bufferList[0].ntype = AIBufferType_IN;
|
||||
config_nf.bufferList[0].ndatalength = str_AI_RE_AD_IN_0_DATA_LENGTH;
|
||||
config_nf.bufferList[0].strName = str_AI_RE_POL_IN_0_IMAGE_Name;
|
||||
|
||||
config_nf.bufferList[1].ntype = AIBufferType_OUT;
|
||||
config_nf.bufferList[1].ndatalength = str_AI_RE_AD_out_0_DATA_LENGTH;
|
||||
config_nf.bufferList[1].strName = str_AI_RE_POL_out_0_IMAGE_Name;
|
||||
|
||||
return m_pAIDeal->Init_RE_AD(config_nf);
|
||||
}
|
||||
|
||||
cv::Rect AI_SecondDet::GetCutRoi(cv::Rect &roi, const cv::Mat &img)
|
||||
{
|
||||
int Dst_Width = str_AI_RE_AD_IN_0_IMAGE_WIDTH;
|
||||
int Dst_Height = str_AI_RE_AD_IN_0_IMAGE_HEIGHT;
|
||||
cv::Rect cutroi = cv::Rect(0, 0, 0, 0);
|
||||
if (Dst_Width >= img.cols || Dst_Height >= img.rows)
|
||||
{
|
||||
return cutroi;
|
||||
}
|
||||
if (roi.width >= Dst_Width || roi.height >= Dst_Height)
|
||||
{
|
||||
return cutroi;
|
||||
}
|
||||
|
||||
int centerX = roi.x + roi.width / 2;
|
||||
int centerY = roi.y + roi.height / 2;
|
||||
|
||||
// 构造一个以中心为中心的 128x128 矩形
|
||||
int halfSize = Dst_Width / 2; // 128 / 2
|
||||
int newX = centerX - halfSize;
|
||||
int newY = centerY - halfSize;
|
||||
int newWidth = Dst_Width;
|
||||
int newHeight = Dst_Height;
|
||||
|
||||
// 检查矩形是否越界
|
||||
if (newX < 0)
|
||||
{
|
||||
newX = 0;
|
||||
}
|
||||
if (newY < 0)
|
||||
{
|
||||
newY = 0;
|
||||
}
|
||||
if (newX + newWidth > img.cols)
|
||||
{
|
||||
newX = img.cols - newWidth;
|
||||
}
|
||||
if (newY + newHeight > img.rows)
|
||||
{
|
||||
newY = img.rows - newHeight;
|
||||
}
|
||||
|
||||
// 创建新的矩形
|
||||
cv::Rect newRect(newX, newY, newWidth, newHeight);
|
||||
int add = 3;
|
||||
// 重新计算 roi 在新的矩形中的位置
|
||||
int newRoiX = roi.x - newRect.x - add;
|
||||
int newRoiY = roi.y - newRect.y - add;
|
||||
int newRoiWidth = roi.width + 2 * add;
|
||||
int newRoiHeight = roi.height + 2 * add;
|
||||
|
||||
// 确保新的 roi 在新的矩形内
|
||||
if (newRoiX < 0)
|
||||
{
|
||||
newRoiX = 0;
|
||||
}
|
||||
if (newRoiY < 0)
|
||||
{
|
||||
newRoiY = 0;
|
||||
}
|
||||
if (newRoiX + newRoiWidth > newRect.width)
|
||||
{
|
||||
newRoiWidth = newRect.width - newRoiX;
|
||||
}
|
||||
if (newRoiY + newRoiHeight > newRect.height)
|
||||
{
|
||||
newRoiHeight = newRect.height - newRoiY;
|
||||
}
|
||||
|
||||
// 更新 roi
|
||||
roi = cv::Rect(newRoiX, newRoiY, newRoiWidth, newRoiHeight);
|
||||
|
||||
// 返回新的矩形
|
||||
return newRect;
|
||||
}
|
||||
int AI_SecondDet::Det_Pol(const cv::Mat &img, DetConfigResult *pDetConfig)
|
||||
{
|
||||
int re = 0;
|
||||
cv::Mat outimg;
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", " POL start");
|
||||
// 如果 有面积或长度功能 开启,就进行推理
|
||||
// if (pDetConfig->pfunction_secondDet->pol_Open_len || pDetConfig->pfunction_secondDet->pol_Open_area)
|
||||
{
|
||||
// 模型初始化是否成功
|
||||
if (m_bModelSucc_POL)
|
||||
{
|
||||
re = m_pAIDeal->AICheck_RE_POL(img, outimg);
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "AI Model POL");
|
||||
// 推理是否成功
|
||||
if (re != 0)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE ", "Error POL AI Model Error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE ", "Error POL AI Model Error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "POL Param Close ");
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
if (outimg.empty())
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE ", "Error POL AI Error");
|
||||
return 1;
|
||||
}
|
||||
cv::Mat AnalysisyImg = outimg(pDetConfig->qx_roi).clone();
|
||||
m_Show_Area = pDetConfig->old_Area;
|
||||
m_Show_Len = pDetConfig->old_len;
|
||||
// 开始分析mask;
|
||||
re = Analysisy(AnalysisyImg, pDetConfig);
|
||||
m_Len_P1.x += pDetConfig->qx_roi.x;
|
||||
m_Len_P1.y += pDetConfig->qx_roi.y;
|
||||
|
||||
m_Len_P2.x += pDetConfig->qx_roi.x;
|
||||
m_Len_P2.y += pDetConfig->qx_roi.y;
|
||||
|
||||
// 存储中间过程图片
|
||||
if (pDetConfig->pfunction_secondDet->pol_saveProcessImg)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
cv::rectangle(outimg, pDetConfig->qx_roi, cv::Scalar(128, 0, 0));
|
||||
cv::rectangle(detimg123, pDetConfig->qx_roi, cv::Scalar(128, 0, 0));
|
||||
|
||||
cv::line(outimg, m_Len_P1, m_Len_P2, cv::Scalar(128, 0, 0));
|
||||
|
||||
{
|
||||
char buffer[128];
|
||||
sprintf(buffer, " oA %d -> nA %d ",
|
||||
pDetConfig->old_Area, m_Show_Area);
|
||||
std::string st1 = buffer;
|
||||
cv::Point p(0, 10);
|
||||
cv::putText(outimg, st1, p, cv::FONT_HERSHEY_SIMPLEX, 0.35, cv::Scalar(200, 0, 255), 0.35, 1, 0);
|
||||
|
||||
sprintf(buffer, " oL %0.2f -> nL %0.2f ",
|
||||
pDetConfig->old_len, m_Show_Len);
|
||||
st1 = buffer;
|
||||
cv::Point p2(0, 20);
|
||||
cv::putText(outimg, st1, p2, cv::FONT_HERSHEY_SIMPLEX, 0.35, cv::Scalar(200, 0, 255), 0.35, 1, 0);
|
||||
}
|
||||
}
|
||||
SaveProcessImg(img, outimg, detimg123, pDetConfig);
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
int AI_SecondDet::Det_AD(const cv::Mat &img, DetConfigResult *pDetConfig)
|
||||
{
|
||||
|
||||
int re = 0;
|
||||
cv::Mat outimg;
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", " AD start");
|
||||
// 如果 有面积或长度功能 开启,就进行推理
|
||||
// if (pDetConfig->pfunction_secondDet->andian_Open_len || pDetConfig->pfunction_secondDet->andian_Open_area)
|
||||
{
|
||||
// 模型初始化是否成功
|
||||
if (m_bModelSucc_AD)
|
||||
{
|
||||
re = m_pAIDeal->AICheck_RE_AD(img, outimg);
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "AI Model AD");
|
||||
// 推理是否成功
|
||||
if (re != 0)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE ", "Error AD AI Model Error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE ", "Error AD AI Model Error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "AD Param Close ");
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
if (outimg.empty())
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE ", "Error AD AI Error");
|
||||
return 1;
|
||||
}
|
||||
if (!CheckUtil::RoiInImg(pDetConfig->qx_roi, outimg))
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "qx roi Error");
|
||||
return 1;
|
||||
}
|
||||
cv::Mat AnalysisyImg = outimg(pDetConfig->qx_roi).clone();
|
||||
|
||||
m_Show_Area = pDetConfig->old_Area;
|
||||
m_Show_Len = pDetConfig->old_len;
|
||||
// 开始分析mask;
|
||||
re = Analysisy(AnalysisyImg, pDetConfig);
|
||||
|
||||
m_Len_P1.x += pDetConfig->qx_roi.x;
|
||||
m_Len_P1.y += pDetConfig->qx_roi.y;
|
||||
|
||||
m_Len_P2.x += pDetConfig->qx_roi.x;
|
||||
m_Len_P2.y += pDetConfig->qx_roi.y;
|
||||
|
||||
if (pDetConfig->pfunction_secondDet->andian_saveProcessImg)
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
cv::rectangle(outimg, pDetConfig->qx_roi, cv::Scalar(128, 0, 0));
|
||||
cv::rectangle(detimg123, pDetConfig->qx_roi, cv::Scalar(128, 0, 0));
|
||||
cv::line(outimg, m_Len_P1, m_Len_P2, cv::Scalar(128, 0, 0));
|
||||
{
|
||||
char buffer[128];
|
||||
sprintf(buffer, " oA %d -> nA %d ",
|
||||
pDetConfig->old_Area, m_Show_Area);
|
||||
std::string st1 = buffer;
|
||||
cv::Point p(0, 10);
|
||||
cv::putText(outimg, st1, p, cv::FONT_HERSHEY_SIMPLEX, 0.35, cv::Scalar(200, 0, 255), 0.35, 1, 0);
|
||||
|
||||
sprintf(buffer, " oL %0.2f -> nL %0.2f ",
|
||||
pDetConfig->old_len, m_Show_Len);
|
||||
st1 = buffer;
|
||||
cv::Point p2(0, 20);
|
||||
cv::putText(outimg, st1, p2, cv::FONT_HERSHEY_SIMPLEX, 0.35, cv::Scalar(200, 0, 255), 0.35, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SaveProcessImg(img, outimg, detimg123, pDetConfig);
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
int AI_SecondDet::Analysisy(const cv::Mat &maskImg, DetConfigResult *pDetConfig)
|
||||
{
|
||||
// 存储轮廓
|
||||
std::vector<std::vector<cv::Point>> contours;
|
||||
// 存储每个轮廓的层级
|
||||
std::vector<cv::Vec4i> hierarchy;
|
||||
|
||||
// 寻找轮廓
|
||||
cv::findContours(maskImg, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
|
||||
|
||||
double maxArea = 0;
|
||||
int maxIndex = -1;
|
||||
|
||||
// 遍历每个轮廓,计算面积并找出最大的面积
|
||||
for (size_t i = 0; i < contours.size(); i++)
|
||||
{
|
||||
double area = cv::contourArea(contours[i]);
|
||||
if (area > maxArea)
|
||||
{
|
||||
maxArea = area;
|
||||
maxIndex = i;
|
||||
}
|
||||
}
|
||||
if (maxIndex < 0)
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "second mask is error");
|
||||
return 1;
|
||||
/* code */
|
||||
}
|
||||
bool barea = false;
|
||||
bool blen = false;
|
||||
int oldArea = pDetConfig->old_Area;
|
||||
float oldLen = pDetConfig->old_len;
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_POL_Cell)
|
||||
{
|
||||
barea = pDetConfig->pfunction_secondDet->pol_Open_area;
|
||||
blen = pDetConfig->pfunction_secondDet->pol_Open_len;
|
||||
}
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
{
|
||||
barea = pDetConfig->pfunction_secondDet->andian_Open_area;
|
||||
blen = pDetConfig->pfunction_secondDet->andian_Open_len;
|
||||
}
|
||||
// 计算面积
|
||||
// if (barea)
|
||||
{
|
||||
int maxContourPixelCount = 0;
|
||||
if (maxIndex >= 0)
|
||||
{
|
||||
cv::Mat mask = cv::Mat::zeros(maskImg.size(), CV_8UC1);
|
||||
cv::drawContours(mask, contours, maxIndex, cv::Scalar(255), cv::FILLED); // 绘制轮廓填充区域
|
||||
maxContourPixelCount = cv::countNonZero(mask); // 计算填充区域的像素个数
|
||||
}
|
||||
m_Show_Area = maxContourPixelCount;
|
||||
|
||||
if (barea)
|
||||
{
|
||||
if (maxContourPixelCount > 0 && maxContourPixelCount < oldArea)
|
||||
{
|
||||
pDetConfig->new_Area = maxContourPixelCount;
|
||||
}
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "Use New Area :old area %d (pixel) new %d", oldArea, pDetConfig->new_Area);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", " Not Use Area :old area %d (pixel) new %d", oldArea, maxContourPixelCount);
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Area", "Cal Area is Close");
|
||||
// }
|
||||
|
||||
// 计算长度
|
||||
// if (blen)
|
||||
{
|
||||
cv::RotatedRect rect = cv::minAreaRect(contours[maxIndex]);
|
||||
|
||||
// 获取最小外接矩形的尺寸
|
||||
float width = rect.size.width;
|
||||
float height = rect.size.height;
|
||||
|
||||
Point2f vertices[4];
|
||||
rect.points(vertices);
|
||||
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
{
|
||||
float len1 = sqrt((vertices[0].x - vertices[1].x) * (vertices[0].x - vertices[1].x) +
|
||||
(vertices[0].y - vertices[1].y) * (vertices[0].y - vertices[1].y));
|
||||
|
||||
float len2 = sqrt((vertices[2].x - vertices[1].x) * (vertices[2].x - vertices[1].x) +
|
||||
(vertices[2].y - vertices[1].y) * (vertices[2].y - vertices[1].y));
|
||||
|
||||
if (len1 > len2)
|
||||
{
|
||||
m_Len_P1.x = vertices[0].x;
|
||||
m_Len_P1.y = vertices[0].y;
|
||||
|
||||
m_Len_P2.x = vertices[1].x;
|
||||
m_Len_P2.y = vertices[1].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Len_P1.x = vertices[2].x;
|
||||
m_Len_P1.y = vertices[2].y;
|
||||
|
||||
m_Len_P2.x = vertices[1].x;
|
||||
m_Len_P2.y = vertices[1].y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Len_P1.x = vertices[2].x;
|
||||
m_Len_P1.y = vertices[2].y;
|
||||
|
||||
m_Len_P2.x = vertices[0].x;
|
||||
m_Len_P2.y = vertices[0].y;
|
||||
}
|
||||
|
||||
vector<Point2f> newcont;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
Point2f p;
|
||||
p.x = vertices[i].x * pDetConfig->fImgage_Scale_X;
|
||||
p.y = vertices[i].y * pDetConfig->fImgage_Scale_Y;
|
||||
newcont.push_back(p);
|
||||
}
|
||||
vector<vector<Point2f>> contours_New;
|
||||
contours_New.push_back(newcont);
|
||||
// Recreate the rotated rectangle with scaled vertices
|
||||
RotatedRect scaledRect = minAreaRect(contours_New[0]);
|
||||
|
||||
// Calculate scaled width and height
|
||||
width = scaledRect.size.width;
|
||||
height = scaledRect.size.height;
|
||||
float new_len = width;
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
{
|
||||
if (width > height)
|
||||
{
|
||||
new_len = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_len = height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_len = sqrt(width * width + height * height);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (width > height)
|
||||
{
|
||||
new_len = width;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_len = height;
|
||||
}
|
||||
}
|
||||
|
||||
// printf("oldLen %f new_len %f \n", oldLen, new_len);
|
||||
m_Show_Len = new_len;
|
||||
if (blen)
|
||||
{
|
||||
if (new_len > 0 && new_len < oldLen)
|
||||
{
|
||||
pDetConfig->new_len = new_len;
|
||||
}
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Len", "Use New Len :old Len %f (mm) new %f", oldLen, pDetConfig->new_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Len", " Not Use Len :old Len %f (mm) new %f", oldLen, new_len);
|
||||
}
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// m_pTemCheck->AddCheckstr(PrintLevel_3, DET_LOG_LEVEL_3, "AICheck_RE Len", "Cal Len is Close");
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AI_SecondDet::SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, const cv::Mat &oldmask, DetConfigResult *pDetConfig)
|
||||
{
|
||||
|
||||
if (inImg.empty() || outImg.empty())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
static int saveimgIdx_pol = 0;
|
||||
static int saveimgIdx_ad = 0;
|
||||
// 循环存储
|
||||
|
||||
std::string str_Root = "/home/aidlux/BOE/Second/";
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_POL_Cell)
|
||||
{
|
||||
|
||||
saveimgIdx_pol++;
|
||||
if (saveimgIdx_pol > 1000)
|
||||
{
|
||||
saveimgIdx_pol = 0;
|
||||
}
|
||||
str_Root += "POL/POl_" + pDetConfig->strChannel + "_" + std::to_string(saveimgIdx_pol);
|
||||
}
|
||||
if (pDetConfig->qx_type == CONFIG_QX_NAME_AD)
|
||||
{
|
||||
|
||||
saveimgIdx_ad++;
|
||||
if (saveimgIdx_ad > 1000)
|
||||
{
|
||||
saveimgIdx_ad = 0;
|
||||
}
|
||||
str_Root += "AD/AD_" + pDetConfig->strChannel + "_" + std::to_string(saveimgIdx_ad);
|
||||
}
|
||||
std::string strIn = str_Root + +"_in.png";
|
||||
int re = 0;
|
||||
if (!inImg.empty())
|
||||
{
|
||||
re = m_pImageStorage->addImage(strIn, inImg);
|
||||
}
|
||||
|
||||
if (re == 0)
|
||||
{
|
||||
std::string strmask = str_Root + "_in_mask.png";
|
||||
if (!outImg.empty())
|
||||
{
|
||||
m_pImageStorage->addImage(strmask, outImg, true); // 强制 存储
|
||||
}
|
||||
|
||||
std::string stroldmask = str_Root + "_old_mask.png";
|
||||
if (!oldmask.empty())
|
||||
{
|
||||
m_pImageStorage->addImage(stroldmask, oldmask, true); // 强制 存储
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,560 @@
|
||||
#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))
|
||||
|
||||
//-------------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 (1)
|
||||
{
|
||||
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);
|
||||
}
|
||||
int GetBlobsFromImg(ERROR_DOTS_BLOBS *blobs_0, ERROR_DOTS_BLOBS *blobs_1, ERROR_DOTS_BLOBS *blobs_2, unsigned char *pB, unsigned char *pr, unsigned char *pc, int width, int height, int obj)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int GetBlobsFromIm_1(ERROR_DOTS_BLOBS *blobs, unsigned char *pcropdata, unsigned char *pcropConstructdata, unsigned char *pGrayErrordata, unsigned char *pRGBErrordata, int width, int height)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
int GetBlobsFromIm_2(ERROR_DOTS_BLOBS *blobs, unsigned char *pcropdata, unsigned char *pcropConstructdata, unsigned char *pGrayErrordata, unsigned char *pRGBErrordata, unsigned char *pGrayMaskdata, int width, int height, int ndiffValueT)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobsFromIm_All(ERROR_DOTS_BLOBS *blobs, unsigned char *pcropdata, unsigned char *pcropConstructdata, unsigned char *pGrayErrordata, unsigned char *pRGBErrordata, unsigned char *pGrayMaskdata, int width, int height, int ndiffValueT)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobsFromIm_single(ERROR_DOTS_BLOBS *blobs, unsigned char *pcropdata, unsigned char *pcropConstructdata, unsigned char *pErrordata, int nstartPos, int nstep, int npitch, int nErrorType, unsigned char *pGrayMaskdata, int width, int height, int ndiffValueT)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobsFromIm_All_onemask(ERROR_DOTS_BLOBS *blobs, unsigned char *pcropdata, unsigned char *pRGBErrordata, unsigned char *pGrayMaskdata, int width, int height, int ndiffValueT)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int GetBlobsFromIm_single_onemask(ERROR_DOTS_BLOBS *blobs, unsigned char *pcropdata, unsigned char *pErrordata, int AndValue, int npitch, int nErrorType, unsigned char *pGrayMaskdata, int width, int height, int ndiffValueT)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
// 当前行和前面行合并
|
||||
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;
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
|
||||
#include "CUDA_Det.cuh"
|
||||
|
||||
__global__ void test_print()
|
||||
{
|
||||
|
||||
printf("Hello World!\n");
|
||||
int index = threadIdx.z * blockDim.x * blockDim.y +
|
||||
threadIdx.y * blockDim.x +
|
||||
threadIdx.x;
|
||||
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
printf("blockIdx.x %d blockDim.x %d, threadIdx.x %d\n", blockIdx.x, blockDim.x, threadIdx.x);
|
||||
printf("block idx: (%3d, %3d, %3d), thread idx: %3d, cord: (%3d, %3d)\n",
|
||||
blockIdx.z, blockIdx.y, blockIdx.x,
|
||||
index, x, y);
|
||||
}
|
||||
__global__ void ucharToFloat(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(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 wrap_test_print()
|
||||
{
|
||||
test_print<<<5, 6>>>();
|
||||
cudaDeviceSynchronize();
|
||||
return;
|
||||
}
|
||||
|
||||
void Cuda_ucharToFloat(const unsigned char *input, float *output, int size)
|
||||
{
|
||||
cudaDeviceSynchronize();
|
||||
int blockSize = 1024;
|
||||
int numBlocks = (size + blockSize - 1) / blockSize;
|
||||
ucharToFloat<<<numBlocks, blockSize>>>(input, output, size);
|
||||
}
|
||||
|
||||
void Cuda_FloatTouchar(const float *input, unsigned char *output, int size)
|
||||
{
|
||||
cudaDeviceSynchronize();
|
||||
int blockSize = 1024;
|
||||
int numBlocks = (size + blockSize - 1) / blockSize;
|
||||
floatToUchar<<<numBlocks, blockSize>>>(input, output, size);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -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,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();
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
#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() > 20 && !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,103 @@
|
||||
|
||||
#include "OtherDetect.h"
|
||||
#include "CheckErrorCodeDefine.hpp"
|
||||
|
||||
AIDetectBase ::AIDetectBase(/* args */)
|
||||
{
|
||||
m_pOtherDet_Config = NULL;
|
||||
m_pAIDeal = NULL;
|
||||
m_bInitialized = false;
|
||||
m_bModelSucc = false;
|
||||
}
|
||||
|
||||
AIDetectBase ::~AIDetectBase()
|
||||
{
|
||||
}
|
||||
int AIDetectBase ::Init(OtherDet_Config *pOtherDet_Config)
|
||||
{
|
||||
m_pOtherDet_Config = pOtherDet_Config;
|
||||
m_pAIDeal = pOtherDet_Config->pAIDeal;
|
||||
m_pTemCheck = pOtherDet_Config->pTemCheck;
|
||||
m_bInitialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
LackPolDet::LackPolDet(/* args */)
|
||||
{
|
||||
}
|
||||
|
||||
LackPolDet::~LackPolDet()
|
||||
{
|
||||
}
|
||||
int LackPolDet::Init_LackPol()
|
||||
{
|
||||
|
||||
AIInitConfig config_nf;
|
||||
config_nf.nGpuIdx = m_pOtherDet_Config->nDeviceId;
|
||||
config_nf.engine_file_path = str_AI_LOSSPOL_Model_Path;
|
||||
config_nf.bufferList[0].ntype = AIBufferType_IN;
|
||||
config_nf.bufferList[0].ndatalength = str_AI_LOSSPOL_IN_0_DATA_LENGTH;
|
||||
|
||||
config_nf.bufferList[1].ntype = AIBufferType_OUT;
|
||||
config_nf.bufferList[1].ndatalength = str_AI_LOSSPOL_out_0_DATA_LENGTH;
|
||||
|
||||
int re = m_pAIDeal->Init_LackPol(config_nf);
|
||||
|
||||
return re;
|
||||
}
|
||||
int LackPolDet::InitModel_ALL()
|
||||
{
|
||||
m_bModelSucc = false;
|
||||
int re = Init_LackPol();
|
||||
if (re != 0)
|
||||
{
|
||||
printf("AI_Edge_Algin Init_LackPol Error \n");
|
||||
return re;
|
||||
}
|
||||
m_bModelSucc = true;
|
||||
return 0;
|
||||
}
|
||||
int LackPolDet::Detect(const cv::Mat &img, DetConfig *pDetConfig, cv::Mat &outMask)
|
||||
{
|
||||
cv::Mat inImg;
|
||||
cv::Size sz;
|
||||
cv::Mat detmask_size;
|
||||
if (pDetConfig == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (img.empty())
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
if (pDetConfig->detMaskImg.empty())
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (!m_bModelSucc)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
sz.width = str_AI_LOSSPOL_IN_0_IMAGE_WIDTH;
|
||||
sz.height = str_AI_LOSSPOL_IN_0_IMAGE_HEIGHT;
|
||||
|
||||
cv::resize(img, inImg, sz, 0, 0, cv::INTER_AREA);
|
||||
cv::resize(pDetConfig->detMaskImg, detmask_size, sz, 0, 0, cv::INTER_AREA);
|
||||
m_pAIDeal->AICheck_LackPol(inImg, outMask);
|
||||
|
||||
if (pDetConfig->bSaveResultImg)
|
||||
{
|
||||
if (!inImg.empty())
|
||||
{
|
||||
cv::imwrite(pDetConfig->strChannel + "_LackPol_In.png", inImg);
|
||||
}
|
||||
if (!outMask.empty())
|
||||
{
|
||||
cv::imwrite(pDetConfig->strChannel + "_LackPol_out.png", outMask);
|
||||
}
|
||||
}
|
||||
|
||||
outMask.setTo(0, detmask_size);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* FileName:CoreLogicFactory.cpp
|
||||
* Version:V1.0
|
||||
* Description:
|
||||
* Created On:Mon Sep 10 11:13:16 UTC 2018
|
||||
* Modified date:
|
||||
* Author:Sky
|
||||
*/
|
||||
#include "SingleGPU.h"
|
||||
|
||||
AI_SingleGPU *AI_SingleGPU::m_pInstance[MAX_GPU_NUMBER] = {nullptr};
|
||||
|
||||
AI_SingleGPU::CGarbo AI_SingleGPU::m_garbo;
|
||||
AI_SingleGPU::AI_SingleGPU(int nGpuIdx)
|
||||
{
|
||||
m_nGpuIdx = nGpuIdx;
|
||||
cout << "AI_SingleGPU GPU:" << m_nGpuIdx << " create succ" << endl;
|
||||
}
|
||||
|
||||
AI_SingleGPU::~AI_SingleGPU()
|
||||
{
|
||||
// cout << "单例对象销毁!" << endl;
|
||||
|
||||
}
|
||||
|
||||
AI_SingleGPU *AI_SingleGPU::GetInstance(int nGpuIdx)
|
||||
{
|
||||
if (nGpuIdx < 0 || nGpuIdx >= MAX_GPU_NUMBER)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (nullptr == m_pInstance[nGpuIdx])
|
||||
{
|
||||
std::mutex mutex_;
|
||||
mutex_.lock(); // 需要自己采用适当的互斥方式
|
||||
if (nullptr == m_pInstance[nGpuIdx])
|
||||
{
|
||||
m_pInstance[nGpuIdx] = new AI_SingleGPU(nGpuIdx);
|
||||
}
|
||||
mutex_.unlock();
|
||||
}
|
||||
return m_pInstance[nGpuIdx];
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
#限定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(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(ConfigModule)
|
||||
MESSAGE("")
|
||||
|
||||
# CommonUtil
|
||||
add_subdirectory(AlgorithmModule)
|
||||
MESSAGE("")
|
||||
|
||||
|
||||
@ -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,19 @@
|
||||
/*
|
||||
* @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 "ConfigBase.h"
|
||||
#include "ConfigInstance.h"
|
||||
|
||||
ConfigBase* ConfigBase::GetInstance()
|
||||
{
|
||||
return (ConfigBase*)new ConfigInstance();
|
||||
}
|
||||
bool compareBylay(const RegionConfigST &a, const RegionConfigST &b)
|
||||
{
|
||||
return a.basicInfo.lay < b.basicInfo.lay;
|
||||
}
|
||||
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* @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 "ConfigInstance.h"
|
||||
|
||||
ConfigInstance::ConfigInstance()
|
||||
{
|
||||
m_ErrorValue = ERROR_Type_Ok;
|
||||
}
|
||||
|
||||
ConfigInstance::~ConfigInstance()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
// for (int i = 0; i < m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.size(); i++)
|
||||
// {
|
||||
// m_AnalysisyConfig.commonCheckConfig.nodeConfigArr.at(i).ToSheildMaskImg();
|
||||
// // 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)
|
||||
{
|
||||
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 @@
|
||||
#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,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}")
|
||||
Loading…
Reference in new issue