diff --git a/Cigarette/CaptureThread.cpp b/Cigarette/CaptureThread.cpp index 9b8ba4b..1722aa0 100644 --- a/Cigarette/CaptureThread.cpp +++ b/Cigarette/CaptureThread.cpp @@ -1,7 +1,7 @@ #include "CaptureThread.h" #include "common.h" -extern bool g_debug_mode; //相机调试模式,调试模式必须暂停状态才能打开 +extern bool g_debug_mode; //相机调试模式,工作模式必须停止状态才能打开 //----------------------------------------------------------------------------- CaptureThread::CaptureThread( Device* pCurrDev, bool boTerminated, FunctionInterface* pFI_ ,int Num) : @@ -10,6 +10,15 @@ CaptureThread::CaptureThread( Device* pCurrDev, bool boTerminated, FunctionInter { p_unit_queue = new ASyncQueue(Unit_Queue_Size); } + +void CaptureThread::fpsTimeout(void) +{ + uint64_t delta = m_cntGrabbedImages - m_cntLastGrabbedImages; + m_cntLastGrabbedImages = m_cntGrabbedImages; + QString data = QString("%1").arg(delta); + emit updateStatistics(data.left(4), Local_Num); +} + CaptureThread::~CaptureThread() { delete p_unit_queue; @@ -100,10 +109,10 @@ void CaptureThread::process( void ) } cnt++; // display some statistics - if (cnt % 100 == 0) + if (cnt % 10 == 0) { QString data = QString::fromStdString(statistics.framesPerSecond.readS()); - emit updateStatistics(data.left(4),Local_Num); + emit updateStatistics(data.left(3),Local_Num); } } else diff --git a/Cigarette/CaptureThread.h b/Cigarette/CaptureThread.h index 264393b..1c492a3 100644 --- a/Cigarette/CaptureThread.h +++ b/Cigarette/CaptureThread.h @@ -108,9 +108,13 @@ signals: private slots: void process( void ); + void fpsTimeout(void); public: int Local_Num; + QTimer* m_Timer; + uint64_t m_cntGrabbedImages = 0; + uint64_t m_cntLastGrabbedImages = 0; SyncQueue > *p_image_queue; ASyncQueue *p_unit_queue; ASyncQueue *p_result_queue; diff --git a/Cigarette/CaptureThreadHIK.cpp b/Cigarette/CaptureThreadHIK.cpp index 20f136e..2eb66b2 100644 --- a/Cigarette/CaptureThreadHIK.cpp +++ b/Cigarette/CaptureThreadHIK.cpp @@ -3,7 +3,7 @@ #include "PLCDevice.h" #include "common.h" #include -extern bool g_debug_mode; //相机调试模式,调试模式必须暂停状态才能打开 +extern bool g_debug_mode; //相机调试模式,工作模式必须停止状态才能打开 extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras]; extern PLCDevice * m_PLCDevice; @@ -231,7 +231,7 @@ void CaptureThreadHIK::process( void ) nRet = MV_CC_RegisterExceptionCallBack(CamHandle, LossCallBack[Local_Num], this); if (nRet) { std::cout << "can not register loss callback" << std::endl; nnRet = nRet; } -#ifdef IMM_FEED_BACK ///不打开无反馈等 +#ifdef IMM_FEED_BACK ///不打开无反馈等( 延后一次两次用ifndef // 不延后用ifdef) nRet = MV_CC_SetEnumValueByString(CamHandle, "EventSelector", "Line0FallingEdge"); if (nRet) { std::cout << "can not set EventSelector" << std::endl; nnRet = nRet; } diff --git a/Cigarette/Cigarette.vcxproj.user b/Cigarette/Cigarette.vcxproj.user index 18bfb80..02760dc 100644 --- a/Cigarette/Cigarette.vcxproj.user +++ b/Cigarette/Cigarette.vcxproj.user @@ -2,11 +2,11 @@ - C:\Qt\5.15.2\msvc2019_64 - PATH=$(QTDIR)\bin%3b$(PATH) + D:\Qt\5.15.2\msvc2019_64 + PATH=$(QTDIR)\bin%3bD:\Qt\5.15.2\msvc2019_64\bin%3b$(PATH) - C:\Qt\5.15.2\msvc2019_64 - PATH=$(QTDIR)\bin%3b$(PATH) + D:\Qt\5.15.2\msvc2019_64 + PATH=$(QTDIR)\bin%3bD:\Qt\5.15.2\msvc2019_64\bin%3b$(PATH) \ No newline at end of file diff --git a/Cigarette/CryptoToolLib.lib b/Cigarette/CryptoToolLib.lib index 3c7cebf..14f8487 100644 Binary files a/Cigarette/CryptoToolLib.lib and b/Cigarette/CryptoToolLib.lib differ diff --git a/Cigarette/alg_jd.cpp b/Cigarette/alg_jd.cpp index ca7e78c..6f1176d 100644 --- a/Cigarette/alg_jd.cpp +++ b/Cigarette/alg_jd.cpp @@ -22,18 +22,18 @@ static int inpHeight = 416; // Height of network's input image static std::vector classes; -bool AlgJd::init(QString path_model, QString model_name) +bool AlgJd::init(QString model_path, QString model_name) { // Load names of classes std::string classesFile; cv::String modelConfiguration; cv::String modelWeights; - if (path_model.length() > 0 && model_name.length() > 0) { + if (model_path.length() > 0 && model_name.length() > 0) { // 拼凑的模型文件路径 - modelWeights = path_model.toStdString() + "/" + model_name.toStdString(); - modelConfiguration = path_model.toStdString() + "/jd.cfg"; - classesFile = path_model.toStdString() + "/jd.names"; + modelWeights = model_path.toStdString() + "/" + model_name.toStdString(); + modelConfiguration = model_path.toStdString() + "/jd.cfg"; + classesFile = model_path.toStdString() + "/jd.names"; } else { modelWeights = "D:/model/jd.weights"; @@ -59,14 +59,14 @@ bool AlgJd::init(QString path_model, QString model_name) net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); - cv::Mat image = cv::imread("alg_jd.bmp"); - //cv::Mat image; - //if (path_jpg.length() > 0) { - // image = cv::imread(path_jpg.toStdString()); - //} - //else { - // image = cv::imread("D:/Release/alg_jd.bmp"); - //} + //cv::Mat image = cv::imread("alg_jd.bmp"); + cv::Mat image; + if (g_sys_conf.jpg_path.length() > 0) { + image = cv::imread(g_sys_conf.jpg_path.toStdString()); + } + else { + image = cv::imread("D:/Release/alg_jd.bmp"); + } //识别一张图,测试模型是否正确,并且完成GPU数据加载 if (!image.data) return false; //判断测试图片是否正常读取 diff --git a/Cigarette/alg_jd.h b/Cigarette/alg_jd.h index a86e80f..4f19712 100644 --- a/Cigarette/alg_jd.h +++ b/Cigarette/alg_jd.h @@ -12,7 +12,7 @@ class AlgJd { public: - bool init(QString path_model, QString model_name); + bool init(QString model_path, QString model_name); bool test_detect(); bool test_detect_batcht(int shoot); int detect(cv::Mat& in, cv::Mat &out, std::vector > &results); diff --git a/Cigarette/cigarette.cpp b/Cigarette/cigarette.cpp index 6ddfa06..37c7d01 100644 --- a/Cigarette/cigarette.cpp +++ b/Cigarette/cigarette.cpp @@ -8,19 +8,19 @@ #include #include "exportData.h" - - -int g_op_time; //OP权限时长(默认300秒) - -int g_admin_time; //ADMINOP权限时长(默认300秒) +int g_op_time; //操作员权限时长(默认300秒) +int g_admin_time; //管理员操作权限时长(默认300秒) int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度 -bool isNeddRotate[NumberOfSupportedCameras]; +bool isNeedRotate[NumberOfSupportedCameras]; -SysConf g_sys_conf; //系统配置参数 -ModbusConf g_modbus_conf; //modbus地址 DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras]; + +SysConf g_sys_conf; //系统配置参数 +ModbusConf g_modbus_conf; //modbus地址参数 PLCDevice * m_PLCDevice; +bool g_plc_dialog_open; //是否打开plc配置对话框 + QDateTime g_ts_start; extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras]; @@ -50,8 +50,9 @@ ASyncQueue *g_shooted_queue[NumberOfSupportedCameras]; // ASyncQueue *g_result_wait_queue[NumberOfSupportedCameras]; // ASyncQueue *g_double_queue[NumberOfSupportedCameras]; // ASyncQueue *g_result_queue[NumberOfSupportedCameras]; // -bool g_debug_mode; //相机调试模式,调试模式必须暂停状态才能打开 +bool g_debug_mode; //相机调试模式,工作模式必须暂停状态才能打开 SyncQueue *g_debug_queue[NumberOfSupportedCameras]; //相机调试模式图像队列 + SyncQueue<_UDPSendInfo> *UDP_Info_queue; SyncQueue<_ExportDataInfo> *export_Data_Info_queue; ExportDataThread exportDataThread; @@ -64,16 +65,12 @@ bool g_op_mode; // QString g_op_pswd; //操作员密码 -bool g_plc_dialog_open; //是否打开plc配置对话框 - -bool g_working; //true 开始工作状态; false 暂停工作状态 +bool g_working; //true 开始工作状态; false 停止工作状态 int last_shift; //记录上一次班 QStringList g_alarm_msg; - std::vector g_vec_alarm; - int g_last_alarm_code; int g_lst_quantiy; //上一秒的产量 @@ -141,7 +138,7 @@ Cigarette::Cigarette(QWidget *parent) g_debug_queue[i]->name = format("debug_%d", i); if (update_rotate) { rotationAngle[i] = cv::ROTATE_90_COUNTERCLOCKWISE + 1; - isNeddRotate[i] = false; + isNeedRotate[i] = false; } } if (update_rotate) { @@ -151,7 +148,7 @@ Cigarette::Cigarette(QWidget *parent) } g_debug_mode = false; - g_admin_mode = true; + g_admin_mode = false; g_admin_time = ADMIN_TIME; g_admin_pswd = read_pswd(); @@ -178,7 +175,6 @@ Cigarette::Cigarette(QWidget *parent) g_last_alarm_code = 0; - g_ts_start = QDateTime::currentDateTime(); for(int i=0;idisplay(0); ui.lcdNumber_total_no_last->display(0); @@ -205,14 +203,6 @@ Cigarette::Cigarette(QWidget *parent) read_sys_config(g_sys_conf); //初始化系统配置 - //g_modbus_conf.kick1 = 0; - //g_modbus_conf.kick2 = 0; - //g_modbus_conf.kick3 = 0; - //g_modbus_conf.kick4 = 0; - //g_modbus_conf.kick5 = 0; - //g_modbus_conf.kick6 = 0; - //g_modbus_conf.kick7 = 0; - //g_modbus_conf.kick8 = 0; #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>0) g_modbus_conf.kick1 = 0; //1#通道剔除个数地址 #endif @@ -226,16 +216,16 @@ Cigarette::Cigarette(QWidget *parent) g_modbus_conf.kick4 = 0; //4#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>4) - g_modbus_conf.kick5 = 0; //1#通道剔除个数地址 + g_modbus_conf.kick5 = 0; //5#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>5) - g_modbus_conf.kick6 = 0; //2#通道剔除个数地址 + g_modbus_conf.kick6 = 0; //6#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>6) - g_modbus_conf.kick7 = 0; //3#通道剔除个数地址 + g_modbus_conf.kick7 = 0; //7#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>7) - g_modbus_conf.kick8 = 0; //4#通道剔除个数地址 + g_modbus_conf.kick8 = 0; //8#通道剔除个数地址 #endif g_modbus_conf.quantity = 0; g_modbus_conf.shift = 0; @@ -314,17 +304,71 @@ Cigarette::Cigarette(QWidget *parent) { if(SingleCamInfo[i].Detect){ cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);")); - if (!alg_jd[i].init(g_sys_conf.path_model,g_sys_conf.model_name)) + QString model_path, model_name; + if (g_sys_conf.model_path.isEmpty()) { + model_path = "D:/model"; + g_sys_conf.model_path = "D:/model"; + } + else + model_path = g_sys_conf.model_path; + + if (g_sys_conf.model_name.isEmpty()) { + model_name = "jd.weights"; + g_sys_conf.model_name = "jd.weights"; + } + 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); } CreatWorkThread(SingleCamInfo[i].CamClass, i, this); } - } -#ifdef __DEBUG - alg_test.init(g_sys_conf.path_model,g_sys_conf.path_jpg); + else { + QDateTime ts_start = QDateTime::currentDateTime(); + QTime time = QTime::currentTime(); + QDateTime local(ts_start); + QString localTime = local.toString("yyyy-MM-dd hh:mm:ss"); + + if (g_modbus_conf.alarm > 0) + { + uint16_t dest16[2] = { 5+i,0 }; + int ret = m_PLCDevice->write_short_2_plc(g_modbus_conf.alarm, 2, dest16); + //if (ret > 0) SingleCamInfo[0].OffLine = false; + + if (ret > 0) + { + AlarmInfo alarm_info; + alarm_info.alarm_code = dest16[0]; + if ((alarm_info.alarm_code > 0) && (alarm_info.alarm_code <= 12)) + { + alarm_info.alarm_msg = (g_alarm_msg[alarm_info.alarm_code]).toStdString(); + alarm_info.alarm_start = localTime.toStdString(); + ui.label_alarm->setText(g_alarm_msg[alarm_info.alarm_code]); + ui.label_alarm->setStyleSheet(tr("background-color: rgb(255, 0, 0);")); + if (g_last_alarm_code != alarm_info.alarm_code) + { + g_vec_alarm.push_back(alarm_info); + g_last_alarm_code = alarm_info.alarm_code; + } + } + else if (alarm_info.alarm_code == 0) { + ui.label_alarm->setStyleSheet(tr("background-color: rgb(0, 170, 0);")); + ui.label_alarm->setText(QStringLiteral("无报警")); + } +#ifdef __UDPSend + QString str; + str = QString("alarm") + '_' + QString::number(alarm_info.alarm_code); + sThread.sendData(str, g_sys_conf.FeedbackPort); #endif + } + } + } + + } + //自动打开所有相机 if (g_sys_conf.auto_open == 1) { @@ -403,8 +447,10 @@ Cigarette::Cigarette(QWidget *parent) connect(pTimer_Cam_signalMapper, SIGNAL(mapped(int)), this, SLOT(OpenCamTimeoutHub(int))); connect(image_lable_DBsignalMapper0, SIGNAL(mapped(int)), this, SLOT(OnDBClickHub(int))); connect(image_lable_DBsignalMapper1, SIGNAL(mapped(int)), this, SLOT(OnDBClickHub(int))); +#ifdef DRAW_RECT connect(image_lable_TPsignalMapper0, SIGNAL(mapped(int)), this, SLOT(OnTPClickHub(int))); connect(image_lable_TPsignalMapper1, SIGNAL(mapped(int)), this, SLOT(OnTPClickHub(int))); +#endif connect(label_ng_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnDBClickNGHub(int))); connect(RotateReleased_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnRotateReleasedHub(int))); @@ -805,7 +851,7 @@ void Cigarette::OnRotateReleasedHub(int Num)// { QString str = "Start to rotate picture " + QString::number(90 * ((rotationAngle[Num] + 1) % 4)) + " degrees of camera " + QString::number(Num) + "."; emit sengMsgToClog(str); - if(isNeddRotate[Num] == true) + if(isNeedRotate[Num] == true) { rotationAngle[Num] = (rotationAngle[Num] + 1) % 4; save_rotate_message(); @@ -1048,7 +1094,7 @@ void Cigarette::DrawRect_init(int Num_Cnt) { cfg_file.open(buf); if (!cfg_file.is_open()) { - std::cout << "Error: Open config file SelectRects.txt" << std::endl; + std::cout << "Error: Open config file SelectRects"<0) else if (tmp_key == "EXPO1") @@ -2560,7 +2604,7 @@ bool Cigarette::read_rotate_message() if (rotate_message.length() > NumberOfSupportedCameras*2) { for (int i = 0; i < NumberOfSupportedCameras; i++) { - isNeddRotate[i] = rotate_message[i * 2].toInt(); + isNeedRotate[i] = rotate_message[i * 2].toInt(); rotationAngle[i] = rotate_message[i * 2 + 1].toInt(); } } @@ -2590,7 +2634,7 @@ bool Cigarette::save_rotate_message() for (int i = 0; i < NumberOfSupportedCameras; i++) { char tmp[8]; memset(tmp, 0, 8); - itoa(isNeddRotate[i], tmp, 10); + itoa(isNeedRotate[i], tmp, 10); cfg_file.write(tmp, 1); cfg_file.write(",", 1); memset(tmp, 0, 8); @@ -2860,7 +2904,6 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose) pCaptureThread[Num]->p_result_wait_queue = g_result_wait_queue[Num]; pCaptureThread[Num]->p_double_queue = g_double_queue[Num]; pCaptureThread[Num]->p_shooted_queue = g_shooted_queue[Num]; - pCaptureThread[Num]->p_debug_queue = g_debug_queue[Num]; pThread[Num] = new QThread; @@ -2871,7 +2914,8 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose) //connect(pCaptureThread[Num], SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(pCaptureThread[Num], SIGNAL(finished()), pThread[Num], SLOT(quit())); connect(pCaptureThread[Num], SIGNAL(finished()), pCaptureThread[Num], SLOT(deleteLater())); - connect(pCaptureThread[Num], SIGNAL(updateStatistics(const QString&,int)), this, SLOT(updateStatisticsHub(const QString&,int))); + if(!g_debug_mode) + connect(pCaptureThread[Num], SIGNAL(updateStatistics(const QString&,int)), this, SLOT(updateStatisticsHub(const QString&,int))); pThread[Num]->start(); if (pThread[Num]->isRunning()) @@ -2987,7 +3031,8 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose) //connect(pBaslerCaptureThread[Num], SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(pBaslerCaptureThread[Num], SIGNAL(finished()), pThread[Num], SLOT(quit())); connect(pBaslerCaptureThread[Num], SIGNAL(finished()), pBaslerCaptureThread[Num], SLOT(deleteLater())); - connect(pBaslerCaptureThread[Num], SIGNAL(updateStatistics(const QString&, int)), this, SLOT(updateStatisticsHub(const QString&, int))); + if(!g_debug_mode) + connect(pBaslerCaptureThread[Num], SIGNAL(updateStatistics(const QString&, int)), this, SLOT(updateStatisticsHub(const QString&, int))); pThread[Num]->start(); if (pThread[Num]->isRunning()) @@ -3110,7 +3155,8 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose) //connect(pHIKCaptureThread[Num], SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(pHIKCaptureThread[Num], SIGNAL(finished()), pThread[Num], SLOT(quit())); connect(pHIKCaptureThread[Num], SIGNAL(finished()), pHIKCaptureThread[Num], SLOT(deleteLater())); - connect(pHIKCaptureThread[Num], SIGNAL(updateStatistics(const QString&,int)), this, SLOT(updateStatisticsHub(const QString&,int))); + if (!g_debug_mode) + connect(pHIKCaptureThread[Num], SIGNAL(updateStatistics(const QString&,int)), this, SLOT(updateStatisticsHub(const QString&,int))); pThread[Num]->start(); if (pThread[Num]->isRunning()) { @@ -3222,6 +3268,7 @@ void Cigarette::EnumerateCameras(SingleCamInfoStruct *TempSingleCamInfoStruct,bo filtered = BaslerCamera::Enumerate(); Pylon::CInstantCameraArray cameras(filtered); Pylon::CTlFactory& tlFactory = Pylon::CTlFactory::GetInstance(); + for (int i = 0; i < min(filtered, NumberOfSupportedCameras); i++) { SingleCamInfoStruct CamInfo; @@ -3386,7 +3433,6 @@ void Cigarette::EnableDebugMode() else if(SingleCamInfo[i].CamClass == HIKClassID) { int nRet = MV_OK; - MV_CC_SetFrameRate(HIKCamHandle[i], 10.0); nRet = MV_CC_SetBoolValue(HIKCamHandle[i], "AcquisitionFrameRateEnable",true); if (nRet) { std::cout << "can not set Hik's AcquisitionFrameRateEnable" << std::endl;} @@ -3417,6 +3463,7 @@ void Cigarette::EnableDebugMode() } g_debug_mode = true; } + void Cigarette::DisableDebugMode() { for(int i=0;i - 80 + 70 20 - 50 + 71 20 @@ -1911,7 +1911,7 @@ 80 20 - 50 + 61 20 @@ -2297,9 +2297,9 @@ - 80 + 70 20 - 50 + 71 20 @@ -2578,9 +2578,9 @@ - 80 + 70 20 - 50 + 71 20 @@ -3194,7 +3194,7 @@ 80 20 - 50 + 61 20 @@ -3414,7 +3414,7 @@ 80 20 - 50 + 61 20 @@ -3586,7 +3586,7 @@ 80 20 - 50 + 61 20 @@ -3854,7 +3854,7 @@ 80 20 - 50 + 61 20 diff --git a/Cigarette/common.h b/Cigarette/common.h index c5cf2e3..9f3ce22 100644 --- a/Cigarette/common.h +++ b/Cigarette/common.h @@ -7,20 +7,21 @@ #include "QtCore\qdatetime.h" //#define __DEBUG //debug信息输出功能 -//#define __UDPSend //网络发送功能 +#define __UDPSend //网络发送功能 #define USB_BASLER_NEW_FW //使用basler定制固件 -//#define IMM_PROCESS //拍照后立马处理,不等校验信号 -//#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号 +#define IMM_PROCESS //拍照后立马处理,不等校验信号 +#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号 //#define ONE_TIME_SHIFT //错开一拍发送反馈(默认错开两次) #define AI_WARM_UP //AI识别开始前的热身动作 -//#define LICENSE_VERIFY //开启license文件校验 +#define LICENSE_VERIFY //开启license文件校验 //CAP_FEED_BACK和DOUBLE_FEED_BACK不要一起开 #if defined (ONE_TIME_SHIFT) //#define CAP_FEED_BACK //拍照时也检测有没有测试结果,有的话就反馈 //#define DOUBLE_FEED_BACK //一次ng,两次反馈ng信号 #endif //#define identify_Hik_YSXID//识别海康相机YSXID -#define __ExportData // 输出检测数据到XML文档 +//#define __ExportData // 输出检测数据到XML文档 +#define DRAW_RECT // 鼠标画框功能 #define Queue_Size 15 #define Unit_Queue_Size Queue_Size*3 @@ -74,9 +75,9 @@ public: QTime shiftB; //B换班时间 QTime shiftC; //C换班时间 QString location; // 所在地 - QString path_model; // 模型路径 + QString model_path; // 模型文件夹路径 QString model_name; // 模型名 - QString path_jpg; // 图片路径 + QString jpg_path; // 图片路径 int timing_shift; //是否定时换班,0否,1是 int expo[NumberOfSupportedCameras]; //相机曝光时间,单位微秒 int gain[NumberOfSupportedCameras]; //相机模拟增益,范围0~64 @@ -107,9 +108,9 @@ public: shift_byhand = 1; //是否手动换班,0否,1是 timing_shift = 0; //是否定时换班,0否,1是 location = ""; - path_model = ""; + model_path = ""; model_name = ""; - path_jpg = ""; + jpg_path = ""; shiftA.setHMS(0, 0, 0); shiftB.setHMS(0, 0, 0); shiftC.setHMS(0, 0, 0); @@ -181,16 +182,16 @@ public: kick4=0; //4#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>4) - kick5=0; //1#通道剔除个数地址 + kick5=0; //5#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>5) - kick6=0; //2#通道剔除个数地址 + kick6=0; //6#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>6) - kick7=0; //3#通道剔除个数地址 + kick7=0; //7#通道剔除个数地址 #endif #if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras>7) - kick8=0; //4#通道剔除个数地址 + kick8=0; //8#通道剔除个数地址 #endif quantity=0; //当班产量地址 shift=0; //换班地址 @@ -203,7 +204,7 @@ public: }; #define DisplayLabel_Type_Bit 0x01 //1:打开范围识别功能,0:关闭范围识别功能 -#define DisplayLabel_Conf_Bit 0x02 //1:可以绘制矩形框,0:不饿能绘制矩形框 +#define DisplayLabel_Conf_Bit 0x02 //1:可以绘制矩形框,0:不能绘制矩形框 class RectRatio { public: diff --git a/Cigarette/debugthread.h b/Cigarette/debugthread.h index 6a0efcb..ea9bd12 100644 --- a/Cigarette/debugthread.h +++ b/Cigarette/debugthread.h @@ -12,7 +12,7 @@ extern SyncQueue *g_debug_queue[NumberOfSupportedCameras]; //鐩告満璋 extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras]; extern int rotationAngle[NumberOfSupportedCameras]; //鍥剧墖鏃嬭浆瑙掑害 -extern bool isNeddRotate[NumberOfSupportedCameras]; +extern bool isNeedRotate[NumberOfSupportedCameras]; class DebugThread : public QThread { Q_OBJECT @@ -53,7 +53,7 @@ protected: if (image.data) { cv::cvtColor(image, image, CV_BGR2RGB); //鐏板害鍥惧儚杞负褰╄壊鍥惧儚 - if (isNeddRotate[local_camera_number]) { + if (isNeedRotate[local_camera_number]) { if(rotationAngle[local_camera_number] != (cv::ROTATE_90_COUNTERCLOCKWISE + 1)) { cv::rotate(image, image, rotationAngle[local_camera_number]); @@ -61,6 +61,7 @@ protected: } emit notify(local_camera_number,0,image); } +#ifdef DRAW_RECT std::lock_guard locker2(g_display_label_conf[local_camera_number].lock); local_DisplayLabelConf.leftButtonDownFlag = g_display_label_conf[local_camera_number].leftButtonDownFlag; local_DisplayLabelConf.Flag[0] = g_display_label_conf[local_camera_number].Flag[0]; @@ -71,6 +72,7 @@ protected: local_DisplayLabelConf.RectVet[1] = g_display_label_conf[local_camera_number].RectVet[1]; DrawSelectRects(image, local_DisplayLabelConf, 0); +#endif } } public: diff --git a/Cigarette/dialogsetup.cpp b/Cigarette/dialogsetup.cpp index bd1eec3..49cd405 100644 --- a/Cigarette/dialogsetup.cpp +++ b/Cigarette/dialogsetup.cpp @@ -55,10 +55,10 @@ DialogSetup::DialogSetup(QWidget * parent) : QDialog(parent) { ui.checkBox_auto_work->setChecked(false); } - if (!g_sys_conf.path_model.isEmpty()) { + if (!g_sys_conf.model_path.isEmpty()) { // 濡傛灉鏇剧粡閫夋嫨杩囨ā鍨嬫枃浠跺す - // 鏌ョ湅dir_path璺緞涓嬫枃浠跺す璇︽儏 - QDir* dirinfo = new QDir(g_sys_conf.path_model); + // 鏌ョ湅model_path璺緞涓嬫枃浠跺す璇︽儏 + QDir* dirinfo = new QDir(g_sys_conf.model_path); if (!dirinfo->exists()) delete dirinfo, dirinfo = nullptr; dirinfo->setNameFilters(QStringList("*.weights")); // 璁剧疆杩囨护鍣 @@ -296,7 +296,7 @@ void DialogSetup::on_toolButton_choose_path_released() { //std::cout << "g_sys_conf.model_name is " << g_sys_conf.model_name.toStdString().c_str() << std::endl; if (dirName.isEmpty()) { - dirName = g_sys_conf.path_model; + dirName = g_sys_conf.model_path; ui.comboBox->setCurrentText(g_sys_conf.model_name); return; } @@ -308,9 +308,9 @@ void DialogSetup::on_toolButton_choose_path_released() { QStringList fileList = dirinfo->entryList(QDir::Files); if (fileList.count() == 0) - g_sys_conf.path_model = "D:/model"; + g_sys_conf.model_path = "D:/model"; else - g_sys_conf.path_model = dirName; + g_sys_conf.model_path = dirName; fileList.removeOne("."); fileList.removeOne(".."); @@ -329,7 +329,7 @@ void DialogSetup::on_toolButton_choose_path_jpg_released() { else { if (ui.comboBox_2->findText(JpgPath) == -1) { ui.comboBox_2->addItem(JpgPath); // 鍦╟omboBox涓樉绀烘枃浠惰矾寰 - g_sys_conf.path_jpg = JpgPath; // 灏嗛夋嫨鐨勮矾寰勫啓鍏onf閰嶇疆鏂囦欢涓 + g_sys_conf.jpg_path = JpgPath; // 灏嗛夋嫨鐨勮矾寰勫啓鍏onf閰嶇疆鏂囦欢涓 } } } @@ -413,13 +413,13 @@ void DialogSetup::write_config() sprintf(buf, "LOCATION=%s\n", g_sys_conf.location.toStdString().c_str()); cfg_file.write(buf, strlen(buf)); memset(buf, 0, 256); - sprintf(buf, "MODELPATH=%s\n", g_sys_conf.path_model.toStdString().c_str()); + sprintf(buf, "MODELPATH=%s\n", g_sys_conf.model_path.toStdString().c_str()); cfg_file.write(buf, strlen(buf)); memset(buf, 0, 256); sprintf(buf, "MODELNAME=%s\n", g_sys_conf.model_name.toStdString().c_str()); cfg_file.write(buf, strlen(buf)); memset(buf, 0, 256); - sprintf(buf, "JPGPATH=%s\n", g_sys_conf.path_jpg.toStdString().c_str()); + sprintf(buf, "JPGPATH=%s\n", g_sys_conf.jpg_path.toStdString().c_str()); cfg_file.write(buf, strlen(buf)); memset(buf, 0, 256); sprintf(buf, "*****************************************\n"); diff --git a/Cigarette/main.cpp b/Cigarette/main.cpp index 05627df..6f928ed 100644 --- a/Cigarette/main.cpp +++ b/Cigarette/main.cpp @@ -21,8 +21,8 @@ int main(int argc, char *argv[]) splash.show(); a.processEvents(); Cigarette w; - //w.show(); - w.showFullScreen(); + w.show(); + //w.showFullScreen(); splash.finish(&w); return a.exec(); } diff --git a/Cigarette/workthread.cpp b/Cigarette/workthread.cpp index 59151e7..3682353 100644 --- a/Cigarette/workthread.cpp +++ b/Cigarette/workthread.cpp @@ -13,13 +13,15 @@ extern SysConf g_sys_conf; //系统 extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras]; extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度 -extern bool isNeddRotate[NumberOfSupportedCameras]; +extern bool isNeedRotate[NumberOfSupportedCameras]; extern SyncQueue >* g_save_queue; //图片保存队列 extern SyncQueue >* g_image_queue[NumberOfSupportedCameras]; //int表示一个目标拍了几张 extern SyncQueue<_UDPSendInfo> *UDP_Info_queue; extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue; extern PLCDevice* m_PLCDevice; +extern bool g_debug_mode; + WorkThread::~WorkThread() { stop(); @@ -59,6 +61,7 @@ void WorkThread::run() local_SysConf.ConfThreshold = g_sys_conf.ConfThreshold;// 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 std::lock_guard locker2(g_display_label_conf[local_camera_number].lock); local_DisplayLabelConf.leftButtonDownFlag = g_display_label_conf[local_camera_number].leftButtonDownFlag; local_DisplayLabelConf.Flag[0] = g_display_label_conf[local_camera_number].Flag[0]; @@ -67,7 +70,10 @@ void WorkThread::run() local_DisplayLabelConf.processPoint = g_display_label_conf[local_camera_number].processPoint; local_DisplayLabelConf.RectVet[0] = g_display_label_conf[local_camera_number].RectVet[0]; local_DisplayLabelConf.RectVet[1] = g_display_label_conf[local_camera_number].RectVet[1]; +#endif } + + QDateTime now_ts = QDateTime::currentDateTime(); std::pair element; local_g_image_queue->take(element); @@ -100,7 +106,7 @@ void WorkThread::run() { cv::Rect temp_Rect(0, h * index, w, h); cv::Mat temp_image = image(temp_Rect).clone(); - if (isNeddRotate[local_camera_number]) { + if (isNeedRotate[local_camera_number]) { if(rotationAngle[local_camera_number] != (cv::ROTATE_90_COUNTERCLOCKWISE + 1)) { cv::rotate(temp_image, temp_image, rotationAngle[local_camera_number]); @@ -163,30 +169,45 @@ void WorkThread::run() if (unit_count >= 2){ image1 = vec_out[(result_index) % 2].clone(); +#ifdef DRAW_RECT IsNG|=CheckSelectRects(image1,vec_results,(result_index) % 2,local_DisplayLabelConf,0); +#endif }else { image1 = vec_out[0].clone(); +#ifdef DRAW_RECT IsNG|=CheckSelectRects(image1,vec_results,0,local_DisplayLabelConf,0); +#endif } +#ifdef DRAW_RECT DrawSelectRects(image1, local_DisplayLabelConf, 0); +#endif if (unit_count >= 3) { image2 = vec_out[2].clone(); +#ifdef DRAW_RECT DrawSelectRects(image2, local_DisplayLabelConf, 1); IsNG|=CheckSelectRects(image1,vec_results,2,local_DisplayLabelConf,1); +#endif } result_index++; exportDataInfo.isNg = IsNG; if (!IsNG) { - emit event_ok(local_camera_number); - local_g_result_queue->put(true); + if (!g_debug_mode) + { + emit event_ok(local_camera_number); + local_g_result_queue->put(true); + } } else { - emit event_ng(local_camera_number); - local_g_result_queue->put(false); + if (!g_debug_mode) + { + emit event_ng(local_camera_number); + local_g_result_queue->put(false); + } + if ((local_SysConf.save == 2) || (local_SysConf.save == 1)) { for(int index=0;index=3) - emit notify(local_camera_number, 1,image2); + emit notify(local_camera_number, 0, image1); + if (unit_count >= 3) + emit notify(local_camera_number, 1, image2); + } + } else - { //保证不错位 - if(local_SysConf.MisMatchAct == 1)//as ng - emit event_ng(local_camera_number); - else if(local_SysConf.MisMatchAct == 0)//as ok - emit event_ok(local_camera_number); - emit display_check_total(local_camera_number, ++frame_total); - qDebug() << local_camera_number<< "#camera# " << now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") <<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << unit_count; + { + //保证不错位 + if (!g_debug_mode) + { + if (local_SysConf.MisMatchAct == 1)//as ng + emit event_ng(local_camera_number); + else if (local_SysConf.MisMatchAct == 0)//as ok + emit event_ok(local_camera_number); + emit display_check_total(local_camera_number, ++frame_total); + qDebug() << local_camera_number << "#camera# " << now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << unit_count; + } } #ifdef __UDPSend UDP_Info_queue->put(UDPSendInfo); diff --git a/conf/conf.txt b/conf/conf.txt index ede4121..f4f7139 100644 --- a/conf/conf.txt +++ b/conf/conf.txt @@ -1,46 +1,47 @@ SAVE=0 MISMATCHACT=1 -SAVE_DAYS=7 +SAVE_DAYS=1 FREESIZE=10 -ComPort=COM1 -CONFTHRESHOLD=1 +ComPort=COM3 +CONFTHRESHOLD=80 AUTO_OPEN=1 AUTO_WORK=1 AUTO_SHIFT=0 TIMING_SHIFT=1 SHIFT_BYHAND=1 -SHIFT_A=10|19 -SHIFT_B=10|21 -SHIFT_C=10|23 +SHIFT_A=13|43 +SHIFT_B=13|44 +SHIFT_C=13|45 LOCATION=CDTHV1.0.1 -MODELPATH= +MODELPATH=D:/model +MODELNAME=jd.weights JPGPATH= ***************************************** -EXPO1=1000 +EXPO1=2000 GAIN1=0 FILTER1=500 -USERID1=1 -NO1=1|1|1 -SHOOT1=3 +USERID1=5 +NO1=0|0|0 +SHOOT1=1 ***************************************** -EXPO2=500 +EXPO2=2000 GAIN2=0 FILTER2=500 -USERID2=4 +USERID2=255 NO2=0|0|0 SHOOT2=3 ***************************************** -EXPO3=500 +EXPO3=2000 GAIN3=0 FILTER3=500 USERID3=255 NO3=0|0|0 SHOOT3=3 ***************************************** -EXPO4=500 +EXPO4=2000 GAIN4=0 FILTER4=500 -USERID4=2 +USERID4=255 NO4=0|0|0 SHOOT4=3 *****************************************