修复 日志界面修复,还需要观察测试
添加 相机类,待完善
This commit is contained in:
+23
-11
@@ -2,7 +2,7 @@
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <qqueue.h>
|
||||
QQueue<cv::Mat> matQueue;
|
||||
std::vector<cv::Mat> matVec;
|
||||
std::mutex queueMutex;//掉线锁
|
||||
|
||||
std::mutex moduleMutex;//掉线锁
|
||||
@@ -166,7 +166,8 @@ void __stdcall ImageCallBackEx(unsigned char* pData0, MV_FRAME_OUT_INFO_EX* pFra
|
||||
qDebug() << "[INFO] " << " srcImage Exist,Time:" << (time_End - time_Start) / 1000.0 << "s" << "--CameraName:" << QString::fromStdString(Username);
|
||||
}
|
||||
queueMutex.lock();
|
||||
matQueue.append(srcImage);
|
||||
matVec.push_back(srcImage);
|
||||
srcImage.release();
|
||||
queueMutex.unlock();
|
||||
pData0 = { 0 };
|
||||
}
|
||||
@@ -174,7 +175,7 @@ void __stdcall ImageCallBackEx(unsigned char* pData0, MV_FRAME_OUT_INFO_EX* pFra
|
||||
//搜索所有设备
|
||||
int SearchDevice()
|
||||
{
|
||||
int nRet=MV_OK;
|
||||
int nRet = MV_OK;
|
||||
MV_GENTL_IF_INFO_LIST pstIFList;
|
||||
if (m_stDevList.nDeviceNum == 0)
|
||||
{
|
||||
@@ -183,7 +184,7 @@ int SearchDevice()
|
||||
// ch:枚举子网内所有设备 | en:Enumerate all devices within subnet
|
||||
//nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE || MV_USB_DEVICE, &m_stDevList);
|
||||
nRet = MV_CC_EnumInterfacesByGenTL(&pstIFList, ".//config//MvFGProducerCML.cti");
|
||||
nRet = MV_CC_EnumDevicesByGenTL(pstIFList.pIFInfo[pstIFList.nInterfaceNum-1], &m_stDevList);
|
||||
nRet = MV_CC_EnumDevicesByGenTL(pstIFList.pIFInfo[pstIFList.nInterfaceNum - 1], &m_stDevList);
|
||||
}
|
||||
for (int i = 0; i < m_stDevList.nDeviceNum; i++)
|
||||
{
|
||||
@@ -265,22 +266,32 @@ bool Hd_MvCamera_module::sendData(std::vector<cv::Mat>& mat, QByteArray& data)
|
||||
|
||||
}
|
||||
}
|
||||
else if (command == "DigitalShift")
|
||||
{
|
||||
int nRet = MV_CC_SetFloatValue(handle, "DigitalShift", value.toFloat());
|
||||
if (nRet != MV_OK)
|
||||
{
|
||||
cout << "DigitalShift" << inputString.toStdString() << endl;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int cnt = 0;
|
||||
while (matQueue.size()==0)
|
||||
while (matVec.size() <= 1)
|
||||
{
|
||||
cnt++;
|
||||
QThread::msleep(1);
|
||||
if(cnt>3000)
|
||||
if (cnt > 10000)
|
||||
return false;
|
||||
}
|
||||
queueMutex.lock();
|
||||
while (matQueue.size() != 0)
|
||||
mat.push_back(matQueue.dequeue());
|
||||
for(auto matImg: matVec)
|
||||
mat.push_back(matImg);
|
||||
//mat.push_back(matQueue.dequeue());
|
||||
|
||||
matQueue.clear();
|
||||
matVec.clear();
|
||||
queueMutex.unlock();
|
||||
|
||||
}
|
||||
@@ -297,7 +308,7 @@ bool Hd_MvCamera_module::reciveData(std::vector<cv::Mat>& mat, QByteArray& data)
|
||||
|
||||
bool Hd_MvCamera_module::initParas(QByteArray&)
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
if (!Username.compare("dummy"))
|
||||
{
|
||||
qDebug() << "[INFO] " << " start" << "--UserName: dummy creat sucess";
|
||||
@@ -347,6 +358,7 @@ bool Hd_MvCamera_module::initParas(QByteArray&)
|
||||
bool Hd_MvCamera_module::run()
|
||||
{
|
||||
qDebug() << "[INFO] " << " run start" << QString::fromStdString(Username);
|
||||
return true;
|
||||
try
|
||||
{
|
||||
srcImage.release();
|
||||
@@ -354,7 +366,7 @@ bool Hd_MvCamera_module::run()
|
||||
int reconnectSign = reconnectCount;
|
||||
while (true)
|
||||
{
|
||||
if(reconnectCount!= reconnectSign)
|
||||
if (reconnectCount != reconnectSign)
|
||||
m_thread->start();
|
||||
if (m_flag)
|
||||
{
|
||||
+38
-21
@@ -1,5 +1,23 @@
|
||||
#include "hd_mvcamera_module.h"
|
||||
std::mutex moduleMutex;//掉线锁
|
||||
|
||||
QByteArray MV_CC_DeviceInfoListToQByteArray(const MV_CC_DEVICE_INFO_LIST& deviceInfoList) {
|
||||
QByteArray byteArray;
|
||||
byteArray.resize(sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
memcpy(byteArray.data(), &deviceInfoList, sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
return byteArray;
|
||||
}
|
||||
MV_CC_DEVICE_INFO_LIST QByteArrayToMV_CC_DeviceInfoList(const QByteArray& byteArray) {
|
||||
MV_CC_DEVICE_INFO_LIST deviceInfoList;
|
||||
if (byteArray.size() == sizeof(MV_CC_DEVICE_INFO_LIST)) {
|
||||
memcpy(&deviceInfoList, byteArray.constData(), sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
}
|
||||
else {
|
||||
qDebug() << "Invalid size of QByteArray for MV_CC_DEVICE_INFO_LIST!";
|
||||
}
|
||||
return deviceInfoList;
|
||||
}
|
||||
|
||||
int reconnectCount = 0;
|
||||
int SearchDevice();
|
||||
void __stdcall ImageCallBackEx(unsigned char* pData0, MV_FRAME_OUT_INFO_EX* pFrameInfo0, void* pUser0);
|
||||
@@ -172,9 +190,11 @@ int SearchDevice()
|
||||
int nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE || MV_USB_DEVICE, &m_stDevList);
|
||||
for (int i = 0; i < m_stDevList.nDeviceNum; i++)
|
||||
{
|
||||
unsigned char* name = m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber;
|
||||
string serialNumber = static_cast<string>((LPCSTR)name);
|
||||
if (Username == serialNumber)
|
||||
unsigned char* serialNumber = m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber;
|
||||
unsigned char* userDefineName = m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chUserDefinedName;
|
||||
string serialNumberStr = static_cast<string>((LPCSTR)serialNumber);
|
||||
string userDefineNameStr = static_cast<string>((LPCSTR)userDefineName);
|
||||
if (Username == serialNumberStr || Username == userDefineNameStr)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
@@ -186,18 +206,17 @@ int SearchDevice()
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Hd_MvCamera_module::Hd_MvCamera_module()
|
||||
{
|
||||
m_thread = new MyThread;
|
||||
}
|
||||
|
||||
void CloseDevice()
|
||||
{
|
||||
MV_CC_StopGrabbing(handle);
|
||||
MV_CC_CloseDevice(handle);
|
||||
MV_CC_DestroyHandle(handle);
|
||||
}
|
||||
Hd_MvCamera_module::Hd_MvCamera_module()
|
||||
{
|
||||
m_thread = new MyThread;
|
||||
}
|
||||
|
||||
Hd_MvCamera_module::~Hd_MvCamera_module()
|
||||
{
|
||||
CloseDevice();
|
||||
@@ -253,23 +272,21 @@ bool Hd_MvCamera_module::sendData(std::vector<cv::Mat>& mat, QByteArray& data)
|
||||
|
||||
bool Hd_MvCamera_module::reciveData(std::vector<cv::Mat>& mat, QByteArray& data)
|
||||
{
|
||||
if (data.size() > 1000)
|
||||
m_stDevList = QByteArrayToMV_CC_DeviceInfoList(data);
|
||||
else
|
||||
Username = data.toStdString();
|
||||
m_flag = false;
|
||||
Username = data.toStdString();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Hd_MvCamera_module::initParas(QByteArray&)
|
||||
{
|
||||
|
||||
if (!Username.compare("dummy"))
|
||||
{
|
||||
qDebug() << "[INFO] " << " start" << "--UserName: dummy creat sucess";
|
||||
return true;
|
||||
}
|
||||
SearchDevice();
|
||||
unsigned char* serialNumber = m_stDevList.pDeviceInfo[index]->SpecialInfo.stGigEInfo.chSerialNumber;
|
||||
string userName = static_cast<string>((LPCSTR)serialNumber);
|
||||
qDebug() << "[INFO] " << " start" << "--UserName:" << QString::fromStdString(userName);
|
||||
string userNameStr = static_cast<string>((LPCSTR)serialNumber);
|
||||
qDebug() << "[INFO] " << " start" << "--UserName:" << QString::fromStdString(userNameStr);
|
||||
if (handle != NULL)
|
||||
{
|
||||
MV_CC_StopGrabbing(handle);
|
||||
@@ -279,11 +296,11 @@ bool Hd_MvCamera_module::initParas(QByteArray&)
|
||||
}
|
||||
|
||||
//打开相机
|
||||
MV_CC_CreateHandle(&handle, m_stDevList.pDeviceInfo[index]);
|
||||
int nRet = MV_CC_OpenDevice(handle);
|
||||
unsigned int nRet = MV_CC_CreateHandle(&handle, m_stDevList.pDeviceInfo[index]);
|
||||
nRet = MV_CC_OpenDevice(handle);
|
||||
////触发模式
|
||||
MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE);
|
||||
MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
|
||||
nRet = MV_CC_SetEnumValue(handle, "TriggerSource", MV_TRIGGER_SOURCE_SOFTWARE);
|
||||
nRet = MV_CC_SetEnumValue(handle, "TriggerMode", MV_TRIGGER_MODE_ON);
|
||||
// //加载用户集
|
||||
nRet = MV_CC_SetEnumValueByString(handle, "UserSetSelector", "UserSet1");
|
||||
if (MV_OK != nRet)
|
||||
@@ -5,7 +5,7 @@ message( " model start : " ${CURRENT_FOLDER}:${RUN_TIME})
|
||||
|
||||
|
||||
|
||||
set(DLL_NAMES "halcon" "opencv" "3DAI""algo""sqlite" "handdleAI""myTools")
|
||||
set(DLL_NAMES "halcon" "opencv" "sqlite" "handdleAI""myTools" "mvs" "algo2")
|
||||
foreach(child ${DLL_NAMES})
|
||||
LIST(APPEND ENV_INCLUDE ${${child}_include})
|
||||
LIST(APPEND ENV_LIB ${${child}_lib})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <algorithmThread.h>
|
||||
#include <ReadBarcode.h>
|
||||
#include "camera_thread.h"
|
||||
#include "myiothread.h"
|
||||
#include "FrontendBackendBridge.h"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <HalconCpp.h>
|
||||
#include <qthread.h>
|
||||
#include <qqueue.h>
|
||||
#include <qmutex.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algo2.h>
|
||||
#include <filesystem>
|
||||
#include <opencv.hpp>
|
||||
#include <string>
|
||||
@@ -13,7 +13,9 @@
|
||||
#include <QtConcurrent/qtconcurrent>.
|
||||
#include <threadPoolController.h>
|
||||
#include <omp.h>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
using namespace HalconCpp;
|
||||
enum ngTypeEnum
|
||||
{
|
||||
OK,
|
||||
@@ -97,7 +99,7 @@ public:
|
||||
}
|
||||
cv::Rect boundingBox = cv::boundingRect(contour);
|
||||
cv::Point mid(boundingBox.x + boundingBox.width / 2, boundingBox.y + boundingBox.height / 2);
|
||||
int sideLength = std::max(std::max(boundingBox.width, boundingBox.height), 128);
|
||||
int sideLength = max(max(boundingBox.width, boundingBox.height), 128);
|
||||
cv::Mat squareImage(sideLength, sideLength, imgInput.type(), cv::Scalar(0, 0, 0));
|
||||
cv::Rect expectRect(mid.x - sideLength / 2, mid.y - sideLength / 2, sideLength, sideLength);
|
||||
int xOffset = 0;
|
||||
@@ -132,7 +134,7 @@ public:
|
||||
return cv::Mat();
|
||||
}
|
||||
cv::Point mid(boundingBox.x + boundingBox.width / 2, boundingBox.y + boundingBox.height / 2);
|
||||
int sideLength = std::max(std::max(boundingBox.width, boundingBox.height), 128);
|
||||
int sideLength = max(max(boundingBox.width, boundingBox.height), 128);
|
||||
cv::Mat squareImage(sideLength, sideLength, imgInput.type(), cv::Scalar(0, 0, 0));
|
||||
cv::Rect expectRect(mid.x - sideLength / 2, mid.y - sideLength / 2, sideLength, sideLength);
|
||||
int xOffset = 0;
|
||||
@@ -611,7 +613,7 @@ public:
|
||||
static bool isContoursOverlap(const std::vector<cv::Point>& contour1, const std::vector<cv::Point>& contour2, double thresholdPercent = 0) {
|
||||
cv::Rect rect1 = cv::boundingRect(contour1);
|
||||
cv::Rect rect2 = cv::boundingRect(contour2);
|
||||
cv::Size tempImgSize(std::max(rect1.x + rect1.width, rect2.x + rect2.width), max(rect1.y + rect1.height, rect2.y + rect2.height));
|
||||
cv::Size tempImgSize(max(rect1.x + rect1.width, rect2.x + rect2.width), max(rect1.y + rect1.height, rect2.y + rect2.height));
|
||||
cv::Mat binaryImage = cv::Mat::zeros(tempImgSize,CV_8U);
|
||||
|
||||
// 画出目标轮廓
|
||||
@@ -640,7 +642,7 @@ public:
|
||||
cv::Rect intersection = rect1 & rect2;
|
||||
if (thresholdPercent != 0)//如果有阈值
|
||||
{
|
||||
int maxCnotourArea = std::max(rect1.area(), rect2.area());
|
||||
int maxCnotourArea = max(rect1.area(), rect2.area());
|
||||
if (intersection.area() / maxCnotourArea < thresholdPercent)
|
||||
return false;
|
||||
}
|
||||
@@ -1046,7 +1048,7 @@ public:
|
||||
{
|
||||
flag = true;
|
||||
data2.contour = simpleAlgo::contourPlusContour(data.contour, data2.contour);//融合
|
||||
data2.ngType = std::max(data.ngType, data2.ngType);
|
||||
data2.ngType = max(data.ngType, data2.ngType);
|
||||
}
|
||||
}
|
||||
if (flag == false)// 否
|
||||
@@ -1072,7 +1074,7 @@ public:
|
||||
{
|
||||
flag = true;
|
||||
data2.contour = simpleAlgo::contourPlusContour(data.contour, data2.contour);//融合
|
||||
data2.ngType = std::max(data.ngType, data2.ngType);
|
||||
data2.ngType = max(data.ngType, data2.ngType);
|
||||
}
|
||||
}
|
||||
if (flag == false)// 否
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
#include <backEndController.h>
|
||||
#include <triggerController.h>
|
||||
|
||||
#include <cameraController.h>
|
||||
#include <jsonParsing.h>
|
||||
#include <future>
|
||||
backEndController::backEndController()
|
||||
{
|
||||
_jsonConfiguration = new jsonConfiguration();
|
||||
_triggerController = new triggerController();
|
||||
_triggerController->init(this);
|
||||
_cameraController = new cameraController();
|
||||
std::vector<std::future<void>> futures;//Òì²½³õʼ»¯
|
||||
futures.push_back(std::async(std::launch::async, &triggerController::init, _triggerController, this));
|
||||
futures.push_back(std::async(std::launch::async, &cameraController::init, _cameraController, this));
|
||||
for (auto& future : futures) {
|
||||
future.wait();
|
||||
}
|
||||
/*_triggerController->init(this);
|
||||
_cameraController->init(this);*/
|
||||
}
|
||||
backEndController::~backEndController()
|
||||
{
|
||||
delete _triggerController;
|
||||
delete _cameraController;
|
||||
delete _jsonConfiguration;
|
||||
}
|
||||
@@ -4,13 +4,17 @@
|
||||
#include <globalStruct.h>
|
||||
class triggerController;
|
||||
class cameraController;
|
||||
class jsonConfiguration;
|
||||
class backEndController :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
bool init = false;
|
||||
triggerController* _triggerController;//´¥·¢Æ÷
|
||||
cameraController* _cameraController;
|
||||
jsonConfiguration* _jsonConfiguration;
|
||||
backEndController();
|
||||
~backEndController();
|
||||
signals:
|
||||
void sendErrorToMainwindow(backEndError);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
#include <cameraController.h>
|
||||
#include <backEndController.h>
|
||||
#include <jsonParsing.h>
|
||||
#include <qlibrary.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <MvCameraControl.h>
|
||||
#include <CameraParams.h>
|
||||
static QByteArray MV_CC_DeviceInfoListToQByteArray(const MV_CC_DEVICE_INFO_LIST& deviceInfoList) {
|
||||
QByteArray byteArray;
|
||||
byteArray.resize(sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
memcpy(byteArray.data(), &deviceInfoList, sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
return byteArray;
|
||||
}
|
||||
static MV_CC_DEVICE_INFO_LIST QByteArrayToMV_CC_DeviceInfoList(const QByteArray& byteArray) {
|
||||
MV_CC_DEVICE_INFO_LIST deviceInfoList;
|
||||
if (byteArray.size() == sizeof(MV_CC_DEVICE_INFO_LIST)) {
|
||||
memcpy(&deviceInfoList, byteArray.constData(), sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
}
|
||||
else {
|
||||
qDebug() << "Invalid size of QByteArray for MV_CC_DEVICE_INFO_LIST!";
|
||||
}
|
||||
return deviceInfoList;
|
||||
}
|
||||
static MV_CC_DEVICE_INFO_LIST searchMvDevice()
|
||||
{
|
||||
MV_CC_DEVICE_INFO_LIST m_stDevList;
|
||||
memset(&m_stDevList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
|
||||
int nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE || MV_USB_DEVICE, &m_stDevList);
|
||||
return m_stDevList;
|
||||
}
|
||||
|
||||
cameraController::~cameraController()
|
||||
{
|
||||
for (auto module : camerasVec)
|
||||
{
|
||||
Base* base_ptr = module.module_ptr;
|
||||
delete base_ptr;
|
||||
}
|
||||
}
|
||||
void cameraController::init(backEndController* input)
|
||||
{
|
||||
_backEndController = input;
|
||||
#pragma region 加载相机dll
|
||||
for (auto val = 0; val < input->_jsonConfiguration->camera.cameraList.size(); val++)
|
||||
{
|
||||
QString camera_key = input->_jsonConfiguration->camera.cameraList[val].connectionName;
|
||||
QString moduleName = input->_jsonConfiguration->camera.cameraList[val].moduleName; // 相机模块名
|
||||
QVector<QString> surfaceVec;
|
||||
QByteArray init_Byte;
|
||||
// 加载相机模块
|
||||
if (!loadModule(camera_key, moduleName, init_Byte))
|
||||
{
|
||||
qCritical() << "[Error] " << " moduleName:" << moduleName << " load camera module failed! ";
|
||||
return;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
//非海康相机可跳过
|
||||
MV_CC_DEVICE_INFO_LIST m_stDevList = searchMvDevice();
|
||||
QByteArray mvDevices = MV_CC_DeviceInfoListToQByteArray(m_stDevList);
|
||||
|
||||
for (auto i = 0; i < camerasVec.size(); i++)
|
||||
{
|
||||
cameraModule m_module = camerasVec.at(i);
|
||||
QString moduleName = m_module.moduleName;
|
||||
QString key = m_module.key;
|
||||
//传递初始化参数
|
||||
QByteArray initByte = m_module.m_initByte;
|
||||
QByteArray m_keyByte = key.toUtf8();
|
||||
//遍历是否有相同key的相机,如果有直接复制指针
|
||||
for (int count = 0; count < camerasVec.size(); count++)
|
||||
if (!camerasVec[count].key.compare(m_module.key) && count < i)
|
||||
m_module.module_ptr = camerasVec[count].module_ptr;
|
||||
m_module.module_ptr->reciveData(vec_mat, m_keyByte); //初始化相机
|
||||
|
||||
//非海康相机可跳过
|
||||
for (int i = 0; i < m_stDevList.nDeviceNum; i++)
|
||||
{
|
||||
std::string userDefineName = static_cast<std::string>((LPCSTR)m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chUserDefinedName);
|
||||
std::string serialNumber = static_cast<std::string>((LPCSTR)m_stDevList.pDeviceInfo[i]->SpecialInfo.stGigEInfo.chSerialNumber);
|
||||
if (!serialNumber.compare(m_module.key.toStdString()) || !userDefineName.compare(m_module.key.toStdString()))
|
||||
{
|
||||
m_module.module_ptr->reciveData(vec_mat, mvDevices);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_module.module_ptr->initParas(initByte))
|
||||
{
|
||||
camera* _camera = new camera(m_module);
|
||||
cameras.insert(std::make_pair(m_module.key, _camera));
|
||||
qDebug() << "[INFO] " << " initParas success!";
|
||||
}
|
||||
else
|
||||
qCritical() << "[Error] " << " moduleName:" << m_module.moduleName << " initParas failed!";
|
||||
}
|
||||
}
|
||||
bool cameraController::loadModule(QString keyName, QString moduleName, QByteArray initByte)
|
||||
{
|
||||
QString task_thread_index = 0;
|
||||
try
|
||||
{
|
||||
QString module_path = "./" + moduleName;
|
||||
qDebug() << "[INFO] " << " module_path:" << module_path;
|
||||
|
||||
/////// 自动拷贝重用dll
|
||||
if (QString(module_path.at(module_path.size() - 1)).toInt() > 0) {
|
||||
//命名格式: 模块名+1/2/3...
|
||||
QString path_model = module_path.mid(0, module_path.size() - 1);
|
||||
if (QFile::exists(path_model + ".dll")) {
|
||||
QFile::remove(module_path + ".dll");
|
||||
QFile::copy(path_model + ".dll", module_path + ".dll");
|
||||
|
||||
qDebug() << "[INFO] " << "copy dll " << module_path;
|
||||
}
|
||||
|
||||
}
|
||||
/// 动态加载dll
|
||||
|
||||
QLibrary* m_lib = new QLibrary(module_path);
|
||||
lib_list.append(m_lib);
|
||||
bool flag = m_lib->load();
|
||||
if (!m_lib->isLoaded())
|
||||
{
|
||||
|
||||
qDebug() << "[Error] " << " Loaded error:" << m_lib->errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
CreateFunction createFun = (CreateFunction)m_lib->resolve("create");
|
||||
ReleaseFunction releaseFun = (ReleaseFunction)m_lib->resolve("destory");
|
||||
if (createFun && releaseFun)
|
||||
{
|
||||
cameraModule m_module;
|
||||
m_module.key = keyName;
|
||||
m_module.m_initByte = initByte;
|
||||
m_module.moduleName = moduleName;
|
||||
m_module.module_ptr = createFun();
|
||||
m_module.destory_ptr = releaseFun;
|
||||
|
||||
if (!task_thread_index.isEmpty())
|
||||
m_module.task_thread_index = task_thread_index;
|
||||
|
||||
camerasVec.push_back(m_module);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_lib;
|
||||
m_lib = nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (QString event)
|
||||
{
|
||||
qCritical() << "[Error] " << " event:" << event;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,76 @@
|
||||
#define CAMERACONTROLLER_H
|
||||
#include <QString>
|
||||
#include <backStruct.h>
|
||||
#include <unordered_map>
|
||||
#include <qlibrary.h>
|
||||
#include <opencv.hpp>
|
||||
#include <unordered_map>
|
||||
#include <qqueue.h>
|
||||
#include <qthread.h>
|
||||
#include <qdebug.h>
|
||||
|
||||
class backEndController;
|
||||
class camera : public QThread
|
||||
{
|
||||
public:
|
||||
QString cameraName;
|
||||
camera(cameraModule cameraModulePtrIn)
|
||||
{
|
||||
cameraModulePtr=cameraModulePtrIn;
|
||||
cameraName = cameraModulePtr.key;
|
||||
this->start();
|
||||
}
|
||||
void run()
|
||||
{
|
||||
std::vector<cv::Mat>camera_mat;
|
||||
while (runFlag)
|
||||
{
|
||||
getCameraImg(camera_mat);
|
||||
if (camera_mat.size() > 0)
|
||||
{
|
||||
for (auto img : camera_mat)
|
||||
imgQueue.enqueue(img);
|
||||
}
|
||||
QThread::msleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
void getCameraImg(std::vector<cv::Mat>& mats)
|
||||
{
|
||||
QByteArray task_name;
|
||||
if (!cameraModulePtr.module_ptr->sendData(mats, task_name))
|
||||
qCritical() << "[Error] " << " camera_mat is error! ";
|
||||
qDebug() << __FUNCTION__ << " line:" << __LINE__ << "camera_mat size:" << mats.size();
|
||||
}
|
||||
bool trigger()
|
||||
{
|
||||
if (!cameraModulePtr.module_ptr->run())
|
||||
{
|
||||
qCritical() << "[Error] " << " m_name:" << cameraName << " run failed!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void getImgQueueSize();
|
||||
private:
|
||||
cameraModule cameraModulePtr;
|
||||
QQueue<cv::Mat>imgQueue;
|
||||
|
||||
bool runFlag = true;
|
||||
};
|
||||
class cameraController
|
||||
{
|
||||
public:
|
||||
void init(backEndController*);
|
||||
~cameraController();
|
||||
std::unordered_map<QString, camera*>cameras;//key 相机名
|
||||
private:
|
||||
bool loadModule(QString keyName, QString moduleName, QByteArray initByte);
|
||||
backEndController* _backEndController;
|
||||
|
||||
std::vector<cameraModule>camerasVec;//用于初始化和销毁
|
||||
std::vector<cv::Mat> vec_mat;//没啥用,一直保持为空就好
|
||||
QList<QLibrary*> lib_list;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <FrontendBackendBridge.h>
|
||||
#include <mainwindow.h>
|
||||
#include<io.h>
|
||||
#include <algo.h>
|
||||
#include<cmath>
|
||||
#include<math.h>
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ bool taskThread::processTask()
|
||||
return true;
|
||||
}
|
||||
processExecData();
|
||||
Sleep(5);
|
||||
_sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <threadPoolController.h>
|
||||
#include <ReadBarcode.h>
|
||||
#include "camera_thread.h"
|
||||
#include "myiothread.h"
|
||||
#include <FrontendBackendBridge.h>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <qmutex.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algo2.h>
|
||||
#include <filesystem>
|
||||
#include <opencv.hpp>
|
||||
#include <string>
|
||||
|
||||
@@ -58,7 +58,6 @@ private:
|
||||
class triggerController : public QThread
|
||||
{
|
||||
public:
|
||||
backEndController* _backEndController;
|
||||
QString triggerFileName = QString("Hd_SocketModule_ModbusTcp");
|
||||
~triggerController()
|
||||
{
|
||||
@@ -124,6 +123,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
backEndController* _backEndController;
|
||||
triggerLockerT tLocker;//防止重复触发,每次收到数据时检查数据是否与上次相同,如果相同checkTrigger会返回false
|
||||
/// <summary>
|
||||
/// 检测QByteArray中某位置的值是否和输入一样,使用了绝对位置
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
#include <qcombobox.h>
|
||||
|
||||
static QTextEdit* globalQtTextEdit=nullptr;
|
||||
static QTextStream globalQtlogFile;
|
||||
static QTextStream globalStdlogFile;
|
||||
static QFile* qtLogFile;
|
||||
static QFile* stdLogFile;
|
||||
static QTextStream* globalQtlogFile = nullptr;
|
||||
static QTextStream* globalStdlogFile = nullptr;
|
||||
|
||||
static void MessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
|
||||
{
|
||||
@@ -40,12 +42,13 @@ static void MessageHandler(QtMsgType type, const QMessageLogContext& context, co
|
||||
break;
|
||||
}
|
||||
logStr.append(QString("%1%2:\n-->%3\n").arg(context.line).arg(context.function).arg(msg));
|
||||
QFile logFile(QString("./Log/%1QtLog.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd")));
|
||||
if (logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
|
||||
globalQtlogFile.setCodec("UTF-8");
|
||||
globalQtlogFile.setDevice(&logFile);
|
||||
globalQtlogFile << logStr << endl;
|
||||
}
|
||||
*globalQtlogFile << logStr << endl;
|
||||
//QFile logFile(QString("./Log/%1QtLog.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd")));
|
||||
//if (logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
|
||||
// globalQtlogFile.setCodec("UTF-8");
|
||||
// globalQtlogFile.setDevice(&logFile);
|
||||
// globalQtlogFile << logStr << endl;
|
||||
//}
|
||||
//if (globalQtTextEdit != nullptr) {
|
||||
// globalQtTextEdit->moveCursor(QTextCursor::End);
|
||||
// globalQtTextEdit->insertPlainText(logStr + "\n");
|
||||
@@ -76,12 +79,7 @@ protected:
|
||||
|
||||
QString logStr = (QDateTime::currentDateTime().toString(u8"(yyyy-MM-dd hh:mm:ss dddd)")).toUtf8();
|
||||
logStr.append(QString("-->%1\n").arg(text));
|
||||
QFile logFile(QString("./Log/%1StdLog.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd")));
|
||||
if (logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
|
||||
globalQtlogFile.setCodec("UTF-8");
|
||||
globalQtlogFile.setDevice(&logFile);
|
||||
globalQtlogFile << logStr << endl;
|
||||
}
|
||||
*globalStdlogFile << logStr << endl;
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -145,7 +143,6 @@ public:
|
||||
|
||||
Layout->addWidget(widgets);
|
||||
}
|
||||
|
||||
void addConfigWidget(QString btnText,QTextEdit* textWidget, logType type)
|
||||
{
|
||||
QPalette palette;
|
||||
@@ -201,10 +198,21 @@ public:
|
||||
if(type==stdConsle)
|
||||
{
|
||||
stdConsoleRedirector _stdConsoleRedirector(std::cout, textWidget);
|
||||
std::cout << "Test" << std::endl;
|
||||
stdLogFile = new QFile(QString("./Log/%1StdLog.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd")));
|
||||
if (stdLogFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
|
||||
globalStdlogFile = new QTextStream();
|
||||
globalStdlogFile->setCodec("UTF-8");
|
||||
globalStdlogFile->setDevice(stdLogFile);
|
||||
}
|
||||
}
|
||||
else if (type == qtConsle)
|
||||
{
|
||||
qtLogFile =new QFile(QString("./Log/%1QtLog.log").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd")));
|
||||
if (qtLogFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
|
||||
globalQtlogFile = new QTextStream();
|
||||
globalQtlogFile->setCodec("UTF-8");
|
||||
globalQtlogFile->setDevice(qtLogFile);
|
||||
}
|
||||
|
||||
globalQtTextEdit = textWidget;
|
||||
//globalQtTextEdit->setUpdatesEnabled(false);
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
{
|
||||
int time1 = startTimeEdit->time().hour() * 60 + startTimeEdit->time().minute();
|
||||
int time2 = endTimeEdit->time().hour() * 60 + startTimeEdit->time().minute();
|
||||
return { std::min(time1,time2),std::max(time1,time2) };
|
||||
return { min(time1,time2),max(time1,time2) };
|
||||
}
|
||||
|
||||
QTime getStartTime() const {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user