修复拍四张软件卡死的问题,修复conf.txt中不按顺序设置相机则balluff相机不能正常工作的问题

main
seiyu 10 months ago
parent e376b84212
commit c7c63a3b2e

@ -6,6 +6,7 @@
#include <QThread>
#include <QMutex>
#include <QTimer>
#include <qdebug.h>
#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

@ -133,7 +133,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp14</LanguageStandard>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
<SupportJustMyCode>false</SupportJustMyCode>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
@ -141,7 +141,7 @@
<SubSystem>Console</SubSystem>
<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>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>

@ -86,11 +86,13 @@ bool AlgJd::test_detect_batcht(int shoot)
{
std::vector<cv::Mat> vec_in;
std::vector<cv::Mat> vec_out;
std::vector<std::vector<std::pair<int, cv::Rect> > > vec_results;
std::vector<std::vector<std::pair<int, cv::Rect>>> 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);

@ -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;

@ -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;
}
};

@ -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<int, cv::Mat> 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<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();
@ -137,7 +139,7 @@ void SyncWorkThread::run()
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;
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);
@ -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)
{

Loading…
Cancel
Save