diff --git a/src/CameraControl.cpp b/src/CameraControl.cpp index fbfc3a2..c319cbc 100644 --- a/src/CameraControl.cpp +++ b/src/CameraControl.cpp @@ -46,6 +46,7 @@ bool CameraControl::readCameraConfig(QString filePath) { m_mapIdCameraInfoSide.clear(); m_mapIdCameraInfoTop.clear(); + exposureRowMap.clear(); m_mapSerialNumberIdSide.clear(); m_mapSerialNumberIdTop.clear(); @@ -119,6 +120,38 @@ bool CameraControl::readCameraConfig(QString filePath) qWarning() << "side id error"; return false; } + //根据文档读取,没有则采用默认值如下 + //现在1和2巷道都是用的下三层(1-3层)曝光值250000ms/增益20, + //中三层(4-6层)曝光值150000ms/增益20, + //上三层(7-9层)曝光值50000ms/增益20 + + QJsonObject exposureRowObj = jsonObj.value("exposureRowMap").toObject(); + if (!exposureRowObj.isEmpty()) + { + for each (QString key in exposureRowObj.keys()) { + + exposureRowMap[key.toInt()] = exposureRowObj.value(key).toInt(); + } + } + else + { + for (int floor = 1; floor <= 9; floor++) { + int exposure = 2500; + if (floor >= 1 && floor <= 3) + { + exposure = 250000; + } + else if (floor >= 7 && floor <= 9) + { + exposure = 50000; + } + else + { + exposure = 150000; + } + exposureRowMap[floor] = exposure; + } + } QJsonObject devicesObj = jsonObj.value("devices").toObject(); if (!devicesObj.isEmpty()) { @@ -178,6 +211,7 @@ bool CameraControl::readCameraConfig(QString filePath) } } } + return true; } @@ -261,6 +295,7 @@ bool CameraControl::loadCamera(const QList& cameraInfoList) else if (cameraType == CameraType::LXTof) { Camera* pLXCamera = new LXCamera(); + if (pLXCamera->initCamera(serialNumber)) { m_vecPCamera.push_back(pLXCamera); @@ -369,6 +404,7 @@ bool CameraControl::setSoftwareTrigger(const QStringList& serialNumberList) bool CameraControl::openCamera(const QString& serialNumber) { QMap::iterator iter = m_mapSNIndex.find(serialNumber); + qInfo() << "openCamera sid: " << serialNumber << " index:" << iter.value(); if (iter == m_mapSNIndex.end()) { qWarning() << "Do not find " << serialNumber; @@ -425,7 +461,10 @@ bool CameraControl::setSoftwareTrigger(const QString& serialNumber) int index = iter.value(); return m_vecPCamera[index]->setTriggerSource(SOFTWARE); } +int CameraControl::getDeviceId(const QString& serialNumber) { + return m_mapSerialNumberIdSide.value(serialNumber); +} bool CameraControl::setExposure(const QString& serialNumber, int exposure) { @@ -565,22 +604,8 @@ void CameraControl::capture(const QStringList& serialNumberList, int location, i //现在1和2巷道都是用的下三层(1-3层)曝光值250000ms/增益20, //中三层(4-6层)曝光值150000ms/增益20, //上三层(7-9层)曝光值50000ms/增益20 - int exposure = 0; - if (floor!=0) - { - if (floor >= 1 && floor <= 3) - { - exposure = 250000; - } - else if (floor >= 7 && floor <= 9) - { - exposure = 50000; - } - else - { - exposure = 150000; - } - } + int exposure = exposureRowMap[floor]; + setExposure(serialNumber, exposure); if (!capture(serialNumber, imgInfo.image, imgInfo.image3D, floor)) diff --git a/src/CameraControl.h b/src/CameraControl.h index 1865a66..0032a0b 100644 --- a/src/CameraControl.h +++ b/src/CameraControl.h @@ -65,6 +65,7 @@ public: bool stopCamera(const QString& serialNumber); bool setSoftwareTrigger(const QString& serialNumber); bool setExposure(const QString& serialNumber,int exposure); + int getDeviceId(const QString& serialNumber); Q_SLOT void onCapture(int cameraLocation,int location, int floor); @@ -78,7 +79,8 @@ private: bool capture(const QString& serialNumber, cv::Mat& img, cv::Mat& img3D,int exposure); void flipImg(const cv::Mat& imgSrc, cv::Mat& imgDst, int rotationAngle); - QMap m_mapIdCameraInfoTop; + QMap m_mapIdCameraInfoTop; + QMap exposureRowMap; QMap m_mapIdCameraInfoSide; QMap m_mapSerialNumberIdTop; QMap m_mapSerialNumberIdSide; // QString:相机SN码,int:相机ID diff --git a/src/CategoryMatcher.cpp b/src/CategoryMatcher.cpp index 0cce98a..d9d3ff9 100644 --- a/src/CategoryMatcher.cpp +++ b/src/CategoryMatcher.cpp @@ -147,14 +147,20 @@ bool CategoryMatcher::smokeMatch(const QString& typeNo, const ILImagePtr ilImgPt ILMatchResultsPtr matchResults, matchResultsF; + ILRotRectRegionPtr rectRoi(__uuidof(LRotRectRegion)); if (level == 1) // 大模板 { ILImageArithmPtr imgArithm(__uuidof(LImageArithm)); imgArithm->Resize(ilImgPtr, 0.5, 0.5, LPVInterNearest, img); + rectRoi->SetPlacement(800, 500, 500, 1250, 600); } + else { - LPVErrorCode err = m_ilmatch->Match((level == 1 ? img : ilImgPtr), nullptr, &matchResults); - LPVErrorCode errF = m_ilmatchF->Match((level == 1 ? img : ilImgPtr), nullptr, &matchResultsF); + rectRoi->SetPlacement(1600, 1000, 2500, 1200, 0); + } + qInfo() << "setrectRoi end"; + LPVErrorCode err = m_ilmatch->Match((level == 1 ? img : ilImgPtr), rectRoi, &matchResults); + LPVErrorCode errF = m_ilmatchF->Match((level == 1 ? img : ilImgPtr), rectRoi, &matchResultsF); if (err < LPVErrorCode::LPVNoError || errF < LPVErrorCode::LPVNoError) { str = QString("[%1]:Match Failed;templateImgPath = %2").arg(id).arg(templateImgPath); qDebug() << str; @@ -314,6 +320,11 @@ void CategoryMatcher::drawImage(ILImagePtr image, QMap re } } + ILRotRectRegionPtr m_rect(__uuidof(LRotRectRegion)); + m_rect->SetPlacement(1600, 1000, 2500, 1200, 0); + m_textSys->SetPenWidth(m_rect, 3); + m_textSys->SetPenColor(m_rect, m_textSys->GetColorRef(0, 255, 0)); + m_display->AddObject(m_rect, 0); if (bRlt) { m_textSys->SetFontColor(m_text, m_textSys->GetColorRef(0, 255, 0)); diff --git a/src/LXCamera.cpp b/src/LXCamera.cpp index c63adac..6867bbb 100644 --- a/src/LXCamera.cpp +++ b/src/LXCamera.cpp @@ -11,7 +11,7 @@ static char wait_key = '0'; -static DcHandle handle = 0; +QMap handleMap ; #define checkTC(state) {LX_STATE val=state; \ if(val != LX_SUCCESS){ \ if(val == LX_E_RECONNECTING){ \ @@ -42,6 +42,7 @@ bool LXCamera::initCamera(const QString& serialNumber) return false; } m_handle = serialNumber.toStdString(); + qInfo() << "Find tof device number = " << device_num; return true; } @@ -55,7 +56,10 @@ void LXCamera::destroyCamera() bool LXCamera::openCamera() { LxDeviceInfo device_info; - LX_STATE lx_state = DcOpenDevice(LX_OPEN_MODE::OPEN_BY_SN, m_handle.c_str(), &handle, &device_info); + DcHandle* handlePtr = new DcHandle(); + LX_STATE lx_state = DcOpenDevice(LX_OPEN_MODE::OPEN_BY_SN, m_handle.c_str(), handlePtr, &device_info); + handle = *handlePtr; + qInfo() << "openCamera3D handle:" << handle << "cameraSN:" << m_handle.c_str(); if (LX_SUCCESS != lx_state) { QString str = QString("open device failed, open_param: %1, err = %2").arg(m_handle.c_str()).arg(lx_state); qDebug() << str; @@ -123,6 +127,8 @@ bool LXCamera::setGain(double gain) bool LXCamera::takeAPic(cv::Mat& imgMat, cv::Mat&imgMat3D) { + + qInfo() << "getPicCamera3D handle:" << handle << "cameraSN:" << m_handle.c_str(); //更新数据 auto ret = DcSetCmd(handle, LX_CMD_GET_NEW_FRAME); if (LX_SUCCESS != ret) diff --git a/src/LXCamera.h b/src/LXCamera.h index 3c0980d..5e72ad2 100644 --- a/src/LXCamera.h +++ b/src/LXCamera.h @@ -1,5 +1,9 @@ #pragma once +#include "lxCamera/lx_camera_api.h" + +#pragma comment(lib,"LxCameraApi.lib") + #include "camera.h" #include "commonDefine.h" @@ -27,4 +31,6 @@ public: private: CameraType m_type = CameraType::LXTof; std::string m_handle; + + DcHandle handle = 0; }; diff --git a/src/SmokeBoxIdentification.cpp b/src/SmokeBoxIdentification.cpp index 0b95c6a..5158a59 100644 --- a/src/SmokeBoxIdentification.cpp +++ b/src/SmokeBoxIdentification.cpp @@ -460,6 +460,7 @@ void SmokeBoxIdentification::calculate(int stocketID) bool bIsMatch = false; for each (const ImageInfo& imgInfo in vecImageInfo) { + QString pclPath = dataSaveFolder; if (imgInfo.bIs2D && !bIsMatch) { QString str = QString("[%1]:Camera %2 Match Start ...").arg(stocket.id).arg(imgInfo.cameraSn); @@ -467,6 +468,7 @@ void SmokeBoxIdentification::calculate(int stocketID) if (!imgInfo.imageFixed->Void()) { + //进行计算品规 if (m_pCategoryMatcher->smokeMatch(typeNum, imgInfo.imageFixed, stocket.id.toInt())) { str = QString("[%1]:Camera %2 Match successful!").arg(stocket.id).arg(imgInfo.cameraSn); @@ -501,6 +503,8 @@ void SmokeBoxIdentification::calculate(int stocketID) } else { + + if (bIsMatch) { QString str = QString("[%1]:3DCamera %2 Start Calculate...").arg(stocket.id).arg(imgInfo.cameraSn); @@ -508,12 +512,10 @@ void SmokeBoxIdentification::calculate(int stocketID) FileInfo fileInfo = imgInfo.saveImgInfo; //根据相机编号,对应找到3D基准文件去计算层高 - QString pclPath = dataSaveFolder; pclPath.append(QString("*.pcd").arg(fileInfo.strId)); QDir dir(pclPath); QFileInfoList fileList = dir.entryInfoList(QStringList() << "*.pcd", QDir::Files | QDir::NoDotAndDotDot); - m_stocketList[stocketID].pcdSrc = pclPath; if (fileList.length() > 0) { pclPath = fileList[0].absolutePath(); @@ -524,6 +526,7 @@ void SmokeBoxIdentification::calculate(int stocketID) int lastPos = pclPath.lastIndexOf('.'); QString depthImagePath = pclPath.left(lastPos); + depthImagePath.append(".PNG"); m_stocketList[stocketID].imagesPathList.append(depthImagePath.right(depthImagePath.length() - 1)); } @@ -544,19 +547,23 @@ void SmokeBoxIdentification::calculate(int stocketID) m_pHeightCalculate->LoadBasicFile(QString{}); //数量计算 - m_stocketList[stocketID].smokeQuantityRlt = QString::number(m_pHeightCalculate->SmokeHeight()); + m_stocketList[stocketID].smokeQuantityRlt = m_stocketList[stocketID].smokeQuantity; //QFile::copy("C:\\Users\\LENOVO\\Downloads\\30t.pcd",pclPath); QFile::rename(".\\Cache\\1.pcd", pclPath); - } else { + CameraControl* cameraCon = CameraControl::instance(); + m_stocketList[stocketID].pcdSrc = pclPath.replace(".", "").append("\\").append(QString::number((cameraCon->getDeviceId(imgInfo.cameraSn)))).append(".pcd"); + qDebug() << "pcdSrc:" << m_stocketList[stocketID].pcdSrc; QString str = QString("[%1]:Pre 2D Camera don't Match. Now Camera %2.").arg(stocket.id).arg(imgInfo.cameraSn); qDebug() << str; } } + + } diff --git a/src/common/log.cpp b/src/common/log.cpp index a8c9c66..47282b3 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -5,7 +5,7 @@ QString LogInfo::m_currtDate = QString(); QString LogInfo::m_folderPath = QString(); QFile* LogInfo::m_fileLog = NULL; -char* LogInfo::msgHead[] = { + const char* LogInfo::msgHead[] = { "Debug ", "Warning ", "Critical", diff --git a/src/common/log.h b/src/common/log.h index 927cd6f..aabfd86 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -20,7 +20,7 @@ private: static QString m_currtDate; static QString m_folderPath; static QFile* m_fileLog; - static char* msgHead[]; + static const char* msgHead[]; }; #endif // LOG_H \ No newline at end of file