From c7c63a3b2eef4ded8eda012fa0cf61549e16d7ce Mon Sep 17 00:00:00 2001 From: seiyu Date: Mon, 11 Mar 2024 17:04:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8B=8D=E5=9B=9B=E5=BC=A0?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E5=8D=A1=E6=AD=BB=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8Dconf.txt=E4=B8=AD=E4=B8=8D=E6=8C=89?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E8=AE=BE=E7=BD=AE=E7=9B=B8=E6=9C=BA=E5=88=99?= =?UTF-8?q?balluff=E7=9B=B8=E6=9C=BA=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cigarette/CaptureThreadBasler.h | 2 +- Cigarette/Cigarette.vcxproj | 4 ++-- Cigarette/alg_jd.cpp | 5 ++++- Cigarette/cigarette.cpp | 9 ++++----- Cigarette/common.h | 3 +-- Cigarette/syncworkthread.cpp | 22 +++++++++++++--------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Cigarette/CaptureThreadBasler.h b/Cigarette/CaptureThreadBasler.h index 0f2dd49..93c4cf3 100644 --- a/Cigarette/CaptureThreadBasler.h +++ b/Cigarette/CaptureThreadBasler.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "SyncQueue.h" #include "ASyncQueue.h" @@ -343,7 +344,6 @@ public: // Create an OpenCV image from a pylon image. openCvImage = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC1, (uint8_t*)pylonImage.GetBuffer()); cv::Mat image_clone = openCvImage.clone(); - if (!g_debug_mode) { #ifdef IMM_PROCESS diff --git a/Cigarette/Cigarette.vcxproj b/Cigarette/Cigarette.vcxproj index 515cc7f..0c448e3 100644 --- a/Cigarette/Cigarette.vcxproj +++ b/Cigarette/Cigarette.vcxproj @@ -133,7 +133,7 @@ true true stdcpp14 - Disabled + MaxSpeed false 4819;%(DisableSpecificWarnings) @@ -141,7 +141,7 @@ Console $(OutDir)\$(ProjectName).exe $(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) - true + false qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies) diff --git a/Cigarette/alg_jd.cpp b/Cigarette/alg_jd.cpp index 20a23c2..7227380 100644 --- a/Cigarette/alg_jd.cpp +++ b/Cigarette/alg_jd.cpp @@ -86,11 +86,13 @@ bool AlgJd::test_detect_batcht(int shoot) { std::vector vec_in; std::vector vec_out; - std::vector > > vec_results; + std::vector>> vec_results; cv::Mat m1, m2, m3; + cv::Mat m4; m1 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0)); m2 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0)); m3 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0)); + m4 = cv::Mat(544, 728, CV_8UC3, cv::Scalar(0, 0, 0)); double t = (double)cv::getTickCount(); switch(shoot){ @@ -101,6 +103,7 @@ bool AlgJd::test_detect_batcht(int shoot) } case 3:vec_in.push_back(m3); case 2:vec_in.push_back(m2); + case 4:vec_in.push_back(m4); default:{ vec_in.push_back(m1); detect_batch(vec_in, vec_out, vec_results); diff --git a/Cigarette/cigarette.cpp b/Cigarette/cigarette.cpp index cdfd686..04fd395 100644 --- a/Cigarette/cigarette.cpp +++ b/Cigarette/cigarette.cpp @@ -94,7 +94,7 @@ bool onrestart = false; VOID BeforeWork(int shoot[]) { #ifdef AI_WARM_UP - for (int j = 0;j<10;j++) + for (int j = 0;j < 10; j++) { for (int i = 0; i < NumberOfSupportedCameras; i++) { @@ -960,7 +960,7 @@ void Cigarette::OnToolButtonCamReleasedHub(int Num) if (!SingleCamInfo[Num].IsOpen) { emit sengMsgToClog("Start open camera " + QString::number(Num) + "."); - if(ControlCamOpenOrClose(Num,OPEN)) + if(ControlCamOpenOrClose(Num, OPEN)) { cam_work_mat[Num]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));//相机工作提示 cam_status_mat[Num]->setStyleSheet(tr("background-color: rgb(0,170,0);"));//相机联机指示 @@ -972,7 +972,7 @@ void Cigarette::OnToolButtonCamReleasedHub(int Num) else { emit sengMsgToClog("Start close camera " + QString::number(Num) + "."); - if(ControlCamOpenOrClose(Num,CLOSE)) + if(ControlCamOpenOrClose(Num, CLOSE)) { cam_work_mat[Num]->setStyleSheet(tr("background-color: rgb(255, 255, 0);")); QString str = QString("border-image: url(:/Cigarette/Resources/cam%1_no.png);").arg(Num+1); @@ -3194,8 +3194,7 @@ bool Cigarette::ControlCamOpenOrClose(int Num,bool OpenOrClose) nRet = MV_CC_SetFloatValue(camhandle, "Gain", g_sys_conf.gain[Num]); if (nRet) { std::cout << "can not set Gain" << std::endl; nnRet = nRet; } - pHIKCaptureThread[Num] = new CaptureThreadHIK(camhandle, false,Num); - + pHIKCaptureThread[Num] = new CaptureThreadHIK(camhandle, false, Num); #ifdef SYNC_CAMERA pHIKCaptureThread[Num]->p_image_sync_queue = g_image_sync_queue; pHIKCaptureThread[Num]->p_image_sync_arr = &g_image_sync_arr; diff --git a/Cigarette/common.h b/Cigarette/common.h index d3881c8..f1d5e0e 100644 --- a/Cigarette/common.h +++ b/Cigarette/common.h @@ -140,11 +140,10 @@ public: no[i][0]=0; no[i][1]=0; no[i][2]=0; - shoot[i]=3; + shoot[i]=4; } MonitorIP = "192.168.10.1"; FeedbackPort = MonitorPort + NumberOfSupportedCameras*2; - } }; diff --git a/Cigarette/syncworkthread.cpp b/Cigarette/syncworkthread.cpp index 22092be..e9e5ade 100644 --- a/Cigarette/syncworkthread.cpp +++ b/Cigarette/syncworkthread.cpp @@ -69,10 +69,12 @@ void SyncWorkThread::run() local_g_image_sync_queue->take(element_vec); bool IsNGForAll = false; int merge_index; - cv::Mat merge_image = cv::Mat::zeros(512 * work_camera_nums, 640 * g_sys_conf.shoot[0], CV_8UC3); + cv::Rect roi; + int j = 0; // 实际工作的相机标识,element_vec中可能有相机没在工作 for (int i = 0; i < element_vec.size(); i++)//每个相机的图轮流遍历 { local_camera_number = i; + int isWork = element_vec[i].first; std::pair element; element = element_vec[i]; int unit_count = element.first; @@ -110,17 +112,17 @@ void SyncWorkThread::run() { continue; //图像为空,跳过 } + cv::Mat merge_image = cv::Mat::zeros(512 * work_camera_nums, 640 * g_sys_conf.shoot[i], CV_8UC3); if (image.channels() == 1) { cv::cvtColor(image, image, CV_BGR2RGB); //灰度图像转为彩色图像 } + cv::resize(image, image, cv::Size(640, 512 * unit_count)); if (local_SysConf.shoot[local_camera_number] == unit_count) { - cv::Rect roi; std::vector 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(); @@ -137,7 +139,7 @@ void SyncWorkThread::run() std::vector>> vec_results; QDateTime ts_start = QDateTime::currentDateTime(); if (unit_count == 1) { - std::vector > results; + std::vector> results; cv::Mat imagein, imageout; imagein = vec_in[0]; alg_jd[local_camera_number].detect(imagein, imageout, results); @@ -157,7 +159,6 @@ void SyncWorkThread::run() #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()) + ","; @@ -193,10 +194,10 @@ void SyncWorkThread::run() /// 合成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); + merge_index = j * unit_count + index + 1; + roi = cv::Rect(index * m.cols, j * 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") + "/" @@ -302,13 +303,15 @@ void SyncWorkThread::run() #ifdef SYNC_CAMERA if (!g_debug_mode) { - emit display_check_total(local_camera_number, ++(frame_total[local_camera_number])); + if(isWork != 0) + 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 + } else { @@ -328,6 +331,7 @@ void SyncWorkThread::run() #ifdef __UDPSend UDP_Info_queue->put(UDPSendInfo); #endif + j++; } if (IsNGForAll) {