为三种相机添加define,方便分开管理

main
Jinhuan 2 weeks ago
parent 150db6c345
commit 7b7f1aea62

@ -1,5 +1,5 @@
#include "CaptureThread.h"
#include "common.h"
#if defined (BALLUFF_SUPPORT)
#include "exportData.h"
extern bool g_debug_mode; //相机调试模式,工作模式必须停止状态才能打开
@ -164,3 +164,4 @@ int CaptureThread::getPendingRequestNr(void)
requestPendingForDisplay_ = INVALID_ID;
return result;
}
#endif

@ -2,6 +2,8 @@
#ifndef CaptureThreadH
#define CaptureThreadH CaptureThreadH
//-----------------------------------------------------------------------------
#include "common.h"
#if defined (BALLUFF_SUPPORT)
#include "balluffcamera.h"
#include <QThread>
#include <QMutex>
@ -16,7 +18,6 @@
#include <apps/Common/qtIncludeEpilogue.h>
#include <opencv2/opencv.hpp>
#include "common.h"
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
extern int work_camera_nums;
@ -264,5 +265,6 @@ public:
}
};
#endif
//-----------------------------------------------------------------------------
#endif // CaptureThreadH

@ -1,7 +1,7 @@
#include "CaptureThreadBasler.h"
#if defined (BASLER_SUPPORT)
#include <QtWidgets/QApplication>
#include "PLCDevice.h"
#include "common.h"
#include <qdebug.h>
#include <exportData.h>
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
@ -205,3 +205,4 @@ void CaptureThreadBasler::ioTimeout()
pDev_->UserOutputValue.SetValue(false);
}
#endif

@ -2,6 +2,8 @@
#ifndef CaptureThreadBaslerH
#define CaptureThreadBaslerH CaptureThreadBaslerH
//-----------------------------------------------------------------------------
#include "common.h"
#if defined (BASLER_SUPPORT)
#include "baslercamera.h"
#include <QThread>
#include <QMutex>
@ -10,7 +12,6 @@
#include "SyncQueue.h"
#include "ASyncQueue.h"
#include "common.h"
#include <opencv2/opencv.hpp>
extern bool g_debug_mode;
@ -385,4 +386,5 @@ public:
}
};
#endif
#endif // CaptureThreadBasler

@ -1,7 +1,7 @@
#include "CaptureThreadHIK.h"
#if defined (HIK_SUPPORT)
#include <QtWidgets/QApplication>
#include "PLCDevice.h"
#include "common.h"
#include <windows.h>
#include "exportData.h"
extern bool g_debug_mode; //相机调试模式,工作模式必须停止状态才能打开
@ -324,3 +324,4 @@ void CaptureThreadHIK::process(void)
}
}
//-----------------------------------------------------------------------------
#endif

@ -2,8 +2,9 @@
#ifndef CaptureThreadHIKH
#define CaptureThreadHIKH CaptureThreadHIKH
//-----------------------------------------------------------------------------
#include "hikcamera.h"
#include "common.h"
#if defined (HIK_SUPPORT)
#include "hikcamera.h"
#include <QThread>
#include <QMutex>
#include <functional>
@ -104,4 +105,5 @@ private:
volatile bool boTerminated_;
QMutex lock_;
};
#endif
#endif // CaptureThreadHIKH

@ -1,4 +1,5 @@
#include "balluffcamera.h"
#if defined (BALLUFF_SUPPORT)
#include <algorithm> // for std::find_if
#include <iostream>
#include <thread>
@ -20,3 +21,4 @@ int BalluffCamera::Enumerate()
{
return devMgr.deviceCount();
}
#endif

@ -1,4 +1,6 @@
#pragma once
#include "common.h"
#if defined (BALLUFF_SUPPORT)
#include "SyncQueue.h"
#include "basecamera.h"
//#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
@ -18,3 +20,4 @@ public:
static mvIMPACT::acquire::DeviceManager devMgr;
static bool license_pass;
};
#endif

@ -1,4 +1,5 @@
#include "baslercamera.h"
#if defined (BASLER_SUPPORT)
#include <algorithm> // for std::find_if
#include <iostream>
#include <thread>
@ -43,3 +44,4 @@ int BaslerCamera::Enumerate()
}
return n_basler_cam;
}
#endif

@ -1,4 +1,6 @@
#pragma once
#include "common.h"
#if defined (BASLER_SUPPORT)
#include "SyncQueue.h"
#include "basecamera.h"
#include <pylon/PylonIncludes.h>
@ -30,3 +32,4 @@ public:
public:
static Pylon::DeviceInfoList_t devices;
};
#endif

@ -35,19 +35,22 @@ AlgJd alg_test;//test AI算法
QThread* pThread[NumberOfSupportedCameras];
int work_camera_nums;
#if defined (BALLUFF_SUPPORT)
//巴鲁夫相机相关
CaptureThread* pCaptureThread[NumberOfSupportedCameras];
FunctionInterface* pFI[NumberOfSupportedCameras];
mvIMPACT::acquire::GenICam::AcquisitionControl* pAC[NumberOfSupportedCameras];
#endif
#if defined (BASLER_SUPPORT)
//巴斯勒相机相关
CaptureThreadBasler* pBaslerCaptureThread[NumberOfSupportedCameras];
Pylon::CBaslerUniversalInstantCamera* BaslerCamHandle[NumberOfSupportedCameras];
#endif
#if defined (HIK_SUPPORT)
//海康相机相关
void* HIKCamHandle[NumberOfSupportedCameras];
CaptureThreadHIK* pHIKCaptureThread[NumberOfSupportedCameras];
#endif
SyncQueue<std::pair<std::string, cv::Mat>>* g_save_queue; //图片保存队列
#ifdef SYNC_CAMERA
ImageSyncArr g_image_sync_arr;
@ -531,18 +534,24 @@ Cigarette::Cigarette(QWidget* parent)
for (int i = 0; i < NumberOfSupportedCameras; i++)
{
if (SingleCamInfo[i].Detect && SingleCamInfo[i].IsOpen) {
#if defined (BALLUFF_SUPPORT)
if (SingleCamInfo[i].CamClass == BalluffClassID) {
if (pCaptureThread[i])
while (!pCaptureThread[i]->Ready)Sleep(10);
}
else if (SingleCamInfo[i].CamClass == BaslerClassID) {
#endif
#if defined (BASLER_SUPPORT)
if (SingleCamInfo[i].CamClass == BaslerClassID) {
if (pBaslerCaptureThread[i])
while (!pBaslerCaptureThread[i]->Ready)Sleep(10);
}
else if (SingleCamInfo[i].CamClass == HIKClassID) {
#endif
#if defined (HIK_SUPPORT)
if (SingleCamInfo[i].CamClass == HIKClassID) {
if (pHIKCaptureThread[i])
while (!pHIKCaptureThread[i]->Ready)Sleep(10);
}
#endif
}
}
@ -579,6 +588,7 @@ void Cigarette::start_work()
for (int i = 0; i < NumberOfSupportedCameras; i++)
{
if (SingleCamInfo[i].Detect && SingleCamInfo[i].IsOpen) {
#if defined (BALLUFF_SUPPORT)
if (SingleCamInfo[i].CamClass == BalluffClassID) {
if (pCaptureThread[i])
{
@ -588,7 +598,9 @@ void Cigarette::start_work()
pCaptureThread[i]->p_shooted_queue->clear();
}
}
else if (SingleCamInfo[i].CamClass == BaslerClassID) {
#endif
#if defined (BASLER_SUPPORT)
if (SingleCamInfo[i].CamClass == BaslerClassID) {
if (pBaslerCaptureThread[i])
{
pBaslerCaptureThread[i]->p_result_queue->clear();
@ -597,7 +609,9 @@ void Cigarette::start_work()
pBaslerCaptureThread[i]->p_shooted_queue->clear();
}
}
else if (SingleCamInfo[i].CamClass == HIKClassID) {
#endif
#if defined (HIK_SUPPORT)
if (SingleCamInfo[i].CamClass == HIKClassID) {
if (pHIKCaptureThread[i])
{
pHIKCaptureThread[i]->p_result_queue->clear();
@ -606,6 +620,7 @@ void Cigarette::start_work()
pHIKCaptureThread[i]->p_shooted_queue->clear();
}
}
#endif
}
}
@ -742,9 +757,9 @@ void Cigarette::Exit()
}
qApp->quit();
this->close();
#if defined (BASLER_SUPPORT)
Pylon::PylonTerminate();
#endif
}
//停止工作按钮
@ -2926,6 +2941,7 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
{
if (OpenOrClose == OPEN && !SingleCamInfo[Num].IsOpen)
{
#if defined (BALLUFF_SUPPORT)
if (SingleCamInfo[Num].CamClass == BalluffClassID)
{
qDebug() << "open for balluff";
@ -3021,7 +3037,9 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
}
return false;
}
else if (SingleCamInfo[Num].CamClass == BaslerClassID)
#endif
#if defined (BASLER_SUPPORT)
if (SingleCamInfo[Num].CamClass == BaslerClassID)
{
qDebug() << "open for basler";
try
@ -3142,7 +3160,9 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
}
return false;
}
else if (SingleCamInfo[Num].CamClass == HIKClassID)
#endif
#if defined (HIK_SUPPORT)
if (SingleCamInfo[Num].CamClass == HIKClassID)
{
qDebug() << "open for hik";
int nRet = MV_OK;
@ -3262,9 +3282,11 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
}
return false;
}
#endif
}
else if (OpenOrClose == CLOSE && SingleCamInfo[Num].IsOpen)
{
#if defined (BALLUFF_SUPPORT)
if (SingleCamInfo[Num].CamClass == BalluffClassID)
{
qDebug() << "close for balluff";
@ -3294,7 +3316,9 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
SingleCamInfo[Num].IsOpen = false;
return true;
}
else if (SingleCamInfo[Num].CamClass == BaslerClassID)
#endif
#if defined (BASLER_SUPPORT)
if (SingleCamInfo[Num].CamClass == BaslerClassID)
{
qDebug() << "close for basler";
disconnect(pThread[Num], SIGNAL(started()), pBaslerCaptureThread[Num], SLOT(process()));
@ -3322,7 +3346,9 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
SingleCamInfo[Num].IsOpen = false;
return true;
}
else if (SingleCamInfo[Num].CamClass == HIKClassID)
#endif
#if defined (HIK_SUPPORT)
if (SingleCamInfo[Num].CamClass == HIKClassID)
{
qDebug() << "close for hik";
void* camhandle;
@ -3351,6 +3377,7 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
SingleCamInfo[Num].IsOpen = false;
return true;
}
#endif
}
return false;
}
@ -3361,12 +3388,15 @@ void Cigarette::EnumerateCameras(SingleCamInfoStruct* TempSingleCamInfoStruct, b
//这些厂商相机枚举时候会过滤别的厂商相机,单独枚举
int basler_cnt = 0;
int filtered = 0;
#if defined (BASLER_SUPPORT)
filtered = BaslerCamera::Enumerate();
Pylon::CInstantCameraArray cameras(filtered);
Pylon::CTlFactory& tlFactory = Pylon::CTlFactory::GetInstance();
#endif
for (int i = 0; i < min(filtered, NumberOfSupportedCameras); i++)
{
#if defined (BASLER_SUPPORT)
SingleCamInfoStruct CamInfo;
//cameras[i].Attach(tlFactory.CreateDevice(BaslerCamera::devices[i]));
//Pylon::String_t selectedAction = ::GenICam::gcstring("Action");
@ -3390,11 +3420,13 @@ void Cigarette::EnumerateCameras(SingleCamInfoStruct* TempSingleCamInfoStruct, b
TempSingleCamInfo.push_back(CamInfo);
basler_cnt++;
//}
#endif
}
//这些厂商相机可以互相枚举但是Enumerate都要执行里面会初始化一些全局信息
int hik_cnt = 0;
int unfiltered = 0;
#if defined (HIK_SUPPORT)
unfiltered = HIKCamera::Enumerate();
for (int i = 0; i < min(unfiltered, NumberOfSupportedCameras); i++)
{
@ -3456,8 +3488,10 @@ void Cigarette::EnumerateCameras(SingleCamInfoStruct* TempSingleCamInfoStruct, b
hik_cnt++;
}
}
#endif
int balluff_cnt = 0;
#if defined (BALLUFF_SUPPORT)
unfiltered = BalluffCamera::Enumerate();
for (int i = 0; i < min(unfiltered, NumberOfSupportedCameras); i++)
{
@ -3484,7 +3518,7 @@ void Cigarette::EnumerateCameras(SingleCamInfoStruct* TempSingleCamInfoStruct, b
}
}
}
#endif
if (showinfo) {
std::cout << "Camera Count:\t" << TempSingleCamInfo.size() << std::endl;
if (balluff_cnt)std::cout << "Balluff Count:\t" << balluff_cnt << std::endl;
@ -3520,6 +3554,7 @@ void Cigarette::EnableDebugMode()
{
if (SingleCamInfo[i].IsOpen && SingleCamInfo[i].Detect)
{
#if defined (BALLUFF_SUPPORT)
if (SingleCamInfo[i].CamClass == BalluffClassID)
{
//设置帧率=10fps
@ -3528,7 +3563,9 @@ void Cigarette::EnableDebugMode()
//关闭外触发
pAC[i]->triggerMode.writeS("Off");
}
else if (SingleCamInfo[i].CamClass == HIKClassID)
#endif
#if defined (HIK_SUPPORT)
if (SingleCamInfo[i].CamClass == HIKClassID)
{
int nRet = MV_OK;
MV_CC_SetFrameRate(HIKCamHandle[i], 10.0);
@ -3538,7 +3575,9 @@ void Cigarette::EnableDebugMode()
nRet = MV_CC_SetEnumValue(HIKCamHandle[i], "TriggerMode", MV_TRIGGER_MODE_OFF);
if (nRet) { std::cout << "can not set Hik's TriggerMode" << std::endl; }
}
else if (SingleCamInfo[i].CamClass == BaslerClassID)
#endif
#if defined (BASLER_SUPPORT)
if (SingleCamInfo[i].CamClass == BaslerClassID)
{
bool nRet = false;
nRet = BaslerCamHandle[i]->AcquisitionFrameRate.TrySetValue(10);
@ -3556,6 +3595,7 @@ void Cigarette::EnableDebugMode()
if (!nRet) { std::cout << "can not set Basler's TriggerMode_Off" << std::endl; }
#endif
}
#endif
}
}
g_debug_mode = true;
@ -3567,6 +3607,7 @@ void Cigarette::DisableDebugMode()
{
if (SingleCamInfo[i].IsOpen && SingleCamInfo[i].Detect)
{
#if defined (BALLUFF_SUPPORT)
if (SingleCamInfo[i].CamClass == BalluffClassID)
{
//设置帧率
@ -3575,7 +3616,9 @@ void Cigarette::DisableDebugMode()
pAC[i]->triggerSource.writeS("Line4");
pAC[i]->triggerActivation.writeS("RisingEdge");
}
else if (SingleCamInfo[i].CamClass == HIKClassID)
#endif
#if defined (HIK_SUPPORT)
if (SingleCamInfo[i].CamClass == HIKClassID)
{
int nRet = MV_OK;
nRet = MV_CC_SetEnumValue(HIKCamHandle[i], "TriggerMode", MV_TRIGGER_MODE_ON);
@ -3592,7 +3635,9 @@ void Cigarette::DisableDebugMode()
nRet = MV_CC_SetBoolValue(HIKCamHandle[i], "AcquisitionFrameRateEnable", false);
if (nRet) { std::cout << "can not set Hik's AcquisitionFrameRateEnable" << std::endl; }
}
else if (SingleCamInfo[i].CamClass == BaslerClassID)
#endif
#if defined (BASLER_SUPPORT)
if (SingleCamInfo[i].CamClass == BaslerClassID)
{
bool nRet = false;
#ifndef USB_BASLER_NEW_FW
@ -3608,6 +3653,7 @@ void Cigarette::DisableDebugMode()
nRet = BaslerCamHandle[i]->AcquisitionFrameRateEnable.TrySetValue(false);
if (!nRet) { std::cout << "can not set Basler's AcquisitionFrameRateEnable" << std::endl; }
}
#endif
}
}
g_debug_mode = false;
@ -3687,11 +3733,13 @@ void Cigarette::record_output_statistic(qint64 quantity, int Kick[NumberOfSuppor
last_shift = shift;
}
#ifdef __MQTTSend
void Cigarette::MqttMsgSend()
{
_MqttSendInfo MqttSendInfo;
MQTT_Info_queue->put(MqttSendInfo);
}
#endif
#ifdef __UDPSend
void Cigarette::recMsgFromUdp(QString data)

@ -10,8 +10,13 @@
#define CLEAR_THREAD //定时清理线程
//#define __UDPSend //网络发送功能
//#define __TCPSend // TCP发送
#define __MQTTSend // MQTT发送
//#define __MQTTSend // MQTT发送
#define BASLER_SUPPORT
#if defined (BASLER_SUPPORT)
#define USB_BASLER_NEW_FW //使用basler定制固件
#endif
#define HIK_SUPPORT
#define BALLUFF_SUPPORT
//#define IMM_PROCESS //拍照后立马处理,不等校验信号
//#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号
#define ONE_TIME_SHIFT //错开一拍发送反馈(默认错开两次)

@ -1,4 +1,5 @@
#include "hikcamera.h"
#if defined (HIK_SUPPORT)
#include <algorithm>
#include <iostream>
#include <thread>
@ -36,3 +37,4 @@ int HIKCamera::Enumerate()
}
}
#endif

@ -1,4 +1,6 @@
#pragma once
#include "common.h"
#if defined (HIK_SUPPORT)
#include "SyncQueue.h"
#include "basecamera.h"
#include "MvCameraControl.h"
@ -18,3 +20,4 @@ public:
static MV_CC_DEVICE_INFO_LIST stDeviceList;
};
#endif
Loading…
Cancel
Save