阶段备份
This commit is contained in:
Binary file not shown.
@@ -16,7 +16,7 @@ bool pinHalconEvaluate(std::shared_ptr <detData> data, cv::Rect& Result, cv::Mat
|
||||
std::vector<handdleAI::Bbox> pinDetEvaluate(std::shared_ptr <detData> data, cv::Mat& src, handleAiModelManager* _handleAiModelManager)
|
||||
{
|
||||
std::vector<handdleAI::Bbox> result;
|
||||
handleAiModelDet* detPtr = _handleAiModelManager->getDetModel(data->_productDataStruct.handleAiData.detModelName);
|
||||
handleAiModelDet* detPtr = _handleAiModelManager->getDetModel("connectorDet.BHD");
|
||||
if (detPtr == nullptr)
|
||||
return std::vector<handdleAI::Bbox>();
|
||||
detPtr->Evaluate(src, result);
|
||||
@@ -43,215 +43,7 @@ std::vector<handdleAI::Bbox> getpinHandleAiEvaluateRect(std::shared_ptr <detData
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//HALCON检测
|
||||
std::vector<cv::Rect> getTopPoints(std::vector<cv::Rect>& rectangles)
|
||||
{
|
||||
double minX, maxX, avgX;
|
||||
double minY, maxY, avgY;
|
||||
for (auto data : rectangles)
|
||||
{
|
||||
std::cout << data.y << std::endl;
|
||||
}
|
||||
return std::vector<cv::Rect>();
|
||||
}
|
||||
void halconEvaluate(std::shared_ptr <detData> data, std::vector<handdleAI::Bbox>connectorPos, std::vector<cv::Mat>& halconImgResult)
|
||||
{
|
||||
cv::Mat src = data->oriImgs[0];
|
||||
for (auto& box : connectorPos)
|
||||
{
|
||||
cv::Mat halconMatResult;
|
||||
bool halconBoolResult = pinHalconEvaluate(data, BboxToRect(box), src, halconMatResult, 5);
|
||||
if (halconBoolResult == true)
|
||||
halconImgResult.push_back(halconMatResult);//HALCON检测结果
|
||||
}
|
||||
}
|
||||
bool pinHalconEvaluate(std::shared_ptr <detData> data, cv::Rect& Result, cv::Mat& src, cv::Mat& out, int productType)
|
||||
{
|
||||
#pragma region halcon变量定义
|
||||
//测量
|
||||
HObject ho_in_Image;
|
||||
HObject ho_in_Image2;
|
||||
HTuple hv_in_ShapePath;
|
||||
HTuple hv_in_Parameter;
|
||||
HTuple hv_out_Pings_X;
|
||||
HTuple hv_out_Pings_Y;
|
||||
HTuple hv_out_NG_Pings_X;
|
||||
HTuple hv_out_NG_Pings_Y;
|
||||
HTuple hv_out_Pings_Num;
|
||||
HTuple hv_out_NG_Pings_Num;
|
||||
HTuple hv_out_Flag_INS;
|
||||
HObject hv_out_Img_INS;
|
||||
//ROI
|
||||
HTuple hv_out_ROI_Value;
|
||||
HTuple hv_out_Flag_ROI;
|
||||
#pragma endregion
|
||||
cv::Mat halconImg = src(cv::Rect(Result.x, Result.y, Result.width, Result.height)).clone();
|
||||
ho_in_Image = MatToHObject(halconImg);
|
||||
//hv_in_Parameter
|
||||
//[0]-产品种类; 1A正面 2A反面 3B正面 4C正面
|
||||
//[1]-图像序号第一位;
|
||||
//[2]-图像序号第二位;
|
||||
//[3]-3d相机精度(mm);
|
||||
//[4]-ping针偏移判NG阈值(mm);
|
||||
//[5]-切图存图开关
|
||||
hv_in_Parameter.Append(3);
|
||||
hv_in_Parameter.Append(1);
|
||||
hv_in_Parameter.Append(1);
|
||||
hv_in_Parameter.Append(0.0135);
|
||||
hv_in_Parameter.Append(0.2);
|
||||
hv_in_Parameter.Append(2);
|
||||
|
||||
hv_in_ShapePath = "./halconModel";
|
||||
//
|
||||
HTuple hv_in_FilePath = ".\\halconFiles\\";
|
||||
HTuple hv_out_OK_Pings;
|
||||
HTuple hv_out_NG_Pings;
|
||||
//
|
||||
switch (productType)
|
||||
{
|
||||
case 0:
|
||||
Pings_Inspection_2_Front_New(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_Pings_X,
|
||||
&hv_out_Pings_Y, &hv_out_NG_Pings_X, &hv_out_NG_Pings_Y, &hv_out_Pings_Num,
|
||||
&hv_out_NG_Pings_Num, &hv_out_Flag_INS, &hv_out_Img_INS);
|
||||
break;
|
||||
case 3:
|
||||
Pings_Inspection_1_Back_New(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_Pings_X,
|
||||
&hv_out_Pings_Y, &hv_out_NG_Pings_X, &hv_out_NG_Pings_Y, &hv_out_Pings_Num,
|
||||
&hv_out_NG_Pings_Num, &hv_out_Flag_INS, &hv_out_Img_INS);
|
||||
case 2:
|
||||
Pings_Inspection_1_Front_New(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_Pings_X,
|
||||
&hv_out_Pings_Y, &hv_out_NG_Pings_X, &hv_out_NG_Pings_Y, &hv_out_Pings_Num,
|
||||
&hv_out_NG_Pings_Num, &hv_out_Flag_INS, &hv_out_Img_INS);
|
||||
break;
|
||||
case 5:
|
||||
Inspenction_stargazer_pin(ho_in_Image, hv_in_FilePath, &hv_out_OK_Pings, &hv_out_NG_Pings,
|
||||
&hv_out_Flag_INS);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
int flag = hv_out_Flag_INS.D();
|
||||
if (flag == 1)
|
||||
{
|
||||
if (productType == 5)
|
||||
{
|
||||
halconImg.copyTo(out);
|
||||
if (out.channels() == 1)
|
||||
cv::cvtColor(out, out, cv::COLOR_GRAY2BGR);
|
||||
int hv_out_OK_PingsSize = hv_out_OK_Pings.Length(), hv_out_NG_PingsSize = hv_out_NG_Pings.Length();
|
||||
std::cout << "OKSize" << hv_out_OK_PingsSize << "NGSize" << hv_out_NG_PingsSize << std::endl;
|
||||
std::vector<cv::Rect>okPos, ngPos, AllPoints;
|
||||
for (int i = 0; i < hv_out_OK_PingsSize / 4; i++)
|
||||
{
|
||||
cv::Rect rect(
|
||||
hv_out_OK_Pings[i * 4].D(),
|
||||
hv_out_OK_Pings[i * 4 + 1].D(),
|
||||
hv_out_OK_Pings[i * 4 + 2].D(),
|
||||
hv_out_OK_Pings[i * 4 + 3].D());
|
||||
okPos.push_back(rect);
|
||||
AllPoints.push_back(rect);
|
||||
}
|
||||
for (int i = 0; i < hv_out_NG_PingsSize / 4; i++)
|
||||
{
|
||||
cv::Rect rect(
|
||||
hv_out_NG_Pings[i + 1].D(),
|
||||
hv_out_NG_Pings[i].D(),
|
||||
hv_out_NG_Pings[i + 4].D(),
|
||||
hv_out_NG_Pings[i + 3].D());
|
||||
ngPos.push_back(rect);
|
||||
AllPoints.push_back(rect);
|
||||
}
|
||||
//画线
|
||||
//halconPaint(out, AllPoints);
|
||||
}
|
||||
else
|
||||
out = HObject2Mat(hv_out_Img_INS);
|
||||
return true;
|
||||
}
|
||||
if (hv_out_Pings_X.Length() > 0)
|
||||
data->halconOK = false;
|
||||
std::cout << "HALCON FAILURE" << std::endl;
|
||||
out = halconImg;
|
||||
return false;
|
||||
//Pings_ROI(ho_in_Image, hv_in_ShapePath, hv_in_Parameter, &hv_out_ROI_Value, &hv_out_Flag_ROI);
|
||||
//for (int i = 0; i < hv_out_ROI_Value.Length() / 4; i++)
|
||||
//{
|
||||
// Result.push_back(
|
||||
// cv::Rect(
|
||||
// hv_out_ROI_Value[i * 4 + 1].D(),
|
||||
// hv_out_ROI_Value[i * 4].D(),
|
||||
// hv_out_ROI_Value[i * 4 + 3].D() - hv_out_ROI_Value[i * 4 + 1].D(),
|
||||
// hv_out_ROI_Value[i * 4 + 2].D() - hv_out_ROI_Value[i * 4].D()
|
||||
// ));
|
||||
//}
|
||||
}
|
||||
|
||||
//缺陷检测
|
||||
cv::Size minPin(30, 30), maxPin(200, 200);
|
||||
cv::Mat pinHandleAiEvaluate(std::shared_ptr <detData> data, cv::Mat& src,
|
||||
handleAiModelSeg* segPtr, handleAiModelCls* clsPtr)
|
||||
{
|
||||
//结果图
|
||||
cv::Mat Paint;
|
||||
if (src.channels() == 3)
|
||||
src.copyTo(Paint);
|
||||
else
|
||||
cvtColor(src, Paint, cv::COLOR_GRAY2BGR);
|
||||
//处理
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
cv::Mat segRes = ~segPtr->Evaluate(src);
|
||||
std::vector<std::vector<cv::Point>> contours;
|
||||
cv::findContours(segRes, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE);
|
||||
int cnt = 0;
|
||||
if (contours.size())//如果有缺陷
|
||||
data->segOriginImgs.push_back(src);
|
||||
for (auto contour : contours)
|
||||
{
|
||||
cv::Rect originRect = cv::boundingRect(contour);
|
||||
if (originRect.width < minPin.width || originRect.height < minPin.height || originRect.width > maxPin.width || originRect.height > maxPin.height)
|
||||
continue;
|
||||
cv::Rect rect = originRect;
|
||||
cv::Mat clsImg = cutImg2Cls(rect, src);
|
||||
int clsRes = clsPtr->Evaluate(clsImg);
|
||||
clsRes = 1;
|
||||
cv::Scalar color = cv::Scalar(0, 0, 255, 30);
|
||||
std::string clsFileName;
|
||||
switch (clsRes)
|
||||
{
|
||||
case 0:
|
||||
color = cv::Scalar(0, 255, 0, 30);
|
||||
clsFileName = "OK";
|
||||
break;
|
||||
case 1:
|
||||
color = cv::Scalar(0, 0, 255, 30);
|
||||
clsFileName = "NG1";
|
||||
data->aiDetOK = false;
|
||||
break;
|
||||
default:
|
||||
clsFileName = std::to_string(clsRes);
|
||||
data->aiDetOK = false;
|
||||
}
|
||||
data->clsOriginImgs.push_back(std::make_pair(clsFileName, clsImg));
|
||||
cv::rectangle(Paint, originRect, color, 2);
|
||||
}
|
||||
//返回结果图
|
||||
return Paint;
|
||||
}
|
||||
void handleAiEvaluate(std::shared_ptr <detData> data, handleAiModelManager* _handleAiModelManager, std::vector<handdleAI::Bbox>connectorPos, std::vector<cv::Mat>& aiImgResult)
|
||||
{
|
||||
cv::Mat src = data->oriImgs[0];
|
||||
for (auto& handleAiData : data->_productDataStruct.handleAiData.detResultHandle)
|
||||
{
|
||||
handleAiModelSeg* segPtr = _handleAiModelManager->getSegModel(handleAiData.segModelName);
|
||||
handleAiModelCls* clsPtr = _handleAiModelManager->getClsModel(handleAiData.clsModelName);
|
||||
for (auto box : connectorPos)
|
||||
{
|
||||
cv::Mat handleAiMat = pinHandleAiEvaluate(data, src(BboxToRect(box)),
|
||||
segPtr, clsPtr);
|
||||
aiImgResult.push_back(handleAiMat);//AI检测结果
|
||||
}
|
||||
}
|
||||
}
|
||||
//主函数
|
||||
int ALGO_InspectionErrorCheck(std::shared_ptr <detData> data)
|
||||
{
|
||||
@@ -294,7 +86,6 @@ void ALGO_Inspection(std::shared_ptr <detData> data, handleAiModelManager* _hand
|
||||
//box.classes = 2;
|
||||
//std::vector<handdleAI::Bbox> pinPos;
|
||||
//pinPos.push_back(box);
|
||||
bool tempCompared = false;
|
||||
//检测
|
||||
std::vector<cv::Mat>halconImgResult;
|
||||
std::vector<cv::Mat>aiImgResult;
|
||||
@@ -308,59 +99,40 @@ void ALGO_Inspection(std::shared_ptr <detData> data, handleAiModelManager* _hand
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
aiImgResult.push_back(asrHandleAiAlgo(data, src(BboxToRect(connector)), _handleAiModelManager));
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
tempCompared = true;
|
||||
break;
|
||||
case 2://APEX
|
||||
halconImgResult.push_back(apexHalconAlgo(data, src(BboxToRect(connector))));
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
aiImgResult.push_back(apexHandleAiAlgo(data, src(BboxToRect(connector)),_handleAiModelManager));
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
tempCompared = true;
|
||||
break;
|
||||
case 3://APEX BACK
|
||||
halconImgResult.push_back(apexBackHalconAlgo(data, src(BboxToRect(connector))));
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
aiImgResult.push_back(apexBackHandleAiAlgo(data, src(BboxToRect(connector)), _handleAiModelManager));
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
tempCompared = true;
|
||||
break;
|
||||
case 5://STARGAZER
|
||||
halconImgResult.push_back(stargazerHalconAlgo(data, src(BboxToRect(connector))));
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
aiImgResult.push_back(stargazerHandleAiAlgo(data, _handleAiModelManager));
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
tempCompared = true;
|
||||
break;
|
||||
case 1://APEX SMALL
|
||||
halconImgResult.push_back(apexSmallHalconAlgo(data, src(BboxToRect(connector))));
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
aiImgResult.push_back(apexSmallHandleAiAlgo(data, src(BboxToRect(connector)), _handleAiModelManager));
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
tempCompared = true;
|
||||
break;
|
||||
case 7://APEX SMALL BACK
|
||||
halconImgResult.push_back(apexSmallBackHalconAlgo(data, src(BboxToRect(connector))));
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
aiImgResult.push_back(apexSmalllBackHandleAiAlgo(data, src(BboxToRect(connector)), _handleAiModelManager));
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
tempCompared = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if(tempCompared == false)
|
||||
{
|
||||
|
||||
//HANDLEAI
|
||||
|
||||
handleAiEvaluate(data, _handleAiModelManager, pinPos, aiImgResult);
|
||||
data->handleAiEndTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
//HALCON
|
||||
|
||||
halconEvaluate(data, pinPos, halconImgResult);
|
||||
data->halconEndTime = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
//平铺结果图
|
||||
if (aiImgResult.size() > 0)
|
||||
|
||||
@@ -62,7 +62,7 @@ static void apexSmallHalconPaint(cv::Mat& out, std::vector<startAndEndPoints>xLi
|
||||
static cv::Mat apexSmallHalconAlgo(std::shared_ptr<detData>data, cv::Mat& src)
|
||||
{
|
||||
cv::Mat halconImg;
|
||||
src(cv::Rect(50, 50, src.cols - 100, src.rows - 150)).copyTo(halconImg);
|
||||
src.copyTo(halconImg);
|
||||
HTuple hv_out_OK_Pings;
|
||||
HTuple hv_out_NG_Pings;
|
||||
HTuple hv_out_Flag_INS;
|
||||
|
||||
@@ -80,36 +80,6 @@ void appConfig::parsingProductData(std::string path)
|
||||
{
|
||||
productData.lightSetting.insert(std::make_pair(std::stoi(it.key()), it.value()));
|
||||
}
|
||||
if (res["HandleAi"].empty() == false)
|
||||
{
|
||||
productData.handleAiData.detModelName = res["HandleAi"]["detModelName"];
|
||||
productData.handleAiData.detGpuIndex = res["HandleAi"]["detGpuIndex"];
|
||||
for (auto& data : res["HandleAi"]["segHandle"])
|
||||
{
|
||||
detResultHandleStruct detResultHandle;
|
||||
detResultHandle.detResultIndex = std::vector<int>(data["detResultIndex"].begin(), data["detResultIndex"].end());
|
||||
detResultHandle.segModelName = data["segModelName"];
|
||||
detResultHandle.segNgIndex = std::vector<int>(data["segNgIndex"].begin(), data["segNgIndex"].end());
|
||||
detResultHandle.segGpuIndex = data["segGpuIndex"];
|
||||
|
||||
detResultHandle.clsModelName = data["clsModelName"];
|
||||
detResultHandle.clsNgIndex = std::vector<int>(data["clsNgIndex"].begin(), data["clsNgIndex"].end());
|
||||
detResultHandle.segGpuIndex = data["segGpuIndex"];
|
||||
for (auto it = data["clsResultHandle"].begin(); it != data["clsResultHandle"].end(); ++it)
|
||||
{
|
||||
std::vector<std::string> result = split(it.value(), ',');
|
||||
if (result.size() != 4)
|
||||
{
|
||||
fancyWarnWindow* warn = new fancyWarnWindow
|
||||
(fancyWarnWindow::Warning, QString("在%1中的clsResultHandle发现格式错误").arg(QString::fromStdString(fileManager::getFileName(file)), true),
|
||||
QString("%1").arg(QString::fromStdString(it.value())), true);
|
||||
continue;
|
||||
}
|
||||
detResultHandle.clsResultHandle.insert(std::make_pair(std::stoi(it.key()), std::make_pair(result[0], cv::Scalar(std::stoi(result[3]), std::stoi(result[2]), std::stoi(result[1])))));
|
||||
}
|
||||
productData.handleAiData.detResultHandle.push_back(detResultHandle);
|
||||
}
|
||||
}
|
||||
if (res["productSign"].empty() == false)
|
||||
{
|
||||
for (auto it = res["productSign"].begin(); it != res["productSign"].end(); ++it)
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <vector>
|
||||
#include <appConfig/json/generalJsonParsing.hpp>
|
||||
#include <simpleTools/stringAlgo.h>
|
||||
#include <handleAi/handleAiSimpleDet.h>
|
||||
#include <uiModule/components/fancyDialog.h>
|
||||
#include <simpleTools/fileManager.h>
|
||||
#include <sqlManager/sqlManager.h>
|
||||
@@ -36,7 +35,6 @@ struct productDataStruct
|
||||
bool disableHandleAiConfig = false;
|
||||
bool enableCodedAlgo = false;
|
||||
int codedAlgoIndex = -1;
|
||||
handleAiSimpleDet handleAiData;
|
||||
|
||||
std::unordered_map<int, productSignStruct> productSign;
|
||||
};
|
||||
|
||||
@@ -151,8 +151,11 @@ void cameraManager::initialization()
|
||||
}
|
||||
|
||||
}
|
||||
void cameraManager::start()
|
||||
void cameraManager::run()
|
||||
{
|
||||
if (initFlag == true)
|
||||
return;
|
||||
bool initReuslt = true;
|
||||
for (auto i = 0; i < camerasVec.size(); i++)
|
||||
{
|
||||
cameraModule m_module = camerasVec.at(i);
|
||||
@@ -171,11 +174,18 @@ void cameraManager::start()
|
||||
{
|
||||
QByteArray errorStr("getStatus");
|
||||
m_module.module_ptr->sendData(vec_mat, errorStr);
|
||||
initFlag = false;
|
||||
initReuslt = false;
|
||||
qCritical() << "[Error] " << " moduleName:" << m_module.moduleName << " initParas failed!";
|
||||
emit _core._qtFunc.sendInitString("相机" + m_module.key + "初始化失败->"+ errorStr);
|
||||
}
|
||||
}
|
||||
if (initReuslt == true)
|
||||
{
|
||||
initFlag = true;
|
||||
status = InitOK;
|
||||
}
|
||||
else
|
||||
status = InitFailure;
|
||||
}
|
||||
bool cameraManager::loadModule(
|
||||
QString keyName,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <globalStruct.h>
|
||||
#include <qdatetime.h>
|
||||
#include <back/threadPoolManager.h>
|
||||
#include <serviceModule.hpp>
|
||||
//硬触发要求在触发相机前给出触发信号
|
||||
class backEndManager;
|
||||
class camera : public QThread
|
||||
@@ -105,14 +106,14 @@ private:
|
||||
int imgLost = 0;//未取用从而丢失的图片数量
|
||||
int showLost = 0;//因为窗口刷新速率低而未显示的数量
|
||||
};
|
||||
class cameraManager : public QObject
|
||||
class cameraManager : public serviceModule
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool initFlag = true;
|
||||
bool initFlag = false;
|
||||
void initialization();
|
||||
~cameraManager();
|
||||
void start();
|
||||
void run();
|
||||
std::unordered_map<std::string, camera*>cameras;//key 相机名
|
||||
camera* getCamera(std::string cameraName)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <qserialport.h>
|
||||
#include <unordered_map>
|
||||
#include <windowsHardwareCtrl.hpp>
|
||||
#include <qthread.h>
|
||||
enum lightSourceChannel
|
||||
{
|
||||
AChannel, BChannel, CChannel, DChannel
|
||||
@@ -62,7 +63,7 @@ public:
|
||||
serialPort->waitForBytesWritten();
|
||||
}
|
||||
};
|
||||
class lightSourceManager
|
||||
class lightSourceManager : public QThread
|
||||
{
|
||||
public:
|
||||
lightSourceManager()
|
||||
@@ -70,7 +71,11 @@ public:
|
||||
|
||||
|
||||
}
|
||||
void start()
|
||||
void run()
|
||||
{
|
||||
init();
|
||||
}
|
||||
void init()
|
||||
{
|
||||
insertLightSource("COM9", 19200, "SA0000#SB0000#SC0000#SD0000#");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <qthread.h>
|
||||
#include <globalStruct.h>
|
||||
class serviceModule :public QThread
|
||||
{
|
||||
public:
|
||||
initStatus status = NotInit;
|
||||
};
|
||||
#pragma once
|
||||
@@ -34,10 +34,20 @@ void triggerManager::initialization(detProcess* _detProcessIn)
|
||||
|
||||
|
||||
}
|
||||
void triggerManager::connectHost()
|
||||
void triggerManager::run()
|
||||
{
|
||||
connectHost();
|
||||
QThread::msleep(3000);
|
||||
while (runFlag)
|
||||
{
|
||||
reciveCommond();
|
||||
QThread::msleep(10);
|
||||
}
|
||||
}
|
||||
bool triggerManager::connectHost()
|
||||
{
|
||||
if (init == true)
|
||||
return;
|
||||
return true;
|
||||
if (libLoadedflag)
|
||||
{
|
||||
CreateFunction createFun = (CreateFunction)m_lib->resolve("create");
|
||||
@@ -55,7 +65,6 @@ void triggerManager::connectHost()
|
||||
trigger->reciveData(vec_mat, QByteArray(IpAndPort.toUtf8()));
|
||||
emit _core._qtFunc.sendInitString(triggerFileName + "连接到" + IpAndPort);
|
||||
initFailure = trigger->initParas(initByte);
|
||||
this->start();
|
||||
}
|
||||
|
||||
if (initFailure == false)
|
||||
@@ -64,12 +73,15 @@ void triggerManager::connectHost()
|
||||
delete m_lib;
|
||||
m_lib = nullptr;
|
||||
emit _core._qtFunc.sendInitString(triggerFileName + "初始化失败");
|
||||
return;
|
||||
}
|
||||
status = InitFailure;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = InitOK;
|
||||
init = true;
|
||||
emit _core._qtFunc.sendInitString(triggerFileName + "成功");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,11 +94,7 @@ void triggerManager::reciveCommond()
|
||||
if (!reciveFinsMsg(readByte))
|
||||
qCritical() << "[TCP] " << " finstcp_ptr sendData error!";
|
||||
tLocker.reFreshLocker(readByte);//经过检查后再触发
|
||||
//auto end = std::chrono::high_resolution_clock::now();
|
||||
//auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
//std::cout << "cost: " << duration.count() << " mm" << std::endl;
|
||||
decodeCameraCMD(readByte);
|
||||
//workThread->snDatas.checkSnFromWaittingVec(readByte);
|
||||
}
|
||||
|
||||
void triggerManager::decodeCameraCMD(QByteArray byte)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <backStruct.h>
|
||||
#include <functional>
|
||||
#include <appConfig/appConfig.h>
|
||||
#include <serviceModule.hpp>
|
||||
using triggerCallback = std::function<void(QByteArray& byte)>;
|
||||
class cameraManager;
|
||||
class detThreadManager;
|
||||
@@ -62,11 +63,12 @@ private:
|
||||
|
||||
};
|
||||
//触发器类 fins触发 tcp触发等 替代myiothread
|
||||
class triggerManager : public QThread
|
||||
class triggerManager : public serviceModule
|
||||
{
|
||||
public:
|
||||
|
||||
QByteArray readAllCmd;
|
||||
QString triggerFileName;
|
||||
QString triggerFileName;
|
||||
QString IpAndPort;
|
||||
QString triggerInitStr;
|
||||
~triggerManager()
|
||||
@@ -77,16 +79,8 @@ public:
|
||||
delete trigger;
|
||||
}
|
||||
void initialization(detProcess*);
|
||||
void connectHost();
|
||||
void run()
|
||||
{
|
||||
QThread::msleep(3000);
|
||||
while (runFlag)
|
||||
{
|
||||
reciveCommond();
|
||||
QThread::msleep(100);
|
||||
}
|
||||
}
|
||||
bool connectHost();
|
||||
void run();
|
||||
void stop()
|
||||
{
|
||||
runFlag = false;
|
||||
|
||||
@@ -24,13 +24,27 @@ public:
|
||||
//初始化
|
||||
void run()
|
||||
{
|
||||
std::vector<std::future<void>>futures;
|
||||
futures.push_back(std::async(std::launch::async, &handleAiModelManager::start, &_handleAiModelManager));
|
||||
futures.push_back(std::async(std::launch::async, &cameraManager::start, &_cameraManager));
|
||||
futures.push_back(std::async(std::launch::async, &lightSourceManager::start, &_lightSourceManager));
|
||||
futures.push_back(std::async(std::launch::async, &triggerManager::connectHost, &_triggerManager));
|
||||
|
||||
_cameraManager.start();
|
||||
_handleAiModelManager.start();
|
||||
_lightSourceManager.start();
|
||||
_triggerManager.start();
|
||||
bool res1 = waitrForInitResult(&_cameraManager);
|
||||
bool res2 = waitrForInitResult(&_handleAiModelManager);
|
||||
bool res3 = waitrForInitResult(&_triggerManager);
|
||||
std::cout << std::to_string(res1) << "," << std::to_string(res2) << "," << std::to_string(res3) << "," << std::endl;
|
||||
}
|
||||
bool waitrForInitResult(serviceModule* ptr)
|
||||
{
|
||||
int timecnt = 0;
|
||||
while (timecnt < 100)
|
||||
{
|
||||
if (ptr->status != NotInit)
|
||||
break;
|
||||
}
|
||||
if (timecnt > 100)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
simpleSiemensTcp _simpleSiemensTcp;
|
||||
detDataManager _detDataManager;//检测中的数据 不需要初始化
|
||||
imgSaveThreadManager _imgSaveThreadManager;//存图线程 不需要初始化
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <handleAi/handleAiModel.h>
|
||||
#include <appConfig/appConfig.h>
|
||||
#include <appCore.hpp>
|
||||
|
||||
handleAiModelManager::handleAiModelManager()
|
||||
{
|
||||
_core._appConfig.productDatasMutex.lock();
|
||||
this->basePath = _core._appConfig.handleAiModelPath + "/";
|
||||
for (auto& productData : _core._appConfig.productDatas)
|
||||
{
|
||||
insertDetModelPath(productData.handleAiData.detModelName, productData.handleAiData.detGpuIndex);
|
||||
for (auto& handleAiData : productData.handleAiData.detResultHandle)
|
||||
{
|
||||
|
||||
insertSegModelPath(handleAiData.segModelName, handleAiData.segGpuIndex);
|
||||
insertClsModelPath(handleAiData.clsModelName, handleAiData.clsGpuIndex);
|
||||
}
|
||||
}
|
||||
_core._appConfig.productDatasMutex.unlock();
|
||||
}
|
||||
@@ -7,9 +7,7 @@
|
||||
#include <unordered_map>
|
||||
#include <qdebug.h>
|
||||
#include <appCore.hpp>
|
||||
|
||||
#define handleAiModelSwitch 1
|
||||
#if handleAiModelSwitch
|
||||
#include <serviceModule.hpp>
|
||||
class appConfig;
|
||||
class handleAiModelSeg
|
||||
{
|
||||
@@ -113,7 +111,7 @@ public:
|
||||
private:
|
||||
handdleAI::pDetection* detPtr;
|
||||
};
|
||||
class handleAiModelManager :public QObject
|
||||
class handleAiModelManager :public serviceModule
|
||||
{
|
||||
public:
|
||||
enum type
|
||||
@@ -121,17 +119,13 @@ public:
|
||||
seg, cls, det
|
||||
};
|
||||
bool initFlag = false;
|
||||
handleAiModelSeg* largeSeg;
|
||||
handleAiModelCls* largeCls;
|
||||
|
||||
handleAiModelSeg* midSeg;
|
||||
handleAiModelCls* midCls;
|
||||
|
||||
handleAiModelSeg* smallSeg;
|
||||
handleAiModelCls* smallCls;
|
||||
handleAiModelDet* smalDet;
|
||||
std::string basePath;
|
||||
handleAiModelManager();
|
||||
handleAiModelManager()
|
||||
{
|
||||
_core._appConfig.productDatasMutex.lock();
|
||||
this->basePath = _core._appConfig.handleAiModelPath + "/";
|
||||
_core._appConfig.productDatasMutex.unlock();
|
||||
};
|
||||
bool insertSegModelPath(std::string modelName,int gpuIndex)
|
||||
{
|
||||
auto mapResult = segModels.find(modelName);
|
||||
@@ -180,10 +174,12 @@ public:
|
||||
}
|
||||
void initialization()
|
||||
{
|
||||
insertSegModelPath("APEX-Seg.BHD",0);
|
||||
insertClsModelPath("APEX-Cls.BHD", 0);
|
||||
|
||||
insertSegModelPath("APEX-Seg.BHD", 0);
|
||||
insertClsModelPath("APEX-Cls.BHD", 0);
|
||||
|
||||
}
|
||||
void start()
|
||||
void run()
|
||||
{
|
||||
if (init == true)
|
||||
return;
|
||||
@@ -193,7 +189,7 @@ public:
|
||||
{
|
||||
futures.push_back(std::async(std::launch::async, &handleAiModelSeg::init, model.second));
|
||||
emit _core._qtFunc.sendInitString(QString::fromStdString(fileManager::getFileName(model.second->path) + "初始化中..."));
|
||||
}
|
||||
}
|
||||
for (auto &model : clsModels)
|
||||
{
|
||||
futures.push_back(std::async(std::launch::async, &handleAiModelCls::init, model.second));
|
||||
@@ -208,11 +204,13 @@ public:
|
||||
for (auto& func : futures)
|
||||
{
|
||||
func.wait();
|
||||
emit _core._qtFunc.sendInitString(QString::fromStdString(fileManager::getFileName(func.get()) + "成功"));
|
||||
qDebug() << QString::fromStdString(fileManager::getFileName(func.get()) + "成功");
|
||||
std::cout << fileManager::getFileName(func.get()) + "成功" << std::endl;
|
||||
std::string result = func.get();
|
||||
emit _core._qtFunc.sendInitString(QString::fromStdString(fileManager::getFileName(result) + "成功"));
|
||||
qDebug() << QString::fromStdString(fileManager::getFileName(result) + "成功");
|
||||
std::cout << fileManager::getFileName(result) + "成功" << std::endl;
|
||||
}
|
||||
init = true;
|
||||
status = InitOK;
|
||||
#endif
|
||||
}
|
||||
~handleAiModelManager()
|
||||
@@ -234,77 +232,5 @@ private:
|
||||
int gpuCnt = 1;//gpu数量
|
||||
bool init = false;
|
||||
};
|
||||
#endif
|
||||
#if handleAiModelSwitch == 0
|
||||
class handleAiModelManager :public QObject
|
||||
{
|
||||
public:
|
||||
std::vector<std::pair<handdleAI::pSegmentation*, std::string>> segModels;
|
||||
std::vector < std::pair< handdleAI::pClassification*, std::string>> clsModels;
|
||||
|
||||
handdleAI::pSegmentation* largeSeg;
|
||||
handdleAI::pClassification* largeCls;
|
||||
|
||||
handdleAI::pSegmentation* midSeg;
|
||||
handdleAI::pClassification* midCls;
|
||||
|
||||
handdleAI::pSegmentation* smallSeg;
|
||||
handdleAI::pClassification* smallCls;
|
||||
|
||||
////////模型放这里///////
|
||||
handleAiModelManager()
|
||||
{
|
||||
segModels.push_back({ largeSeg ,"./HandleAiModels/large-seg.BHD" });
|
||||
segModels.push_back({ midSeg ,"./HandleAiModels/mid-seg.BHD" });
|
||||
segModels.push_back({ smallSeg ,"./HandleAiModels/small-seg.BHD" });
|
||||
|
||||
clsModels.push_back({ largeCls ,"./HandleAiModels/large-cls.BHD" });
|
||||
clsModels.push_back({ midCls ,"./HandleAiModels/mid-cls.BHD" });
|
||||
clsModels.push_back({ smallCls ,"./HandleAiModels/small-cls.BHD" });
|
||||
}
|
||||
///////////END/////////
|
||||
|
||||
void createSeg(handdleAI::pSegmentation* segPtr, std::string path, int gpuId)
|
||||
{
|
||||
segPtr = handdleAI::CreateSegObj((char*)path.c_str(), gpuId);
|
||||
}
|
||||
void createCls(handdleAI::pClassification* clsPtr, std::string path, int gpuId)
|
||||
{
|
||||
clsPtr = handdleAI::CreateClsObjV3((char*)path.c_str(), gpuId,1);
|
||||
}
|
||||
void init(backEndManager* _backEndManagerIn)
|
||||
{
|
||||
|
||||
std::vector<std::future<void>> futures;//异步初始化
|
||||
for (auto model : segModels)
|
||||
{
|
||||
futures.push_back(std::async(std::launch::async, &handleAiModelManager::createSeg,this, model.first,model.second,0));
|
||||
emit _backEndManagerIn->sendInitString(QString::fromStdString(getFileName(model.second) + "初始化中..."));
|
||||
}
|
||||
for (auto model : clsModels)
|
||||
{
|
||||
futures.push_back(std::async(std::launch::async, &handleAiModelManager::createCls, this, model.first, model.second, 0));
|
||||
emit _backEndManagerIn->sendInitString(QString::fromStdString(getFileName(model.second) + "初始化中..."));
|
||||
}
|
||||
int cnt = 0;
|
||||
for (auto& func : futures)
|
||||
{
|
||||
func.wait();
|
||||
//emit _backEndManagerIn->sendInitString(QString::fromStdString(getFileName(models[cnt]->path) + "成功"));
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
~handleAiModelManager()
|
||||
{
|
||||
handdleAI::DestroySegObj(largeSeg);
|
||||
handdleAI::DestroySegObj(midSeg);
|
||||
handdleAI::DestroySegObj(smallSeg);
|
||||
|
||||
handdleAI::DestroyClsObj(largeCls);
|
||||
handdleAI::DestroyClsObj(midCls);
|
||||
handdleAI::DestroyClsObj(smallCls);
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
#pragma once
|
||||
@@ -1,28 +0,0 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <opencv.hpp>
|
||||
#include <unordered_map>
|
||||
struct detResultHandleStruct
|
||||
{
|
||||
std::vector<int> detResultIndex;//本产品对应det模型训练时的序号
|
||||
|
||||
std::string segModelName;//重复时将不会重复初始化
|
||||
std::vector<int>segNgIndex;//NG的将会进入cls检测
|
||||
int segGpuIndex = 0;
|
||||
|
||||
std::string clsModelName;//重复时将不会重复初始化
|
||||
std::vector<int>clsNgIndex;//NG判断
|
||||
int clsGpuIndex = 0;
|
||||
|
||||
//int为Cls的分类结果 string为文本 Scalar为颜色
|
||||
std::unordered_map<int, std::pair<std::string, cv::Scalar>>clsResultHandle;//结果绘制
|
||||
};
|
||||
struct handleAiSimpleDet
|
||||
{
|
||||
//最后调用模型时是使用路径去查找,请保证规则一致
|
||||
std::string detModelName;//重复时将不会重复初始化
|
||||
int detGpuIndex = 0;
|
||||
|
||||
std::vector<detResultHandleStruct>detResultHandle;
|
||||
};
|
||||
#pragma once
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <appConfig/json/generalJsonParsing.hpp>
|
||||
#include <uiModule/components/fancyDialog.h>
|
||||
#include <opencv.hpp>
|
||||
#include <handleAi/handleAiSimpleDet.h>
|
||||
#include <unordered_map>
|
||||
#include <simpleTools/stringAlgo.h>
|
||||
#include <qmutex.h>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user