修改部分同步线程的内容,添加合成图片

main
seiyu 10 months ago
parent 2506ac806e
commit e376b84212

@ -14,12 +14,12 @@
#include "apps/Common/exampleHelper.h" #include "apps/Common/exampleHelper.h"
#include <apps/Common/qtIncludePrologue.h> #include <apps/Common/qtIncludePrologue.h>
#include <apps/Common/qtIncludeEpilogue.h> #include <apps/Common/qtIncludeEpilogue.h>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "common.h" #include "common.h"
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras]; extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
extern int work_camera_nums;
class CaptureThread_Func class CaptureThread_Func
{ {
@ -229,7 +229,7 @@ public:
std::lock_guard<std::mutex> locker(p_image_sync_arr_->lock); std::lock_guard<std::mutex> locker(p_image_sync_arr_->lock);
p_image_sync_arr_->image_sync_arr.at(pCaptureThread->Local_Num) = std::make_pair(unit_count, long_image); p_image_sync_arr_->image_sync_arr.at(pCaptureThread->Local_Num) = std::make_pair(unit_count, long_image);
p_image_sync_arr_->collect_cnt++; p_image_sync_arr_->collect_cnt++;
if (p_image_sync_arr_->collect_cnt == NumberOfSupportedCameras) if (p_image_sync_arr_->collect_cnt == work_camera_nums)
{ {
p_image_sync_queue_->put(p_image_sync_arr_->image_sync_arr); p_image_sync_queue_->put(p_image_sync_arr_->image_sync_arr);
p_image_sync_arr_->collect_cnt = 0; p_image_sync_arr_->collect_cnt = 0;

@ -13,6 +13,7 @@
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
extern bool g_debug_mode; extern bool g_debug_mode;
extern int work_camera_nums;
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras]; extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
enum MyEvents enum MyEvents
{ {
@ -287,7 +288,7 @@ public:
std::lock_guard<std::mutex> locker(p_image_sync_arr_->lock); std::lock_guard<std::mutex> locker(p_image_sync_arr_->lock);
p_image_sync_arr_->image_sync_arr.at(pCaptureThreadBasler->Local_Num) = std::make_pair(unit_count, long_image); p_image_sync_arr_->image_sync_arr.at(pCaptureThreadBasler->Local_Num) = std::make_pair(unit_count, long_image);
p_image_sync_arr_->collect_cnt++; p_image_sync_arr_->collect_cnt++;
if (p_image_sync_arr_->collect_cnt == NumberOfSupportedCameras) if (p_image_sync_arr_->collect_cnt == work_camera_nums)
{ {
p_image_sync_queue_->put(p_image_sync_arr_->image_sync_arr); p_image_sync_queue_->put(p_image_sync_arr_->image_sync_arr);
p_image_sync_arr_->collect_cnt = 0; p_image_sync_arr_->collect_cnt = 0;

@ -8,6 +8,7 @@ extern bool g_debug_mode; //
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras]; extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue; extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
extern PLCDevice* m_PLCDevice; extern PLCDevice* m_PLCDevice;
extern int work_camera_nums;
inline void LossCallBackfunction(unsigned int pData, void* pUser){ inline void LossCallBackfunction(unsigned int pData, void* pUser){
try{ try{
@ -43,7 +44,7 @@ inline void FallingGpioEventfunction(MV_EVENT_OUT_INFO* pEventInfo, void* pUser)
std::lock_guard<std::mutex> locker(CaptureThreadHIKptr->p_image_sync_arr->lock); std::lock_guard<std::mutex> locker(CaptureThreadHIKptr->p_image_sync_arr->lock);
CaptureThreadHIKptr->p_image_sync_arr->image_sync_arr.at(CaptureThreadHIKptr->Local_Num) = std::make_pair(unit_count, long_image); CaptureThreadHIKptr->p_image_sync_arr->image_sync_arr.at(CaptureThreadHIKptr->Local_Num) = std::make_pair(unit_count, long_image);
CaptureThreadHIKptr->p_image_sync_arr->collect_cnt++; CaptureThreadHIKptr->p_image_sync_arr->collect_cnt++;
if (CaptureThreadHIKptr->p_image_sync_arr->collect_cnt == NumberOfSupportedCameras) if (CaptureThreadHIKptr->p_image_sync_arr->collect_cnt == work_camera_nums)
{ {
CaptureThreadHIKptr->p_image_sync_queue->put(CaptureThreadHIKptr->p_image_sync_arr->image_sync_arr); CaptureThreadHIKptr->p_image_sync_queue->put(CaptureThreadHIKptr->p_image_sync_arr->image_sync_arr);
CaptureThreadHIKptr->p_image_sync_arr->collect_cnt = 0; CaptureThreadHIKptr->p_image_sync_arr->collect_cnt = 0;

@ -133,7 +133,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp14</LanguageStandard> <LanguageStandard>stdcpp14</LanguageStandard>
<Optimization>MaxSpeed</Optimization> <Optimization>Disabled</Optimization>
<SupportJustMyCode>false</SupportJustMyCode> <SupportJustMyCode>false</SupportJustMyCode>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile> </ClCompile>
@ -141,7 +141,7 @@
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile> <OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;Ws2_32.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;Ws2_32.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries> <IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries> </IgnoreSpecificDefaultLibraries>
@ -249,6 +249,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_SyncWorkThread.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\qrc_cigarette.cpp"> <ClCompile Include="GeneratedFiles\qrc_cigarette.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader> </PrecompiledHeader>
@ -339,6 +343,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_SyncWorkThread.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="hikcamera.cpp" /> <ClCompile Include="hikcamera.cpp" />
<ClCompile Include="Logthread.cpp" /> <ClCompile Include="Logthread.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
@ -347,7 +355,7 @@
<ClCompile Include="PLC\PLCDevice.cpp" /> <ClCompile Include="PLC\PLCDevice.cpp" />
<ClCompile Include="plc_item.cpp" /> <ClCompile Include="plc_item.cpp" />
<ClCompile Include="SyncQueue.cpp" /> <ClCompile Include="SyncQueue.cpp" />
<ClCompile Include="syncworkthread.cpp" /> <ClCompile Include="SyncWorkThread.cpp" />
<ClCompile Include="threadReceive.cpp" /> <ClCompile Include="threadReceive.cpp" />
<ClCompile Include="threadSend.cpp" /> <ClCompile Include="threadSend.cpp" />
<ClCompile Include="threadSendTCP.cpp" /> <ClCompile Include="threadSendTCP.cpp" />
@ -396,6 +404,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="FtpManager.h" /> <ClInclude Include="FtpManager.h" />
<CustomBuild Include="SyncWorkThread.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DNOMINMAX -DQT_NETWORK_LIB -D%(PreprocessorDefinitions) "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(ProjectDir)MvIMPACT" "-I$(ProjectDir)OpenCV455Simple\include" "-I$(ProjectDir)Common" "-I$(ProjectDir)Pylon6.2\include" "-I$(ProjectDir)modbus" "-I$(ProjectDir)MVS3.2.1\Include" "-I$(ProjectDir)PLC" "-I$(QTDIR)\include\QtNetwork"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
</CustomBuild>
<ClInclude Include="threadSendTCP.h" /> <ClInclude Include="threadSendTCP.h" />
<ClInclude Include="tinyxml2.h" /> <ClInclude Include="tinyxml2.h" />
<CustomBuild Include="threadReceive.h"> <CustomBuild Include="threadReceive.h">

@ -260,7 +260,13 @@
<ClCompile Include="threadSendTCP.cpp"> <ClCompile Include="threadSendTCP.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="syncworkthread.cpp"> <ClCompile Include="SyncWorkThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_SyncWorkThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_SyncWorkThread.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
@ -358,7 +364,7 @@
<CustomBuild Include="exportData.h"> <CustomBuild Include="exportData.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</CustomBuild> </CustomBuild>
<CustomBuild Include="syncworkthread.h"> <CustomBuild Include="SyncWorkThread.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</CustomBuild> </CustomBuild>
</ItemGroup> </ItemGroup>

Binary file not shown.

@ -12,12 +12,12 @@
#define BaslerClassID 0x02 #define BaslerClassID 0x02
#define c_maxCamerasToUse (size_t)2 #define c_maxCamerasToUse (size_t)2
//5:灰色 //5:╩ри╚
//6:黑色 //6:╨зи╚
//1:红色 //1:╨Ли╚
//2:黄色 //2:╩фи╚
//3:白色 //3:╟ви╚
//4:绿色 //4:бли╚
class BaslerCamera: public BaseCamera class BaslerCamera: public BaseCamera
{ {

@ -34,6 +34,7 @@ AlgJd alg_test;//test AI
#endif #endif
QThread* pThread[NumberOfSupportedCameras]; QThread* pThread[NumberOfSupportedCameras];
int work_camera_nums;
//巴鲁夫相机相关 //巴鲁夫相机相关
CaptureThread* pCaptureThread[NumberOfSupportedCameras]; CaptureThread* pCaptureThread[NumberOfSupportedCameras];
FunctionInterface* pFI[NumberOfSupportedCameras]; FunctionInterface* pFI[NumberOfSupportedCameras];
@ -74,15 +75,10 @@ ExportDataThread exportDataThread;
#endif #endif
bool g_admin_mode; //是否管理员模式 bool g_admin_mode; //是否管理员模式
QString g_admin_pswd; //管理员密码 QString g_admin_pswd; //管理员密码
bool g_op_mode; //是否操作员模式 bool g_op_mode; //是否操作员模式
QString g_op_pswd; //操作员密码 QString g_op_pswd; //操作员密码
bool g_working; //true 开始工作状态; false 停止工作状态 bool g_working; //true 开始工作状态; false 停止工作状态
int last_shift; //记录上一次班 int last_shift; //记录上一次班
QStringList g_alarm_msg; QStringList g_alarm_msg;
@ -160,6 +156,7 @@ Cigarette::Cigarette(QWidget *parent)
export_XMLData_Info_queue->name = "Export Data Info queue"; export_XMLData_Info_queue->name = "Export Data Info queue";
#endif #endif
last_shift = 256; last_shift = 256;
work_camera_nums = 0;
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
g_image_sync_queue = new SyncQueue<std::vector<std::pair<int, cv::Mat>>>(Queue_Size); g_image_sync_queue = new SyncQueue<std::vector<std::pair<int, cv::Mat>>>(Queue_Size);
@ -191,18 +188,16 @@ Cigarette::Cigarette(QWidget *parent)
printf("\nFail to write message to file.");; printf("\nFail to write message to file.");;
} }
} }
g_debug_mode = false;
g_admin_mode = false; g_admin_mode = false;
g_admin_time = ADMIN_TIME; g_admin_time = ADMIN_TIME;
g_admin_pswd = read_pswd(); g_admin_pswd = read_pswd();
g_op_mode = false; g_op_mode = false;
g_op_time = OP_TIME; g_op_time = OP_TIME;
g_op_pswd = read_op_pswd(); g_op_pswd = read_op_pswd();
g_working = false; g_working = false;
g_debug_mode = false;
g_alarm_msg << QStringLiteral("无报警") /// 0 g_alarm_msg << QStringLiteral("无报警") /// 0
<< QStringLiteral("1#相机丢结果") /// 1 << QStringLiteral("1#相机丢结果") /// 1
@ -334,6 +329,7 @@ Cigarette::Cigarette(QWidget *parent)
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
{ {
if(SingleCamInfo[i].Detect){ if(SingleCamInfo[i].Detect){
work_camera_nums++;
cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);")); cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
QString model_path, model_name; QString model_path, model_name;
if (g_sys_conf.model_path.isEmpty()) { if (g_sys_conf.model_path.isEmpty()) {
@ -1305,6 +1301,7 @@ void Cigarette::OnDisplayCheckNumberHub(int Num, long no)
{ {
production_number[Num]++; production_number[Num]++;
lcdNumber_total_mat[Num]->display(production_number[Num]); lcdNumber_total_mat[Num]->display(production_number[Num]);
//lcdNumber_total_mat[Num]->display(no);
#ifdef __UDPSend #ifdef __UDPSend
_UDPSendInfo UDPSendInfo; _UDPSendInfo UDPSendInfo;
UDPSendInfo.FrameID = total_frame; UDPSendInfo.FrameID = total_frame;
@ -2823,6 +2820,7 @@ void Cigarette::CreatWorkThread(int classid,int Num,Cigarette* classptr)
connect(&work_thread[Num], SIGNAL(event_ok(int)), classptr, SLOT(OnOKHub(int))); connect(&work_thread[Num], SIGNAL(event_ok(int)), classptr, SLOT(OnOKHub(int)));
connect(&work_thread[Num], SIGNAL(event_ng(int)), classptr, SLOT(OnNGHub(int))); connect(&work_thread[Num], SIGNAL(event_ng(int)), classptr, SLOT(OnNGHub(int)));
work_thread[Num].start_work(); work_thread[Num].start_work();
debug_thread[Num].init(g_debug_queue[Num],Num); debug_thread[Num].init(g_debug_queue[Num],Num);
connect(&debug_thread[Num], SIGNAL(notify(int,int,cv::Mat)), classptr, SLOT(OnNotifyHub(int,int,cv::Mat))); connect(&debug_thread[Num], SIGNAL(notify(int,int,cv::Mat)), classptr, SLOT(OnNotifyHub(int,int,cv::Mat)));
debug_thread[Num].start_work(); debug_thread[Num].start_work();
@ -3069,10 +3067,10 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose)
pBaslerCaptureThread[Num] = new CaptureThreadBasler(baslerCamera, false, Num,g_sys_conf.shoot[Num]); pBaslerCaptureThread[Num] = new CaptureThreadBasler(baslerCamera, false, Num,g_sys_conf.shoot[Num]);
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
pCaptureThread[Num]->p_image_sync_queue = g_image_sync_queue; pBaslerCaptureThread[Num]->p_image_sync_queue = g_image_sync_queue;
pCaptureThread[Num]->p_image_sync_arr = &g_image_sync_arr; pBaslerCaptureThread[Num]->p_image_sync_arr = &g_image_sync_arr;
#else #else
pCaptureThread[Num]->p_image_queue = g_image_queue[Num]; pBaslerCaptureThread[Num]->p_image_queue = g_image_queue[Num];
#endif #endif
pBaslerCaptureThread[Num]->p_result_queue = g_result_queue[Num]; pBaslerCaptureThread[Num]->p_result_queue = g_result_queue[Num];
pBaslerCaptureThread[Num]->p_result_wait_queue = g_result_wait_queue[Num]; pBaslerCaptureThread[Num]->p_result_wait_queue = g_result_wait_queue[Num];
@ -3199,10 +3197,10 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose)
pHIKCaptureThread[Num] = new CaptureThreadHIK(camhandle, false,Num); pHIKCaptureThread[Num] = new CaptureThreadHIK(camhandle, false,Num);
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
pCaptureThread[Num]->p_image_sync_queue = g_image_sync_queue; pHIKCaptureThread[Num]->p_image_sync_queue = g_image_sync_queue;
pCaptureThread[Num]->p_image_sync_arr = &g_image_sync_arr; pHIKCaptureThread[Num]->p_image_sync_arr = &g_image_sync_arr;
#else #else
pCaptureThread[Num]->p_image_queue = g_image_queue[Num]; pHIKCaptureThread[Num]->p_image_queue = g_image_queue[Num];
#endif #endif
pHIKCaptureThread[Num]->p_result_queue = g_result_queue[Num]; pHIKCaptureThread[Num]->p_result_queue = g_result_queue[Num];
pHIKCaptureThread[Num]->p_debug_queue = g_debug_queue[Num]; pHIKCaptureThread[Num]->p_debug_queue = g_debug_queue[Num];

@ -11,7 +11,7 @@
#include "baslercamera.h" #include "baslercamera.h"
#include "hikcamera.h" #include "hikcamera.h"
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
#include "syncworkthread.h" #include "SyncWorkThread.h"
#else #else
#include "workthread.h" #include "workthread.h"
#endif #endif

@ -1,5 +1,4 @@
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <mutex> #include <mutex>
@ -14,7 +13,7 @@
//#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号 //#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号
#define ONE_TIME_SHIFT //错开一拍发送反馈(默认错开两次) #define ONE_TIME_SHIFT //错开一拍发送反馈(默认错开两次)
#define AI_WARM_UP //AI识别开始前的热身动作 #define AI_WARM_UP //AI识别开始前的热身动作
#define LICENSE_VERIFY //开启license文件校验 //#define LICENSE_VERIFY //开启license文件校验
//CAP_FEED_BACK和DOUBLE_FEED_BACK不要一起开 //CAP_FEED_BACK和DOUBLE_FEED_BACK不要一起开
#if defined (ONE_TIME_SHIFT) #if defined (ONE_TIME_SHIFT)
//#define CAP_FEED_BACK //拍照时也检测有没有测试结果,有的话就反馈 //#define CAP_FEED_BACK //拍照时也检测有没有测试结果,有的话就反馈
@ -23,8 +22,7 @@
//#define identify_Hik_YSXID//识别海康相机YSXID //#define identify_Hik_YSXID//识别海康相机YSXID
//#define __ExportData // 输出检测数据到XML文档 //#define __ExportData // 输出检测数据到XML文档
#define DRAW_RECT // 鼠标画框功能 #define DRAW_RECT // 鼠标画框功能
//#define SYNC_CAMERA //相机同步处理图片 #define SYNC_CAMERA //相机同步处理图片
#define Queue_Size 15 #define Queue_Size 15
#define Unit_Queue_Size Queue_Size*3 #define Unit_Queue_Size Queue_Size*3
@ -37,7 +35,7 @@
#endif #endif
// 主界面基本参数配置文件 // 主界面基本参数配置文件
#define CONFPATH "D:/Release/conf_path.txt" #define CONFPATH "D:/conf/conf_path.txt"
//#define CONFIGURE_FILE "D:/conf/conf.txt" //#define CONFIGURE_FILE "D:/conf/conf.txt"
// 相机旋转角度配置文件 // 相机旋转角度配置文件
#define ROTATE_FILE "rotate.txt" #define ROTATE_FILE "rotate.txt"
@ -46,13 +44,10 @@
#define SELECT_RECTS_FILE "SelectRects%d%d.txt" #define SELECT_RECTS_FILE "SelectRects%d%d.txt"
#define STATISTIC_FILE "camera%1_statistic.txt" #define STATISTIC_FILE "camera%1_statistic.txt"
#define ALARM_RECORD_FILE "alarm.txt" #define ALARM_RECORD_FILE "alarm.txt"
#define OUTPUT_HIGH_WIDTH 20000 //输出信号的脉冲宽度,微秒 #define OUTPUT_HIGH_WIDTH 20000 //输出信号的脉冲宽度,微秒
#define OP_TIME 300 //OP权限时长默认300秒 #define OP_TIME 300 //OP权限时长默认300秒
#define ADMIN_TIME 600 //ADMIN权限时长默认300秒 #define ADMIN_TIME 600 //ADMIN权限时长默认300秒
#define STOP_SECONDS 3 //检查多少次不变触发自动换班 #define STOP_SECONDS 3 //检查多少次不变触发自动换班
int string_split(std::string str, std::string pattern,std::vector<std::string> &out); int string_split(std::string str, std::string pattern,std::vector<std::string> &out);

@ -1,4 +1,4 @@
#include "workthread.h" #include "SyncWorkThread.h"
#include "alg_jd.h" #include "alg_jd.h"
#include "common.h" #include "common.h"
#include "balluffcamera.h" #include "balluffcamera.h"
@ -15,6 +15,7 @@ extern DisplayLabelConf g_display_label_conf[NumberOfSupportedCameras];
extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度 extern int rotationAngle[NumberOfSupportedCameras]; //图片旋转角度
extern bool isNeedRotate[NumberOfSupportedCameras]; extern bool isNeedRotate[NumberOfSupportedCameras];
extern int work_camera_nums;
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表示一个目标拍了几张
@ -42,10 +43,13 @@ SyncWorkThread::~SyncWorkThread()
void SyncWorkThread::init(SyncQueue<std::vector<std::pair<int, cv::Mat>>>* image_ptr, ASyncQueue<bool>* result_ptr) void SyncWorkThread::init(SyncQueue<std::vector<std::pair<int, cv::Mat>>>* image_ptr, ASyncQueue<bool>* result_ptr)
{ {
local_g_image_sync_queue = image_ptr; local_g_image_sync_queue = image_ptr;
local_g_result_queue = result_ptr; local_g_result_queue = result_ptr;
b_quit = false; b_quit = false;
frame_total = 0; for (int i = 0; i < NumberOfSupportedCameras; i++) {
frame_total[i] = 0;
}
} }
void SyncWorkThread::start_work() void SyncWorkThread::start_work()
{ {
start(HighestPriority); start(HighestPriority);
@ -57,271 +61,283 @@ void SyncWorkThread::stop()
void SyncWorkThread::run() void SyncWorkThread::run()
{ {
try{ try {
uint32_t result_index[NumberOfSupportedCameras] = {0}; uint32_t result_index[NumberOfSupportedCameras] = { 0 };
while (!b_quit) { while (!b_quit) {
QDateTime now_ts = QDateTime::currentDateTime(); QDateTime now_ts = QDateTime::currentDateTime();
std::vector<std::pair<int, cv::Mat>> element_vec; std::vector<std::pair<int, cv::Mat>> element_vec;
local_g_image_sync_queue->take(element_vec); local_g_image_sync_queue->take(element_vec);
bool IsNGForAll = false;
bool IsNGForAll = false; int merge_index;
for(int i=0;i<element_vec.size();i++)//每个相机的图轮流遍历 cv::Mat merge_image = cv::Mat::zeros(512 * work_camera_nums, 640 * g_sys_conf.shoot[0], CV_8UC3);
{ for (int i = 0; i < element_vec.size(); i++)//每个相机的图轮流遍历
local_camera_number = i; {
std::pair<int, cv::Mat> element; local_camera_number = i;
int unit_count = element.first; std::pair<int, cv::Mat> element;
cv::Mat image = element.second; element = element_vec[i];
int unit_count = element.first;
{//不要删掉这个括号,用来定义锁的作用域 cv::Mat image = element.second;
std::lock_guard<std::mutex> locker(g_sys_conf.lock); {//不要删掉这个括号,用来定义锁的作用域
local_SysConf.save = g_sys_conf.save; std::lock_guard<std::mutex> locker(g_sys_conf.lock);
local_SysConf.shoot[local_camera_number] = g_sys_conf.shoot[local_camera_number]; local_SysConf.save = g_sys_conf.save;
local_SysConf.MisMatchAct = g_sys_conf.MisMatchAct; local_SysConf.shoot[local_camera_number] = g_sys_conf.shoot[local_camera_number];
local_SysConf.ConfThreshold = g_sys_conf.ConfThreshold;// local_SysConf.MisMatchAct = g_sys_conf.MisMatchAct;
for (int i = 0; i < 3; i++)local_SysConf.no[local_camera_number][i] = g_sys_conf.no[local_camera_number][i]; 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 #ifdef DRAW_RECT
std::lock_guard<std::mutex> locker2(g_display_label_conf[local_camera_number].lock); std::lock_guard<std::mutex> locker2(g_display_label_conf[local_camera_number].lock);
local_DisplayLabelConf.leftButtonDownFlag = g_display_label_conf[local_camera_number].leftButtonDownFlag; local_DisplayLabelConf.leftButtonDownFlag = g_display_label_conf[local_camera_number].leftButtonDownFlag;
local_DisplayLabelConf.Flag[0] = g_display_label_conf[local_camera_number].Flag[0]; local_DisplayLabelConf.Flag[0] = g_display_label_conf[local_camera_number].Flag[0];
local_DisplayLabelConf.Flag[1] = g_display_label_conf[local_camera_number].Flag[1]; local_DisplayLabelConf.Flag[1] = g_display_label_conf[local_camera_number].Flag[1];
local_DisplayLabelConf.originalPoint = g_display_label_conf[local_camera_number].originalPoint; local_DisplayLabelConf.originalPoint = g_display_label_conf[local_camera_number].originalPoint;
local_DisplayLabelConf.processPoint = g_display_label_conf[local_camera_number].processPoint; 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[0] = g_display_label_conf[local_camera_number].RectVet[0];
local_DisplayLabelConf.RectVet[1] = g_display_label_conf[local_camera_number].RectVet[1]; local_DisplayLabelConf.RectVet[1] = g_display_label_conf[local_camera_number].RectVet[1];
#endif #endif
} }
#ifdef __UDPSend #ifdef __UDPSend
_UDPSendInfo UDPSendInfo; _UDPSendInfo UDPSendInfo;
UDPSendInfo.FrameID = info_frame; UDPSendInfo.FrameID = info_frame;
UDPSendInfo.index = local_camera_number; UDPSendInfo.index = local_camera_number;
#endif #endif
#ifdef __TCPSend #ifdef __TCPSend
_TCPSendInfo TCPSendInfo; _TCPSendInfo TCPSendInfo;
#endif #endif
if (!image.data) if (!image.data)
{ {
continue; //图像为空,跳过 continue; //图像为空,跳过
}
if (image.channels() == 1)
{
cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像
}
if (local_SysConf.shoot[local_camera_number] == unit_count)
{
std::vector<cv::Mat> vec_in;
int w = image.cols;
int h = image.rows / unit_count;
for (int index = 0; index < unit_count; index++) {
cv::Rect temp_Rect(0, h * index, w, h);
cv::Mat temp_image = image(temp_Rect).clone();
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]);
}
}
vec_in.push_back(temp_image.clone());
} }
if (image.channels() == 1)
std::vector<cv::Mat> vec_out; {
std::vector<std::vector<std::pair<int, cv::Rect> > > vec_results; cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像
QDateTime ts_start = QDateTime::currentDateTime();
if(unit_count == 1){
std::vector<std::pair<int, cv::Rect> > results;
cv::Mat imagein,imageout;
imagein = vec_in[0];
alg_jd[local_camera_number].detect(imagein, imageout, results);
vec_out.push_back(imageout.clone());
vec_results.push_back(results);
}else{
alg_jd[local_camera_number].detect_batch(vec_in, vec_out, vec_results);
} }
QDateTime ts_jd = QDateTime::currentDateTime(); if (local_SysConf.shoot[local_camera_number] == unit_count)
int time_process = ts_start.msecsTo(ts_jd); {
emit display_timecost(local_camera_number, time_process); cv::Rect roi;
#ifdef __UDPSend std::vector<cv::Mat> vec_in;
UDPSendInfo.timecost = QString::number(time_process); int w = image.cols;
int h = image.rows / unit_count;
for (int index = 0; index < unit_count; index++) {
cv::Rect temp_Rect(0, h * index, w, h);
cv::Mat temp_image = image(temp_Rect).clone();
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]);
}
}
vec_in.push_back(temp_image.clone());
}
std::vector<cv::Mat> vec_out;
std::vector<std::vector<std::pair<int, cv::Rect>>> vec_results;
QDateTime ts_start = QDateTime::currentDateTime();
if (unit_count == 1) {
std::vector<std::pair<int, cv::Rect> > results;
cv::Mat imagein, imageout;
imagein = vec_in[0];
alg_jd[local_camera_number].detect(imagein, imageout, results);
vec_out.push_back(imageout.clone());
vec_results.push_back(results);
}
else {
alg_jd[local_camera_number].detect_batch(vec_in, vec_out, vec_results);
}
QDateTime ts_jd = QDateTime::currentDateTime();
int time_process = ts_start.msecsTo(ts_jd);
#ifdef SYNC_CAMERA
emit display_timecost(local_camera_number, time_process);
#endif #endif
cv::Mat image1;
cv::Mat image2;
QString jd_no;
for (int index = 0; index < unit_count; index++) {
jd_no += QString::number(vec_results[index].size()) + ",";
}
jd_no.chop(1);
emit display_jd_no(local_camera_number, jd_no);
#ifdef __UDPSend #ifdef __UDPSend
UDPSendInfo.JD = jd_no; UDPSendInfo.timecost = QString::number(time_process);
#endif #endif
bool IsNG = false; cv::Mat image1;
int ngReason = 0; cv::Mat image2;
QMap<int, QString> ng_reason_maps;
ng_reason_maps[0] = "unknow"; QString jd_no;
ng_reason_maps[1] = "less_than_setting"; for (int index = 0; index < unit_count; index++) {
ng_reason_maps[2] = "too_diff_from_model"; jd_no += QString::number(vec_results[index].size()) + ",";
ng_reason_maps[3] = "out_of_setting_range";
for(int index=0;index<unit_count;index++)
{
if(vec_results[index].size() < local_SysConf.no[local_camera_number][index])
{
IsNG |= true;
ngReason = 1;
}
//if (vec_results[index].size() != 1)IsNG |= true;//反向训练
if (local_SysConf.ConfThreshold == 0)
{
IsNG = false;
ngReason = 0;
} }
if (local_SysConf.save == 2)//三张照片分别存储 jd_no.chop(1);
{ #ifdef SYNC_CAMERA
cv::Mat m = vec_in[index].clone(); emit display_jd_no(local_camera_number, jd_no);
QString file_name = g_conf_path.save_pics_path + "/ALL/" + #endif
now_ts.toString("yyyy-MM-dd") + "/" #ifdef __UDPSend
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" + UDPSendInfo.JD = jd_no;
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) + #endif
"#" + "_" + QString::number(index + 1) + ".jpg"; bool IsNG = false;
std::string filename = file_name.toLocal8Bit().constData(); int ngReason = 0;
g_save_queue->put(std::make_pair(filename, m)); QMap<int, QString> ng_reason_maps;
ng_reason_maps[0] = "unknow";
ng_reason_maps[1] = "less_than_setting";
ng_reason_maps[2] = "too_diff_from_model";
ng_reason_maps[3] = "out_of_setting_range";
for (int index = 0; index < unit_count; index++){
if (vec_results[index].size() < local_SysConf.no[local_camera_number][index])
{
IsNG |= true;
ngReason = 1;
}
//if (vec_results[index].size() != 1)IsNG |= true;//反向训练
if (local_SysConf.ConfThreshold == 0)
{
IsNG = false;
ngReason = 0;
}
if (local_SysConf.save == 2)//三张照片分别存储
{
/// 合成element_vec.size() * unit_count 宫格图像
cv::Mat m = vec_in[index].clone();
QString file_name;
merge_index = i * unit_count + index + 1;
roi = cv::Rect(index * m.cols, i * m.rows, m.cols, m.rows);
m.copyTo(merge_image(roi));
if (merge_index == work_camera_nums * unit_count) {
file_name = g_conf_path.save_pics_path + "/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + ".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), merge_image));
#ifdef __TCPSend #ifdef __TCPSend
TCPSendInfo.pics_name = filename; TCPSendInfo.pics_name = file_name.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo); TCP_Info_queue->put(TCPSendInfo);
#endif #endif
}
}
} }
}
if (unit_count >= 2) {
if (unit_count >= 2){ image1 = vec_out[(result_index[i]) % 2].clone();
image1 = vec_out[(result_index[i]) % 2].clone();
#ifdef DRAW_RECT #ifdef DRAW_RECT
IsNG|=CheckSelectRects(image1,vec_results,(result_index[i]) % 2, local_DisplayLabelConf, 0); IsNG |= CheckSelectRects(image1, vec_results, (result_index[i]) % 2, local_DisplayLabelConf, 0);
if (IsNG) { if (IsNG) {
ngReason = 2; ngReason = 2;
} }
#endif #endif
}else {
image1 = vec_out[0].clone();
#ifdef DRAW_RECT
IsNG|=CheckSelectRects(image1,vec_results,0,local_DisplayLabelConf,0);
if (IsNG) {
ngReason = 2;
} }
else {
image1 = vec_out[0].clone();
#ifdef DRAW_RECT
IsNG |= CheckSelectRects(image1, vec_results, 0, local_DisplayLabelConf, 0);
if (IsNG) {
ngReason = 2;
}
#endif #endif
} }
#ifdef DRAW_RECT #ifdef DRAW_RECT
DrawSelectRects(image1, local_DisplayLabelConf, 0); DrawSelectRects(image1, local_DisplayLabelConf, 0);
#endif #endif
if (unit_count >= 3) { if (unit_count >= 3) {
image2 = vec_out[2].clone(); image2 = vec_out[2].clone();
#ifdef DRAW_RECT #ifdef DRAW_RECT
DrawSelectRects(image2, local_DisplayLabelConf, 1); DrawSelectRects(image2, local_DisplayLabelConf, 1);
IsNG|=CheckSelectRects(image1,vec_results,2,local_DisplayLabelConf,1); IsNG |= CheckSelectRects(image1, vec_results, 2, local_DisplayLabelConf, 1);
if (IsNG) { if (IsNG) {
ngReason = 3; ngReason = 3;
} }
#endif #endif
}
result_index[i]++;
if (!IsNG)
{
if (!g_debug_mode)
{
emit event_ok(local_camera_number);
local_g_result_queue->put(true);
} }
} result_index[i]++;
else
{ if (!IsNG)
if (!g_debug_mode)
{ {
emit event_ng(local_camera_number); if (!g_debug_mode)
local_g_result_queue->put(false); {
IsNGForAll = TRUE; #ifdef SYNC_CAMERA
emit event_ok(local_camera_number);
#endif
local_g_result_queue->put(true);
}
} }
else
if ((local_SysConf.save == 2) || (local_SysConf.save == 1))
{ {
for(int index=0;index<unit_count;index++) if (!g_debug_mode)
{ {
cv::Mat m = vec_in[index].clone(); #ifdef SYNC_CAMERA
QString file_name = g_conf_path.save_pics_path + "/ng/" + emit event_ng(local_camera_number);
now_ts.toString("yyyy-MM-dd") + "/"
+ 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) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
QString remotePath = "/image/ng/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
#ifdef __TCPSend
TCPSendInfo.pics_name = file_name.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo);
#endif #endif
m = vec_out[index].clone(); local_g_result_queue->put(false);
file_name = g_conf_path.save_pics_path + "/ng_result/" + IsNGForAll = TRUE;
now_ts.toString("yyyy-MM-dd") + "/" }
+ 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) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
remotePath = "/image/ng_result/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
#ifdef __TCPSend if ((local_SysConf.save == 2) || (local_SysConf.save == 1))
TCPSendInfo.pics_name = file_name.toLocal8Bit().constData(); {
TCP_Info_queue->put(TCPSendInfo); for (int index = 0; index < unit_count; index++)
#endif {
cv::Mat m = vec_in[index].clone();
QString file_name = g_conf_path.save_pics_path + "/ng/" +
now_ts.toString("yyyy-MM-dd") + "/"
+ 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) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
QString remotePath = "/image/ng/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
//g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
m = vec_out[index].clone();
file_name = g_conf_path.save_pics_path + "/ng_result/" +
now_ts.toString("yyyy-MM-dd") + "/"
+ 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) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
remotePath = "/image/ng_result/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
//g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
}
} }
} }
#ifdef SYNC_CAMERA
if (!g_debug_mode)
{
emit display_check_total(local_camera_number, ++(frame_total[local_camera_number]));
//exportDataInfo.cameraTotal = frame_total;
emit notify(local_camera_number, 0, image1);
if (unit_count >= 3)
emit notify(local_camera_number, 1, image2);
}
#endif
} }
if (!g_debug_mode) else
{
emit display_check_total(local_camera_number, ++frame_total);
//exportDataInfo.cameraTotal = frame_total;
emit notify(local_camera_number, 0, image1);
if (unit_count >= 3)
emit notify(local_camera_number, 1, image2);
}
}
else
{
//保证不错位
if (!g_debug_mode)
{ {
if (local_SysConf.MisMatchAct == 1)//as ng #ifdef SYNC_CAMERA
emit event_ng(local_camera_number); //保证不错位
else if (local_SysConf.MisMatchAct == 0)//as ok if (!g_debug_mode)
emit event_ok(local_camera_number); {
emit display_check_total(local_camera_number, ++frame_total); if (local_SysConf.MisMatchAct == 1)//as ng
qDebug() << local_camera_number << "#camera# " << now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << unit_count; 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[local_camera_number]));
qDebug() << local_camera_number << "#camera# " << now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << unit_count;
}
#endif
} }
}
#ifdef __UDPSend #ifdef __UDPSend
UDP_Info_queue->put(UDPSendInfo); UDP_Info_queue->put(UDPSendInfo);
#endif #endif
}
if (IsNGForAll)
{
/*to do something*/
}
} }
if(IsNGForAll)
{
/*to do somthing*/
}
}
} }
catch (cv::Exception& e) catch (cv::Exception& e)
{ {
const char* err_msg = e.what(); const char* err_msg = e.what();
std::cout << "exception caught: " << err_msg << std::endl; std::cout << "exception caught: " << err_msg << std::endl;
} }
} }

@ -7,26 +7,29 @@
#include "SyncQueue.h" #include "SyncQueue.h"
#include "ASyncQueue.h" #include "ASyncQueue.h"
#include "common.h" #include "common.h"
class SyncWorkThread :
class SyncWorkThread : public QThread public QThread
{ {
Q_OBJECT Q_OBJECT
#ifdef SYNC_CAMERA
signals: signals:
void notify(int Num,int Cnt,cv::Mat); void notify(int Num, int Cnt, cv::Mat);
void display_timecost(int Num,int ms); void display_timecost(int Num, int ms);
void display_check_total(int Num,long no); void display_check_total(int Num, long no);
void display_jd_no(int Num,QString jd_no); void display_jd_no(int Num, QString jd_no);
void event_ok(int Num); void event_ok(int Num);
void event_ng(int Num); void event_ng(int Num);
#endif
public: public:
SyncWorkThread(QObject *parent = 0): QThread(parent) SyncWorkThread(QObject* parent = 0) : QThread(parent)
{ {
} }
~SyncWorkThread(); ~SyncWorkThread();
void init(SyncQueue<std::vector<std::pair<int, cv::Mat>>>* image_ptr, ASyncQueue<bool>* result_ptr); void init(SyncQueue<std::vector<std::pair<int, cv::Mat>>>* image_ptr, ASyncQueue<bool>* result_ptr);
void start_work(); void start_work();
void stop(); void stop();
@ -37,7 +40,7 @@ public:
SyncQueue<std::vector<std::pair<int, cv::Mat>>>* local_g_image_sync_queue; SyncQueue<std::vector<std::pair<int, cv::Mat>>>* local_g_image_sync_queue;
ASyncQueue<bool>* local_g_result_queue; ASyncQueue<bool>* local_g_result_queue;
bool b_quit; bool b_quit;
long frame_total; long frame_total[NumberOfSupportedCameras];
SysConf local_SysConf; SysConf local_SysConf;
DisplayLabelConf local_DisplayLabelConf; DisplayLabelConf local_DisplayLabelConf;
}; };

@ -136,7 +136,10 @@ void WorkThread::run()
} }
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);
#ifndef SYNC_CAMERA
emit display_timecost(local_camera_number, time_process); emit display_timecost(local_camera_number, time_process);
#endif
#ifdef __UDPSend #ifdef __UDPSend
UDPSendInfo.timecost = QString::number(time_process); UDPSendInfo.timecost = QString::number(time_process);
#endif #endif
@ -148,7 +151,9 @@ void WorkThread::run()
jd_no += QString::number(vec_results[index].size()) + ","; jd_no += QString::number(vec_results[index].size()) + ",";
} }
jd_no.chop(1); jd_no.chop(1);
#ifndef SYNC_CAMERA
emit display_jd_no(local_camera_number, jd_no); emit display_jd_no(local_camera_number, jd_no);
#endif
#ifdef __UDPSend #ifdef __UDPSend
UDPSendInfo.JD = jd_no; UDPSendInfo.JD = jd_no;
#endif #endif
@ -182,8 +187,11 @@ void WorkThread::run()
"#" + "_" + QString::number(index + 1) + ".jpg"; "#" + "_" + QString::number(index + 1) + ".jpg";
std::string filename = file_name.toLocal8Bit().constData(); std::string filename = file_name.toLocal8Bit().constData();
g_save_queue->put(std::make_pair(filename, m)); g_save_queue->put(std::make_pair(filename, m));
QString sendName = now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".jpg";
#ifdef __TCPSend #ifdef __TCPSend
TCPSendInfo.pics_name = filename; TCPSendInfo.pics_name = sendName.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo); TCP_Info_queue->put(TCPSendInfo);
#endif #endif
} }
@ -226,7 +234,9 @@ void WorkThread::run()
{ {
if (!g_debug_mode) if (!g_debug_mode)
{ {
#ifndef SYNC_CAMERA
emit event_ok(local_camera_number); emit event_ok(local_camera_number);
#endif
local_g_result_queue->put(true); local_g_result_queue->put(true);
} }
} }
@ -234,7 +244,9 @@ void WorkThread::run()
{ {
if (!g_debug_mode) if (!g_debug_mode)
{ {
#ifndef SYNC_CAMERA
emit event_ng(local_camera_number); emit event_ng(local_camera_number);
#endif
local_g_result_queue->put(false); local_g_result_queue->put(false);
} }
@ -254,10 +266,7 @@ void WorkThread::run()
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] + "#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg"; ".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
#ifdef __TCPSend
TCPSendInfo.pics_name = file_name.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo);
#endif
m = vec_out[index].clone(); m = vec_out[index].clone();
file_name = g_conf_path.save_pics_path + "/ng_result/" + file_name = g_conf_path.save_pics_path + "/ng_result/" +
now_ts.toString("yyyy-MM-dd") + "/" now_ts.toString("yyyy-MM-dd") + "/"
@ -271,14 +280,10 @@ void WorkThread::run()
".jpg"; ".jpg";
//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)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
#ifdef __TCPSend
TCPSendInfo.pics_name = file_name.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo);
#endif
} }
} }
} }
#ifndef SYNC_CAMERA
if (!g_debug_mode) if (!g_debug_mode)
{ {
emit display_check_total(local_camera_number, ++frame_total); emit display_check_total(local_camera_number, ++frame_total);
@ -288,9 +293,10 @@ void WorkThread::run()
if (unit_count >= 3) if (unit_count >= 3)
emit notify(local_camera_number, 1, image2); emit notify(local_camera_number, 1, image2);
} }
#endif
} }
else #ifndef SYNC_CAMERA
else
{ {
//±£Ö¤²»´íλ //±£Ö¤²»´íλ
if (!g_debug_mode) if (!g_debug_mode)
@ -303,6 +309,7 @@ void WorkThread::run()
qDebug() << local_camera_number << "#camera# " << now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << unit_count; qDebug() << local_camera_number << "#camera# " << now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " << unit_count;
} }
} }
#endif
#ifdef __UDPSend #ifdef __UDPSend
UDP_Info_queue->put(UDPSendInfo); UDP_Info_queue->put(UDPSendInfo);
#endif #endif

@ -10,7 +10,8 @@
class WorkThread : public QThread class WorkThread : public QThread
{ {
Q_OBJECT Q_OBJECT
#ifndef SYNC_CAMERA
signals: signals:
void notify(int Num,int Cnt,cv::Mat); void notify(int Num,int Cnt,cv::Mat);
void display_timecost(int Num,int ms); void display_timecost(int Num,int ms);
@ -19,7 +20,8 @@ signals:
void event_ok(int Num); void event_ok(int Num);
void event_ng(int Num); void event_ng(int Num);
#endif
public: public:
WorkThread(QObject *parent = 0): QThread(parent) WorkThread(QObject *parent = 0): QThread(parent)
{ {

Loading…
Cancel
Save