|
|
|
@ -28,10 +28,8 @@ QDateTime g_ts_start;
|
|
|
|
|
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
|
|
|
|
|
|
|
|
|
|
AlgJd alg_jd[NumberOfSupportedCameras]; //检测胶点的AI算法
|
|
|
|
|
AlgJd_ng alg_jd_ng[NumberOfSupportedCameras]; // 检测卡纸、薄膜褶皱
|
|
|
|
|
#ifdef __DEBUG
|
|
|
|
|
AlgJd alg_test;//test AI算法
|
|
|
|
|
AlgKz alg_kz_test;
|
|
|
|
|
#endif
|
|
|
|
|
QThread* pThread[NumberOfSupportedCameras];
|
|
|
|
|
|
|
|
|
@ -48,7 +46,7 @@ Pylon::CBaslerUniversalInstantCamera* BaslerCamHandle[NumberOfSupportedCameras];
|
|
|
|
|
void *HIKCamHandle[NumberOfSupportedCameras];
|
|
|
|
|
CaptureThreadHIK* pHIKCaptureThread[NumberOfSupportedCameras];
|
|
|
|
|
|
|
|
|
|
SyncQueue<std::pair<std::string, cv::Mat> > *g_save_queue; //图片保存队列
|
|
|
|
|
SyncQueue<std::pair<std::string, cv::Mat>> *g_save_queue; //ͼƬ±£´æ¶ÓÁÐ
|
|
|
|
|
SyncQueue<std::pair<int, cv::Mat> > *g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张
|
|
|
|
|
ASyncQueue<bool> *g_shooted_queue[NumberOfSupportedCameras]; //
|
|
|
|
|
ASyncQueue<bool> *g_result_wait_queue[NumberOfSupportedCameras]; //
|
|
|
|
@ -92,7 +90,6 @@ VOID BeforeWork(int shoot[])
|
|
|
|
|
{
|
|
|
|
|
if (SingleCamInfo[i].Detect && SingleCamInfo[i].IsOpen) {
|
|
|
|
|
alg_jd[i].test_detect_batcht(shoot[i]);
|
|
|
|
|
alg_jd_ng[i].test_detect_batcht_ng(shoot[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -105,6 +102,7 @@ Cigarette::Cigarette(QWidget *parent)
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
InitPtrMat();
|
|
|
|
|
read_conf(g_conf_path);
|
|
|
|
|
|
|
|
|
|
if (!g_conf_path.config_path.isEmpty()) {
|
|
|
|
|
// 如果非空
|
|
|
|
|
QDir* dirinfo = new QDir(g_conf_path.config_path);
|
|
|
|
@ -276,7 +274,6 @@ Cigarette::Cigarette(QWidget *parent)
|
|
|
|
|
|
|
|
|
|
m_PLCDevice = new PLCDevice;
|
|
|
|
|
PLCDevice::init_plc(m_PLCDevice);
|
|
|
|
|
|
|
|
|
|
if(m_PLCDevice->g_plc_ok)
|
|
|
|
|
{
|
|
|
|
|
printf("Connected to dev!\n");
|
|
|
|
@ -314,36 +311,26 @@ Cigarette::Cigarette(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
if(SingleCamInfo[i].Detect){
|
|
|
|
|
cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
|
|
|
|
|
|
|
|
|
|
QString model_path, model1_name, model2_name;
|
|
|
|
|
QString model_path, model_name;
|
|
|
|
|
if (g_sys_conf.model_path.isEmpty()) {
|
|
|
|
|
model_path = "D:/model";
|
|
|
|
|
//g_sys_conf.model_path = model_path;
|
|
|
|
|
g_sys_conf.model_path = "D:/model";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
model_path = g_sys_conf.model_path;
|
|
|
|
|
|
|
|
|
|
if (g_sys_conf.model1_name.isEmpty()) {
|
|
|
|
|
model1_name = "jd.weights";
|
|
|
|
|
g_sys_conf.model1_name = model1_name;
|
|
|
|
|
model2_name = "jd_ng.weights";
|
|
|
|
|
g_sys_conf.model2_name = model2_name;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
model1_name = g_sys_conf.model1_name;
|
|
|
|
|
model2_name = g_sys_conf.model2_name;
|
|
|
|
|
if (g_sys_conf.model_name.isEmpty()) {
|
|
|
|
|
model_name = "jd.weights";
|
|
|
|
|
g_sys_conf.model_name = "jd.weights";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!alg_jd[i].init(model_path, model1_name))
|
|
|
|
|
else
|
|
|
|
|
model_name = g_sys_conf.model_name;
|
|
|
|
|
|
|
|
|
|
if (!alg_jd[i].init(model_path, model_name))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(NULL, QStringLiteral("系统自检失败"), QStringLiteral("AI模型1初始化失败,请检查程序完整性"), QMessageBox::Ok);
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
else if (!alg_jd_ng[i].init_ng(model_path, model2_name))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::information(NULL, QStringLiteral("系统自检失败"), QStringLiteral("AI模型2初始化失败,请检查程序完整性"), QMessageBox::Ok);
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
CreatWorkThread(SingleCamInfo[i].CamClass, i, this);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
@ -390,8 +377,7 @@ Cigarette::Cigarette(QWidget *parent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef __DEBUG
|
|
|
|
|
alg_test.init(g_sys_conf.model_path, g_sys_conf.model1_name);//test AI算法
|
|
|
|
|
alg_kz_test.init(g_sys_conf.model_path, g_sys_conf.model2_name);
|
|
|
|
|
alg_test.init(g_sys_conf.model_path, g_sys_conf.model_name);//test AIËã·¨
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//自动打开所有相机
|
|
|
|
@ -792,14 +778,7 @@ void Cigarette::TestImg()
|
|
|
|
|
}
|
|
|
|
|
std::vector<std::pair<int, cv::Rect> > results;
|
|
|
|
|
cv::Mat output;
|
|
|
|
|
// alg_test.detect(imagein, output, results);
|
|
|
|
|
//alg_kz_test.detect(imagein, output, results);
|
|
|
|
|
|
|
|
|
|
cv::Mat transit = imagein.clone();
|
|
|
|
|
//std::vector<std::pair<int, cv::Rect> > results;
|
|
|
|
|
alg_test.detect(imagein, transit, output, results);
|
|
|
|
|
alg_kz_test.detect(imagein, transit, output, results);
|
|
|
|
|
|
|
|
|
|
alg_test.detect(imagein, output,results);
|
|
|
|
|
std::string WindowName = "TestImg";
|
|
|
|
|
cv::namedWindow(WindowName, cv::WINDOW_NORMAL);
|
|
|
|
|
cv::imshow(WindowName, output);
|
|
|
|
@ -835,17 +814,12 @@ void Cigarette::TestImgs()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Mat output;
|
|
|
|
|
cv::Mat transit = imagein.clone();
|
|
|
|
|
std::vector<std::pair<int, cv::Rect> > results;
|
|
|
|
|
std::vector<cv::Rect> vec_jd_results;
|
|
|
|
|
std::vector<cv::Rect> vec_bm_results;
|
|
|
|
|
alg_test.detect(imagein, transit, output, results);
|
|
|
|
|
alg_kz_test.detect(imagein, transit, output, results);
|
|
|
|
|
|
|
|
|
|
std::string WindowName = "TestImgs";
|
|
|
|
|
alg_test.detect(imagein, output,results);
|
|
|
|
|
std::string WindowName = "TestImg";
|
|
|
|
|
cv::namedWindow(WindowName, cv::WINDOW_NORMAL);
|
|
|
|
|
cv::imshow(WindowName, transit);
|
|
|
|
|
int k = cv::waitKeyEx(100);
|
|
|
|
|
cv::imshow(WindowName, output);
|
|
|
|
|
int k = cv::waitKeyEx(1);
|
|
|
|
|
if (k == 27)break;//ESC键
|
|
|
|
|
#ifdef __ExportData
|
|
|
|
|
alg_test.analyse(imagein, results);
|
|
|
|
@ -2410,26 +2384,6 @@ bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
|
|
|
|
|
{ ///相似度
|
|
|
|
|
conf.ConfThreshold = atoi(line.substr(pos + 1).c_str());
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "CONFTHRESHOLDS")
|
|
|
|
|
{ ///相似度
|
|
|
|
|
std::vector<std::string> vec_info;
|
|
|
|
|
string_split(line.substr(pos + 1), "|",vec_info);
|
|
|
|
|
if (vec_info.size() == 4)
|
|
|
|
|
{
|
|
|
|
|
conf.ConfThresholds[0]=atoi(vec_info[0].c_str());// 0 胶点
|
|
|
|
|
conf.ConfThresholds[1]=atoi(vec_info[1].c_str());// 1 卡纸
|
|
|
|
|
conf.ConfThresholds[2]=atoi(vec_info[2].c_str());// 2 薄膜
|
|
|
|
|
conf.ConfThresholds[3]=atoi(vec_info[3].c_str());// 3 卡纸下
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "UP_JD_SPACE")
|
|
|
|
|
{ /// 是否自动打开相机:0否;1是
|
|
|
|
|
conf.Up_jd_Space= atoi(line.substr(pos + 1).c_str());
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "DOWN_JD_SPACE")
|
|
|
|
|
{ /// 是否自动打开相机:0否;1是
|
|
|
|
|
conf.Down_jd_Space = atoi(line.substr(pos + 1).c_str());
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "AUTO_OPEN")
|
|
|
|
|
{ /// 是否自动打开相机:0否;1是
|
|
|
|
|
conf.auto_open = atoi(line.substr(pos + 1).c_str());
|
|
|
|
@ -2483,11 +2437,7 @@ bool Cigarette::read_sys_config(SysConf &conf, QString conf_path)
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "MODELNAME")
|
|
|
|
|
{
|
|
|
|
|
conf.model1_name = line.substr(pos + 1).c_str();
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "KZMODELNAME")
|
|
|
|
|
{
|
|
|
|
|
conf.model2_name = line.substr(pos + 1).c_str();
|
|
|
|
|
conf.model_name = line.substr(pos + 1).c_str();
|
|
|
|
|
}
|
|
|
|
|
else if (tmp_key == "JPGPATH")
|
|
|
|
|
{
|
|
|
|
@ -3006,11 +2956,13 @@ void Cigarette::read_plc_items()
|
|
|
|
|
std::fstream cfg_file;
|
|
|
|
|
QString plc_file = g_conf_path.config_path + "/" + PLC_CONFIG_FILE;
|
|
|
|
|
cfg_file.open(plc_file.toLocal8Bit().constData());
|
|
|
|
|
|
|
|
|
|
if (!cfg_file.is_open())
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Error: Open production file " << PLC_CONFIG_FILE << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!cfg_file.eof())
|
|
|
|
|
{
|
|
|
|
|
char tmp[1024] = "";
|
|
|
|
@ -3844,18 +3796,25 @@ void Cigarette::CleanThreadStartAuto()
|
|
|
|
|
|
|
|
|
|
void Cigarette::record_output_statistic(qint64 quantity, int Kick[NumberOfSupportedCameras], int shift)
|
|
|
|
|
{
|
|
|
|
|
QString file_name, file_path;
|
|
|
|
|
for (int i = 0; i < NumberOfSupportedCameras; i++)
|
|
|
|
|
{
|
|
|
|
|
if (SingleCamInfo[i].IsOpen && quantity > 0) {
|
|
|
|
|
std::fstream cfg_file;
|
|
|
|
|
char str[256];
|
|
|
|
|
memset(str, 0, 256);
|
|
|
|
|
sprintf(str, STATISTIC_FILE, i);
|
|
|
|
|
//char str[256];
|
|
|
|
|
//memset(str, 0, 256);
|
|
|
|
|
//sprintf(str, STATISTIC_FILE, i);
|
|
|
|
|
//char buf[256];
|
|
|
|
|
//memset(buf, 0, 256);
|
|
|
|
|
//sprintf(buf, "%s/%s", g_conf_path.config_path.toLocal8Bit().constData(), str);
|
|
|
|
|
file_name = QString(STATISTIC_FILE).arg(i);
|
|
|
|
|
file_path = g_conf_path.config_path + "/" + file_name;
|
|
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
|
sprintf(buf, "%s/%s", g_conf_path.config_path.toLocal8Bit().constData(), str);
|
|
|
|
|
|
|
|
|
|
sprintf(buf, "%s", file_path.toLocal8Bit().constData());
|
|
|
|
|
//std::cout<<"===buf>"<<buf<<std::endl;
|
|
|
|
|
|
|
|
|
|
cfg_file.open(buf, std::ios::app);
|
|
|
|
|
if (cfg_file.good())
|
|
|
|
|
{
|
|
|
|
@ -4058,14 +4017,18 @@ void Cigarette::recMsgFromUdp(QString data)
|
|
|
|
|
}
|
|
|
|
|
else if (data == "GETCONF")
|
|
|
|
|
{
|
|
|
|
|
QString file_name, file_path;
|
|
|
|
|
sThread.sendFile(g_conf_path.config_path, g_sys_conf.FilePort);
|
|
|
|
|
for(int i=0;i<NumberOfSupportedCameras;i++)
|
|
|
|
|
{
|
|
|
|
|
char buf[256];
|
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
|
sprintf(buf, STATISTIC_FILE, i);
|
|
|
|
|
QString str(buf);
|
|
|
|
|
sThread.sendFile(str.toLocal8Bit().constData(), g_sys_conf.FilePort);
|
|
|
|
|
//char buf[256];
|
|
|
|
|
//memset(buf, 0, 256);
|
|
|
|
|
//sprintf(buf, STATISTIC_FILE, i);
|
|
|
|
|
//QString str(buf);
|
|
|
|
|
|
|
|
|
|
file_name = QString(STATISTIC_FILE).arg(i);
|
|
|
|
|
file_path = g_conf_path.config_path + "/" + file_name;
|
|
|
|
|
sThread.sendFile(file_path.toLocal8Bit().constData(), g_sys_conf.FilePort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|