|
|
@ -1,6 +1,5 @@
|
|
|
|
#include "workthread.h"
|
|
|
|
#include "workthread.h"
|
|
|
|
#include "alg_jd.h"
|
|
|
|
#include "alg_jd.h"
|
|
|
|
#include "alg_jd_ng.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "balluffcamera.h"
|
|
|
|
#include "balluffcamera.h"
|
|
|
|
#include "baslercamera.h"
|
|
|
|
#include "baslercamera.h"
|
|
|
@ -9,8 +8,6 @@
|
|
|
|
#include "exportData.h"
|
|
|
|
#include "exportData.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
|
|
|
|
extern AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
|
|
|
|
extern AlgJd_ng alg_jd_ng[NumberOfSupportedCameras]; // ng模型
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern ConfPath g_conf_path;
|
|
|
|
extern ConfPath g_conf_path;
|
|
|
|
extern SysConf g_sys_conf; //系统配置参数
|
|
|
|
extern SysConf g_sys_conf; //系统配置参数
|
|
|
|
extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
|
|
|
|
extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
|
|
|
@ -18,8 +15,8 @@ extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
|
|
|
|
extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度
|
|
|
|
extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度
|
|
|
|
extern bool isNeedRotate[NumberOfSupportedCameras];
|
|
|
|
extern bool isNeedRotate[NumberOfSupportedCameras];
|
|
|
|
|
|
|
|
|
|
|
|
extern SyncQueue<std::pair<std::string, cv::Mat>> *g_save_queue; //图片保存队列
|
|
|
|
extern SyncQueue<std::pair<std::string, cv::Mat> >* g_save_queue; //图片保存队列
|
|
|
|
extern SyncQueue<std::pair<int, cv::Mat>> *g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
|
|
|
|
extern SyncQueue<std::pair<int, cv::Mat> >* g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
|
|
|
|
extern SyncQueue<_UDPSendInfo> *UDP_Info_queue;
|
|
|
|
extern SyncQueue<_UDPSendInfo> *UDP_Info_queue;
|
|
|
|
extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
|
|
|
|
extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
|
|
|
|
extern PLCDevice* m_PLCDevice;
|
|
|
|
extern PLCDevice* m_PLCDevice;
|
|
|
@ -62,9 +59,6 @@ void WorkThread::run()
|
|
|
|
local_SysConf.shoot[local_camera_number] = g_sys_conf.shoot[local_camera_number];
|
|
|
|
local_SysConf.shoot[local_camera_number] = g_sys_conf.shoot[local_camera_number];
|
|
|
|
local_SysConf.MisMatchAct = g_sys_conf.MisMatchAct;
|
|
|
|
local_SysConf.MisMatchAct = g_sys_conf.MisMatchAct;
|
|
|
|
local_SysConf.ConfThreshold = g_sys_conf.ConfThreshold;//
|
|
|
|
local_SysConf.ConfThreshold = g_sys_conf.ConfThreshold;//
|
|
|
|
local_SysConf.Up_jd_Space = g_sys_conf.Up_jd_Space;
|
|
|
|
|
|
|
|
local_SysConf.Down_jd_Space = g_sys_conf.Down_jd_Space;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)local_SysConf.no[local_camera_number][i] = g_sys_conf.no[local_camera_number][i];
|
|
|
|
for (int i = 0; i < 3; i++)local_SysConf.no[local_camera_number][i] = g_sys_conf.no[local_camera_number][i];
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DRAW_RECT
|
|
|
|
#ifdef DRAW_RECT
|
|
|
@ -79,6 +73,7 @@ void WorkThread::run()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QDateTime now_ts = QDateTime::currentDateTime();
|
|
|
|
QDateTime now_ts = QDateTime::currentDateTime();
|
|
|
|
std::pair<int, cv::Mat> element;
|
|
|
|
std::pair<int, cv::Mat> element;
|
|
|
|
local_g_image_queue->take(element);
|
|
|
|
local_g_image_queue->take(element);
|
|
|
@ -101,19 +96,18 @@ void WorkThread::run()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像
|
|
|
|
cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (local_SysConf.shoot[local_camera_number] == unit_count)
|
|
|
|
if (local_SysConf.shoot[local_camera_number] == unit_count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
exportDataInfo.shotCounts = unit_count;
|
|
|
|
exportDataInfo.shotCounts = unit_count;
|
|
|
|
std::vector<cv::Mat> vec_in;
|
|
|
|
std::vector<cv::Mat> vec_in;
|
|
|
|
int w = image.cols;
|
|
|
|
int w = image.cols;
|
|
|
|
int h = image.rows / unit_count;
|
|
|
|
int h = image.rows / unit_count;
|
|
|
|
for (int index = 0; index < unit_count; index++)
|
|
|
|
for(int index=0;index<unit_count;index++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::Rect temp_Rect(0, h * index, w, h);
|
|
|
|
cv::Rect temp_Rect(0, h * index, w, h);
|
|
|
|
cv::Mat temp_image = image(temp_Rect).clone();
|
|
|
|
cv::Mat temp_image = image(temp_Rect).clone();
|
|
|
|
if (isNeedRotate[local_camera_number]) {
|
|
|
|
if (isNeedRotate[local_camera_number]) {
|
|
|
|
if (rotationAngle[local_camera_number] != (cv::ROTATE_90_COUNTERCLOCKWISE + 1))
|
|
|
|
if(rotationAngle[local_camera_number] != (cv::ROTATE_90_COUNTERCLOCKWISE + 1))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::rotate(temp_image, temp_image, rotationAngle[local_camera_number]);
|
|
|
|
cv::rotate(temp_image, temp_image, rotationAngle[local_camera_number]);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -122,47 +116,31 @@ void WorkThread::run()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<cv::Mat> vec_out;
|
|
|
|
std::vector<cv::Mat> vec_out;
|
|
|
|
|
|
|
|
std::vector<std::vector<std::pair<int, cv::Rect> > > vec_results;
|
|
|
|
//单张
|
|
|
|
|
|
|
|
cv::Mat transits;
|
|
|
|
|
|
|
|
std::vector<std::pair<int, cv::Rect>> results;
|
|
|
|
|
|
|
|
std::vector<std::pair<int, cv::Rect>> results_ng;
|
|
|
|
|
|
|
|
//多张
|
|
|
|
|
|
|
|
std::vector<cv::Mat> transits_ng;
|
|
|
|
|
|
|
|
std::vector<std::vector<std::pair<int, cv::Rect>>> vec_results;
|
|
|
|
|
|
|
|
std::vector<std::vector<std::pair<int, cv::Rect>>> vec_results_ng;
|
|
|
|
|
|
|
|
QDateTime ts_start = QDateTime::currentDateTime();
|
|
|
|
QDateTime ts_start = QDateTime::currentDateTime();
|
|
|
|
if (unit_count == 1) {
|
|
|
|
if(unit_count == 1){
|
|
|
|
//std::vector<std::pair<int, cv::Rect>> results;
|
|
|
|
std::vector<std::pair<int, cv::Rect> > results;
|
|
|
|
//std::vector<std::pair<int, cv::Rect>> results_ng;
|
|
|
|
cv::Mat imagein,imageout;
|
|
|
|
cv::Mat imagein, imageout;
|
|
|
|
|
|
|
|
imagein = vec_in[0];
|
|
|
|
imagein = vec_in[0];
|
|
|
|
alg_jd[local_camera_number].detect(imagein, imageout, results);
|
|
|
|
alg_jd[local_camera_number].detect(imagein, imageout, results);
|
|
|
|
transits = imageout.clone();
|
|
|
|
|
|
|
|
alg_jd_ng[local_camera_number].detect_ng(imagein, transits, imageout, results_ng);
|
|
|
|
|
|
|
|
vec_out.push_back(imageout.clone());
|
|
|
|
vec_out.push_back(imageout.clone());
|
|
|
|
vec_results.push_back(results);
|
|
|
|
vec_results.push_back(results);
|
|
|
|
vec_results_ng.push_back(results_ng);
|
|
|
|
}else{
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
alg_jd[local_camera_number].detect_batch(vec_in, vec_out, vec_results);
|
|
|
|
alg_jd[local_camera_number].detect_batch(vec_in, vec_out, vec_results);
|
|
|
|
for (int i = 0; i < vec_out.size(); i++)
|
|
|
|
|
|
|
|
transits_ng.push_back(vec_out[i]);
|
|
|
|
|
|
|
|
alg_jd_ng[local_camera_number].detect_batch_ng(vec_in, transits_ng, vec_out, vec_results_ng);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QDateTime ts_jd = QDateTime::currentDateTime();
|
|
|
|
QDateTime ts_jd = QDateTime::currentDateTime();
|
|
|
|
int time_process = ts_start.msecsTo(ts_jd);
|
|
|
|
int time_process = ts_start.msecsTo(ts_jd);
|
|
|
|
emit display_timecost(local_camera_number, time_process);
|
|
|
|
emit display_timecost(local_camera_number, time_process);
|
|
|
|
//UDPSendInfo.timecost = QString::number(time_process);
|
|
|
|
UDPSendInfo.timecost = QString::number(time_process);
|
|
|
|
//exportDataInfo.timeCost = QString::number(time_process).toStdString();
|
|
|
|
exportDataInfo.timeCost = QString::number(time_process).toStdString();
|
|
|
|
|
|
|
|
|
|
|
|
cv::Mat image1;
|
|
|
|
cv::Mat image1;
|
|
|
|
cv::Mat image2;
|
|
|
|
cv::Mat image2;
|
|
|
|
|
|
|
|
|
|
|
|
QString jd_no;
|
|
|
|
QString jd_no;
|
|
|
|
for (int index = 0; index < unit_count; index++)
|
|
|
|
for(int index=0;index<unit_count;index++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
jd_no += QString::number(vec_results[index].size()) + ",";
|
|
|
|
jd_no += QString::number(vec_results[index].size())+",";
|
|
|
|
exportDataInfo.jd[index] = vec_results[index].size();
|
|
|
|
exportDataInfo.jd[index] = vec_results[index].size();
|
|
|
|
exportDataInfo.isJdExist[index] = vec_results[index].size() > 0;
|
|
|
|
exportDataInfo.isJdExist[index] = vec_results[index].size() > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -171,10 +149,10 @@ void WorkThread::run()
|
|
|
|
UDPSendInfo.JD = jd_no;
|
|
|
|
UDPSendInfo.JD = jd_no;
|
|
|
|
|
|
|
|
|
|
|
|
bool IsNG = false;
|
|
|
|
bool IsNG = false;
|
|
|
|
bool IsNG_model2[3] = { false };
|
|
|
|
for(int index=0;index<unit_count;index++)
|
|
|
|
for (int index = 0; index < unit_count; index++)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (vec_results[index].size() < local_SysConf.no[local_camera_number][index])IsNG |= true;
|
|
|
|
if(vec_results[index].size() < local_SysConf.no[local_camera_number][index])IsNG |= true;
|
|
|
|
|
|
|
|
//if (vec_results[index].size() != 1)IsNG |= true;//反向训练
|
|
|
|
if (local_SysConf.ConfThreshold == 0)IsNG = false;
|
|
|
|
if (local_SysConf.ConfThreshold == 0)IsNG = false;
|
|
|
|
if (local_SysConf.save == 2)//三张照片分别存储
|
|
|
|
if (local_SysConf.save == 2)//三张照片分别存储
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -184,12 +162,13 @@ void WorkThread::run()
|
|
|
|
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
|
|
|
|
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
|
|
|
|
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
|
|
|
|
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
|
|
|
|
"#" + "_" + QString::number(index + 1) + ".jpg";
|
|
|
|
"#" + "_" + QString::number(index + 1) + ".jpg";
|
|
|
|
g_save_queue->put(std::make_pair(file_name.toStdString(), m));
|
|
|
|
|
|
|
|
|
|
|
|
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (unit_count >= 2){
|
|
|
|
if (unit_count >= 2){
|
|
|
|
image1 = vec_out[0].clone();
|
|
|
|
image1 = vec_out[(result_index) % 2].clone();
|
|
|
|
#ifdef DRAW_RECT
|
|
|
|
#ifdef DRAW_RECT
|
|
|
|
IsNG|=CheckSelectRects(image1,vec_results,(result_index) % 2,local_DisplayLabelConf,0);
|
|
|
|
IsNG|=CheckSelectRects(image1,vec_results,(result_index) % 2,local_DisplayLabelConf,0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -211,54 +190,16 @@ void WorkThread::run()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result_index++;
|
|
|
|
result_index++;
|
|
|
|
//exportDataInfo.isNg = IsNG;
|
|
|
|
exportDataInfo.isNg = IsNG;
|
|
|
|
|
|
|
|
|
|
|
|
////jinhuan+
|
|
|
|
|
|
|
|
//if (vec_jd_results.size() && vec_kzjl_results.size())
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// //从上往下第一个胶点的中心y值
|
|
|
|
|
|
|
|
// int top_jd_y = vec_jd_results[0].y + vec_jd_results[0].height / 2;
|
|
|
|
|
|
|
|
// //从上往下最后一个胶点的中心y值
|
|
|
|
|
|
|
|
// int bottom_jd_y = vec_jd_results[vec_jd_results.size()-1].y + vec_jd_results[vec_jd_results.size()-1].height / 2;
|
|
|
|
|
|
|
|
// //卡纸的上边沿y值
|
|
|
|
|
|
|
|
// int top_kz_y = vec_kzjl_results[0].tl().y;
|
|
|
|
|
|
|
|
// //卡纸的下边沿y值
|
|
|
|
|
|
|
|
// int bottom_kz_y = vec_kzjl_results[0].br().y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //if (abs(top_jd_y - top_kz_y) < local_SysConf.Up_jd_Space)IsNG=true;//像素
|
|
|
|
|
|
|
|
// //if (abs(bottom_kz_y - bottom_jd_y) < local_SysConf.Down_jd_Space)IsNG = true;//像素
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//else
|
|
|
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
// IsNG = true;//卡纸和胶点数量不够
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (vec_kzzz_results.size() != 0) {//卡纸有褶皱
|
|
|
|
|
|
|
|
// IsNG = true;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (vec_bm_results.size() != 0) {//薄膜有褶皱
|
|
|
|
|
|
|
|
// IsNG = true;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//if (vec_qb_results.size() != 0) {//卡纸有翘边
|
|
|
|
|
|
|
|
// IsNG = true;
|
|
|
|
|
|
|
|
// IsNG_model2[2] = IsNG;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
////jinhuan-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < unit_count; index++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (results_ng.size() != 0 || vec_results_ng[index].size() != 0) {//ng模型检测:有ng
|
|
|
|
|
|
|
|
IsNG = true;
|
|
|
|
|
|
|
|
IsNG_model2[index] = IsNG;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!IsNG)
|
|
|
|
if (!IsNG)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!g_debug_mode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
emit event_ok(local_camera_number);
|
|
|
|
emit event_ok(local_camera_number);
|
|
|
|
local_g_result_queue->put(true);
|
|
|
|
local_g_result_queue->put(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!g_debug_mode)
|
|
|
|
if (!g_debug_mode)
|
|
|
@ -270,8 +211,6 @@ void WorkThread::run()
|
|
|
|
if ((local_SysConf.save == 2) || (local_SysConf.save == 1))
|
|
|
|
if ((local_SysConf.save == 2) || (local_SysConf.save == 1))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for(int index=0;index<unit_count;index++)
|
|
|
|
for(int index=0;index<unit_count;index++)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((vec_results[index].size() < local_SysConf.no[local_camera_number][index])|| IsNG_model2[index])
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cv::Mat m = vec_in[index].clone();
|
|
|
|
cv::Mat m = vec_in[index].clone();
|
|
|
|
QString file_name = g_conf_path.save_pics_path + "/ng/" +
|
|
|
|
QString file_name = g_conf_path.save_pics_path + "/ng/" +
|
|
|
@ -279,16 +218,15 @@ void WorkThread::run()
|
|
|
|
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
|
|
|
|
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
|
|
|
|
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
|
|
|
|
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
|
|
|
|
"#" + "_" + QString::number(index + 1) + ".jpg";
|
|
|
|
"#" + "_" + QString::number(index + 1) + ".jpg";
|
|
|
|
g_save_queue->put(std::make_pair(file_name.toStdString(), m));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*m = vec_out[index].clone();
|
|
|
|
/*m = vec_out[index].clone();
|
|
|
|
file_name = g_conf_path.save_pics_path + "/ng_result/" +
|
|
|
|
file_name = "D:/image/" +
|
|
|
|
now_ts.toString("yyyy-MM-dd") + "/"
|
|
|
|
now_ts.toString("yyyy-MM-dd") +
|
|
|
|
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
|
|
|
|
"/" + QString::number(local_camera_number + 1) +
|
|
|
|
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
|
|
|
|
"/ng_result/" + QString::number(index) + "/" +
|
|
|
|
"#" + "_" + QString::number(index + 1) + ".jpg";
|
|
|
|
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "_" + QString::number(index) + ".bmp";*/
|
|
|
|
g_save_queue->put(std::make_pair(file_name.toStdString(), m));*/
|
|
|
|
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
|
|
|
|
}
|
|
|
|
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|