This commit is contained in:
rci
2024-10-26 09:52:02 +08:00
parent 8d76094353
commit 29f446cf68
10 changed files with 216 additions and 37 deletions
@@ -7,7 +7,9 @@
#include <filesystem>
#include <myTools.h>
#include <algo.h>
#include <global.h>
using namespace cv;
QByteArray chartOKNG = "0";//0OK 1NG
QByteArray silieResultText = "0";
QByteArray fanzheResultText = "0";
QByteArray jiErWidth = "0";
@@ -548,14 +550,25 @@ bool Hd_AI_algo_hanHou::readData(std::vector<cv::Mat>&vec_mat,QByteArray &data)
//if (allNum++ % 2 == 0)
// data = "2*3*2";// resByte.dequeue();
//else
data = "1*" + silieResultText + + "*" + fanzheResultText
+ "*" + jiErWidth + "*" + jiErHeight
+ "*" + hanYin1 + "*" + hanYin2
+"&" + fanzheResultText + "&" + silieResultText
+ "+" + fanzheResultText + "+" + silieResultText
+ "+" + jiErWidth + "+" + jiErHeight
+ "+" + hanYin1 + "+" + hanYin2
;//1OK,2NG
//发送到PLC的数据
QByteArray resultCmd = resultCmdSplitStart +
silieResultText + +generalSplit + fanzheResultText
+ generalSplit + jiErWidth + generalSplit + jiErHeight
+ generalSplit + hanYin1 + generalSplit + hanYin2
+ resultCmdSplitEnd;
//饼状图OKNG
QByteArray chartData = chartSplitStart + chartOKNG + chartSplitEnd;//应该只有一个数据 1OK 0NG
//缺陷直方图
QByteArray defectData = defectSplitStart + fanzheResultText + generalSplit + silieResultText + defectSplitEnd;//0NG 1OK
//csv
QByteArray csvData = csvSplitStart + silieResultText
+ generalSplit + fanzheResultText + generalSplit + silieResultText
+ generalSplit + jiErWidth + generalSplit + jiErHeight
+ generalSplit + hanYin1 + generalSplit + hanYin2 + csvSplitEnd;
data = resultCmd + chartData + defectData + csvData;
resByte.clear();
////之后根据结果类修改
//if(resIfNg == true)
@@ -657,6 +670,7 @@ bool Hd_AI_algo_hanHou::writeData(std::vector<cv::Mat>& vec_mat, QByteArray &dat
createDirectoryIfNotExists(oriImgSaveDir + getCurrentDate() + "//" + getCurrentHour() + "//");
addImgToSaveStruct(HikMat[0], "0",getOriSaveFromat());//保存原图
if(HikMat.size() > 1)
addImgToSaveStruct(HikMat[1], "0", getOriSaveFromat2());//保存原图
//if (!source_savePath.isEmpty())
//{
@@ -755,8 +769,8 @@ bool Hd_AI_algo_hanHou::initParas(QByteArray& byte)
//StationNo = vec_ret.at(0).toInt();
seg_hanHouSiLie = handdleAI::CreateSegObjS("./model/seg-yuHanhanHouSiLie.BHD", 32, 0);
seg_hanHouFanZhe = handdleAI::CreateSegObjS("./model/seg-yuHanhanFanZhe.BHD", 32, 0);
//seg_hanHouSiLie = handdleAI::CreateSegObjS("./model/seg-yuHanhanHouSiLie.BHD", 32, 0);
//seg_hanHouFanZhe = handdleAI::CreateSegObjS("./model/seg-yuHanhanFanZhe.BHD", 32, 0);
//InitThreads(StationNo, img2D);
//InitModels(StationNo, img2D);
@@ -924,7 +938,7 @@ bool Hd_AI_algo_hanHou::AIdetect(cv::Mat img2D, QString mysaveKey, QString myDir
{
try
{
return true;
//存图数据加保存队列,加锁,避免数据访问冲突
saveStruct_mutex->lock();
@@ -94,6 +94,12 @@ bool IsColor(MvGvspPixelType enType)
return false;
}
}
void SetExposureTime(float exposureValue)
{
qDebug() << "[INFO] " << "exposureValue:" << exposureValue;
MV_CC_SetEnumValue(handle, "ExposureAuto", MV_EXPOSURE_AUTO_MODE_OFF);
MV_CC_SetFloatValue(handle, "ExposureTime", exposureValue);
}
//搜索所有设备
int SearchDevice()
@@ -330,13 +336,6 @@ void __stdcall ImageCallBackEx(unsigned char* pData0, MV_FRAME_OUT_INFO_EX* pFra
cv::imwrite(savePath.toStdString(), resizeS);*/
}
void SetExposureTime(float exposureValue)
{
qDebug() << "[INFO] " << "exposureValue:" << exposureValue;
MV_CC_SetEnumValue(handle, "ExposureAuto", MV_EXPOSURE_AUTO_MODE_OFF);
MV_CC_SetFloatValue(handle, "ExposureTime", exposureValue);
}
void SetGain(float GainValue)
{
qDebug() << "[INFO] " << "GainValue:" << GainValue;
@@ -4,7 +4,7 @@ string(TIMESTAMP RUN_TIME)
message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME})
set(DLL_NAMES "opencv" "qt5")
set(DLL_NAMES "opencv" "qt5" "myTools")
foreach(child ${DLL_NAMES})
LIST(APPEND ENV_INCLUDE ${${child}_include})
LIST(APPEND ENV_LIB ${${child}_lib})
@@ -1,5 +1,5 @@
#include "Logic_taskthread.h"
#include <global.h>
//图像锁、通信指令锁
void Logic_taskthread::setMutex(QMutex* image_lock, QMutex* write_mutex) {
if (m_image_lock == nullptr)
@@ -810,7 +810,13 @@ bool Logic_taskthread::deleteSnData ( QByteArray byteArray, QVector<QString>& sn
// 算法结果 写入plc
bool Logic_taskthread::writeAiCommond ( QString cameraName,QString camera_name_index,QByteArray byteArray )
{
QByteArrayList PLCvec_ret= byteArray.split('*'); // 存储结果的
std::string str = byteArray.toStdString();
int start = str.find(resultCmdSplitStart) + std::size(resultCmdSplitStart)-1;
int end = str.find(resultCmdSplitEnd)- start;
if (end > 0 && start > 0)
str = str.substr(start,end);
//char split = *generalSplit;
QByteArrayList PLCvec_ret= QByteArray::fromStdString(str).split(*generalSplit); // 存储结果的
if (PLCvec_ret.isEmpty() )
{
+1 -1
View File
@@ -13,7 +13,7 @@ foreach(dll ${OUR_LIBS})
endforeach(dll ${})
set(DLL_NAMES "halcon" "opencv" "json" "handdleAI")
set(DLL_NAMES "halcon" "opencv" "json" "handdleAI" "myTools")
foreach(child ${DLL_NAMES})
LIST(APPEND ENV_INCLUDE ${${child}_include})
LIST(APPEND ENV_LIB ${${child}_lib})
+30 -12
View File
@@ -1,6 +1,7 @@
#include "Qt_epWindow.h"
#include "qapplication.h"
#include <rlib_writeCsv.hpp>
#include <global.h>
#pragma execution_character_set("utf-8")
clock_t pressStart, pressStop;
@@ -1803,6 +1804,24 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
int mm = nowTime.split(" ")[1].split(":")[1].toInt();
if ((hh > 8 && hh < 20) || (hh == 8 && mm >= 30) || (hh == 20 && mm < 30))
ifNight = false;
std::string str = byteArray.toStdString();
std::string chartData, csvData, defectData;
//CHART表格数据
int startChart = str.find(chartSplitStart) + std::size(chartSplitStart) - 1;
int endChart = str.find(chartSplitEnd) - startChart;
if (startChart > 0 && endChart > 0)
chartData = str.substr(startChart, endChart);
//CSV表格数据
int startCSV = str.find(csvSplitStart) + std::size(csvSplitStart) - 1;
int endCSV = str.find(csvSplitEnd) - startCSV;
if (startCSV > 0 && endCSV > 0)
csvData = str.substr(startCSV, endCSV);
//缺陷直方图
int startDefect = str.find(csvSplitStart) + std::size(csvSplitStart) - 1;
int endDefect = str.find(csvSplitEnd) - startDefect;
if (startDefect > 0 && endDefect > 0)
defectData = str.substr(startDefect, endDefect);
if (key.contains("程序号"))
{
cName_surface_defectNums.clear();
@@ -1843,10 +1862,12 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
set_tabQPushButton(0);
//waiteBox-> close();
}
else if (myByte.contains("*") )//|| CommunicationProcessLevel==1) //简单流程每张图就是结果
if (chartData.size() > 0)//|| CommunicationProcessLevel==1) //简单流程每张图就是结果
{
int result = stoi(chartData);
QPieSeriesData_ALL.allNum++;
if (myByte.contains("1*") || (CommunicationProcessLevel==1 && myByte=='1'))
if (result == 1)
{
myByte = "OK";
setInsertTextColor(ui.plainTextEdit_history, QColor("green"));
@@ -1869,13 +1890,12 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
if (historyLogList.size() > 100000)
historyLogList.dequeue();
ui.plainTextEdit_history->appendPlainText(historyLogList.last());
//实时信息
{
ui.label_result->setText(myByte);
ui.label_SN->setText(snInfo);
ui.label_allNum->setText(QString::number(QPieSeriesData_ALL.allNum));
ui.label_OKPercent->setText(QString::number(int(QPieSeriesData_ALL.okNum*1.0000 / QPieSeriesData_ALL.allNum * 10000) / 100.00) + "%");
ui.label_OKPercent->setText(QString::number(int(QPieSeriesData_ALL.okNum * 1.0000 / QPieSeriesData_ALL.allNum * 10000) / 100.00) + "%");
ui.label_OKNum->setText(QString::number(QPieSeriesData_ALL.okNum));
ui.label_NGnum->setText(QString::number(QPieSeriesData_ALL.ngNum));; //百万级变负数??
if (QPieSeriesData_ALL.allNum > 1)
@@ -1888,12 +1908,11 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
}
start = clock();
}
//饼图更新
{
//ALL饼图;slices()[0] ok;slices()[1] ng;
QPieSeriesData_ALL.series->slices()[0]->setValue(int(QPieSeriesData_ALL.okNum * 1.0000 / QPieSeriesData_ALL.allNum * 10000) / 100.00);
QPieSeriesData_ALL.series->slices()[1]->setValue(100.00- int(QPieSeriesData_ALL.okNum * 1.0000 / QPieSeriesData_ALL.allNum * 10000) / 100.00);
QPieSeriesData_ALL.series->slices()[1]->setValue(100.00 - int(QPieSeriesData_ALL.okNum * 1.0000 / QPieSeriesData_ALL.allNum * 10000) / 100.00);
//换班判断
if (ifLastNight != ifNight)
@@ -1925,7 +1944,7 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
if (ifNight)
{
QPieSeriesData_night.allNum++;
if(myByte=="OK")
if (myByte == "OK")
QPieSeriesData_night.okNum++;
else if (myByte == "NG")
QPieSeriesData_night.ngNum++;
@@ -1975,11 +1994,10 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
rowNumn++;
}
}
//更新缺陷统计表图
if (myByteCpy.contains("&")) //格式为:忽略段&缺陷类型1的是否有缺陷标志&缺陷类型2的是否有缺陷标志...
if(defectData.size() > 0)
{
QStringList myByteList = myByteCpy.split("&");
QStringList myByteList = myByteCpy.split(*generalSplit);
if (myByteList.size() > 1)
for (int i = 1; i < myByteList.size(); i++)
{
@@ -2089,11 +2107,11 @@ void Qt_epWindow::getTransferData(QString key, QString cameraName, QString snInf
}
//写表格CSV
if (myByteCpy.contains("+"))
if (csvData.size()>0)
{
QString ymd = QDateTime::currentDateTime().toString("yyyy-MM-dd");
QString hms = QDateTime::currentDateTime().toString("hh:mm:ss");
QStringList outDataList = myByteCpy.split("+");
QStringList outDataList = myByteCpy.split(*generalSplit);
std::vector<std::string> strList;
strList.push_back(hms.toStdString());// 时间
strList.push_back(snInfo.toStdString());//SN
Binary file not shown.
+135 -3
View File
@@ -28,11 +28,13 @@ extern "C" __declspec(dllexport) void _stdcall _628_1_Polarity_detection(HObject
*hv_Out_Roboot1:吸嘴1-> 吸嘴编号,x绝对坐标,y绝对坐标
* hv_Out_Roboot2:吸嘴2->吸嘴编号,x绝对坐标,y绝对坐标
* hv_Out_Roboot3:吸嘴3->吸嘴编号,x绝对坐标,y绝对坐标
* hv_StartRun: 1启动振动盘,2不启动振动盘
* 机器人引导函数
* 三协机台
*/
extern "C" __declspec(dllexport) void _stdcall _628_BootTheMachine(HObject ho_Image, HTuple hv_NinePointDocument, HTuple hv_SetNumber,
HTuple* hv_Circle_Point, HTuple* hv_Make, HTuple* hv_Out_Roboot1, HTuple* hv_Out_Roboot2,HTuple* hv_Out_Roboot3);
extern "C" __declspec(dllexport) void _stdcall _628_BootTheMachine(HObject ho_Image, HTuple hv_NinePointDocument, HTuple hv_SetNumber,
HTuple* hv_Circle_Point, HTuple* hv_Make, HTuple* hv_Out_Roboot1, HTuple* hv_Out_Roboot2,
HTuple* hv_Out_Roboot3, HTuple* hv_StartRun);
/*
*ho_Image:输入图片(原图)
@@ -47,6 +49,23 @@ extern "C" __declspec(dllexport) void _stdcall _628_BootTheMachine(HObject ho_Im
extern "C" __declspec(dllexport) void _stdcall cs_628_jier_T(HObject ho_Image, HTuple hv_Pix, HTuple* hv_out_line, HTuple* hv_out_Soldering_line,
HTuple* hv_distance, HTuple* hv_Make);
/*
*ho_Image:输入图片(原图)
* hv_Pix:像素精度
* hv_out_line:输出直线坐标
* hv_distance:输出测量值 ->高,宽。数组形式
* hv_Make:输出-1为算法错误,输出1为算法正常执行
* 铝极耳裁剪测量函数
* 三协预焊机台
*/
extern "C" __declspec(dllexport) void _stdcall cs_628_jier_L(HObject ho_Image, HTuple hv_Pix, HTuple* hv_out_line, HTuple* hv_distance,
HTuple* hv_Make);
/*
@@ -70,7 +89,7 @@ extern "C" __declspec(dllexport) void _stdcall _628_NailingPosition(HObject ho_I
/*
ho_Image:输入原图
hv_out_Value:输出检测结果[1,1] .1为铝,[2,2] 2为铜
hv_out_Value:输出检测结果[1,1] .1为铝,[2,2] 2为铜 ,0为无料
hv_Make:算法执行状态-1为算法NG,1为算法ok
极性检测函数
终焊三协机台
@@ -139,9 +158,52 @@ extern "C" __declspec(dllexport) void _stdcall _628_AfterWelding_Distance_T(HObj
HTuple* hv_Out_TopRight_Value, HTuple* hv_Out_BottomLeft_Line, HTuple* hv_Out_BottomLeft_Value,
HTuple* hv_Out_BottomRight_Line, HTuple* hv_Out_BottomRight_Value, HTuple* hv_Make);
/*
* ho_Image :输入图片
* hv_Out_Rectangle : 输出矩形的两个顶点坐标
* hv_Text :输出检测信息字符串格式
* hv_Make:输出-1为算法错误,输出1为算法正常执行
*软连接热熔工位函数
* 三协的机台
*/
extern "C" __declspec(dllexport) void _stdcall _628_3_TopCoverMelted(HObject ho_Image, HTuple* hv_Out_Rectangle, HTuple* hv_Make,
HTuple* hv_Text);
/*
* ho_Image_L :输入图片(铝)
* ho_Image_T :输入图片(铜)
* hv_Pix_L :铝极相机像素精度
* hv_Pix_T :铜极相机像素精度
* hv_Out_Line_T :铜极输出线的端点坐标(需判断个数)
* hv_Out_Point_T :铜极输出中心圆的中心坐标及半径
* hv_Out_Chamfering_T :铜极输出倒角值
* hv_Distances_T :铜极输出上下,左右距离
* hv_Out_Line_L :铝极输出线的端点坐标(需判断个数)
* hv_Out_Point_L :铝极输出中心圆的中心坐标及半径
* hv_Out_Chamfering_L :铝极输出倒角值
* hv_Distances_L :铝极输出上下,左右距离
* hv_Out_InterpoleValue :输出两极柱之间距离
* hv_Makes:输出-1为算法错误,输出1为算法正常执行
*软连接极柱测量工位函数
* 三协的机台
*/
extern "C" __declspec(dllexport) void _stdcall _628_3_PoleDetections(HObject ho_Image_L, HObject ho_Image_T, HTuple hv_Pix_L,
HTuple hv_Pix_T, HTuple* hv_Out_Line_T, HTuple* hv_Out_Point_T, HTuple* hv_Out_Chamfering_T,
HTuple* hv_Distances_T, HTuple* hv_Out_Line_L, HTuple* hv_Out_Point_L, HTuple* hv_Out_Chamfering_L,
HTuple* hv_Distances_L, HTuple* hv_Out_InterpoleValue, HTuple* hv_Makes);
/*
* ho_Image :输入图片
* hv_Pix :相机像素精度
* hv_Distance_Value :间距测量值
* hv_Out_Point :输出防爆阀中心点和二维码中心点距离
* hv_Makes:输出-1为算法错误,输出1为算法正常执行
*软连接防爆阀与二维码之间距离测量函数
* 三协的机台
*/
extern "C" __declspec(dllexport) void _stdcall _628_3_ExplosionProofValves(HObject ho_Image, HTuple hv_Pix, HTuple* hv_Distance_Value,
HTuple* hv_Out_Point, HTuple* hv_Make);
@@ -225,6 +287,60 @@ extern "C" __declspec(dllexport) void _stdcall _628_25D(HObject ho_Image1, HObje
HObject* ho_Out_Image1, HObject* ho_Out_image2, HTuple hv_sacats, HTuple hv_Tilts,
HTuple* hv_Make);
//Function Name: Cal_Defect_Height
//Author:
//Description: 2D获取缺陷后, 基于特征点的位置关系, 建立2D和3D的映射关系.
//Input: in_Image2: 密封钉区域的2D二值化的图像(bmp),,
// in_Image3: 3D深度图像(tiff),
// in_xResolution: x向精度(mm/pix)
// in_yResolution: y向精度(mm/pix),
// in_zResolution: Z向精度(mm/pix)
// in_DefectLocation: 2d图像缺陷坐标点位置, 每四个一组,
// in_DefectLocation[0]:缺陷外接矩形的X向坐标(pix)
// in_DefectLocation[1]:缺陷外接矩形的y向坐标(pix)
// in_DefectLocation[2]:缺陷外接矩形的宽度width(pix)
// in_DefectLocation[3]:缺陷外接矩形的高度height(pix)
// in_FilePath, 矩阵martix文件路径,
// in_offsetValue, 位置补偿值,
// in_offsetValue[0]: 左工位X向补偿值(pix)
// in_offsetValue[1]: 左工位Y向补偿值(pix)
// in_offsetValue[2]: 右工位X向补偿值(pix)
// in_offsetValue[3]: 右工位Y向补偿值(pix)
// in_HoffsetValue, 缺陷高度补偿值(正值,单位:mm)
//output: out_Height: 缺陷的高度(mm),
// out_Flag: 算法执行的标志位, 0: 算法执行异常 1:算法执行ok
// 赢合机台
//verion change log: XXX 2024-10-22 V1.1 Create new function
extern "C" __declspec(dllexport) void _stdcall Cal_Defect_Height(HObject ho_in_Image2, HObject ho_in_Image3, HTuple hv_in_xResolution,
HTuple hv_in_yResolution, HTuple hv_in_zResolution, HTuple hv_in_DefectLocation,
HTuple hv_in_FilePath, HTuple hv_in_OffsetValue, HTuple hv_in_HoffsetValue, HTuple* hv_out_Height,
HTuple* hv_out_Angle, HTuple* hv_out_Flag);
//**********************************************************************
//Function Name: Cal_Long_Coatingcover_Dist
//Author:
//Description: 计算膜到端盖的距离,
//Input(HObject): in_Image,滤波处理后的抓边图像
//Input(HTuple): in_Resolution, 相机精度(mm/pix)
//output(HTuple): out_Maxdistance, 膜到端盖的最大距离(mm)
// out_Mindistance, 膜到端盖的最小距离(mm)
// out_Line, 基准线位置(x1,y1,x2,y2)
// out_X, 膜的x点坐标集
// out_Y, 膜的y点坐标集
// out_Flag: 执行成功位标识 1, 算法执行成功 2, 算法执行ng
// out_NgTails: NG的明细
//verion change log: 胡汉兵 2024-07-11 V1.1 Create new function .
//**********************************************************************
extern "C" __declspec(dllexport) void _stdcall Cal_Long_Coatingcover_Dist(HObject ho_in_Image, HTuple hv_in_Resolution, HTuple* hv_out_Maxdistance,
HTuple* hv_out_Mindistance, HTuple* hv_out_Line, HTuple* hv_out_X, HTuple* hv_out_Y,
HTuple* hv_out_Flag, HTuple* hv_out_Ngtails);
#endif
@@ -264,6 +380,22 @@ void BeforeWelding_T(HObject ho_Image_T, HTuple hv_Pix_T, HTuple* hv_Make, HTupl
HTuple* hv_Out_Vale, HTuple* hv_Out_PointRow, HTuple* hv_Out_PointCol);
void Cal_PointCould_HeightValue(HObject ho_Tmp_Region, HObject ho_Zero_Region, HObject ho_XImageScaled,
HObject ho_YImageScaled, HObject ho_ZImageScaled, HTuple hv_HeightPointPerenct,
HTuple* hv_Out_Mean, HTuple* hv_Out_Max, HTuple* hv_Out_Min, HTuple* hv_Out_Height,
HTuple* hv_Out_Flag, HTuple* hv_Out_NgTails);
void cs_628_PoleDetection(HObject ho_Image, HTuple hv_Pix, HTuple* hv_Distances,
HTuple* hv_UP_Down_Point, HTuple* hv_life_Ren_Point, HTuple* hv_Point, HTuple* hv_Chamfering,
HTuple* hv_Make);
void Get_Rectangle2_Corner(HObject ho_Rectangle, HTuple* hv_out_Row, HTuple* hv_out_Col);
void Get_LineParameters(HObject ho_in_Image, HObject* ho_out_Contour, HTuple hv_in_Parameters,
HTuple* hv_out_Parameters, HTuple* hv_out_Flag, HTuple* hv_out_NgTails);
void rake1(HObject ho_Image, HObject * ho_Regions, HTuple hv_InParameters, HTuple * hv_ResultRow,
HTuple * hv_ResultColumn);
#endif
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
#define resultCmdSplitStart "[resultCmdSplitStart]"
#define resultCmdSplitEnd "[resultCmdSplitEnd]"
#define defectSplitStart "[defectSplitStart]"
#define defectSplitEnd "[defectSplitEnd]"
#define chartSplitStart "[chartSplitStart]"
#define chartSplitEnd "[chartSplitEnd]"
#define csvSplitStart "[csvSplitStart]"
#define csvSplitEnd "[csvSplitEnd]"
#define generalSplit "|"
//SAMPLE