|
|
#pragma execution_character_set("utf-8")
|
|
|
#include "SmokeBoxIdentification.h"
|
|
|
|
|
|
SmokeBoxIdentification::SmokeBoxIdentification(QWidget *parent)
|
|
|
: QMainWindow(parent)
|
|
|
{
|
|
|
qRegisterMetaType<QVector<ImageInfo> >("QVector<ImageInfo>");
|
|
|
qRegisterMetaType<QMap<QString, int> >("QMap<QString,int>");
|
|
|
qRegisterMetaType<QMap<QString, int> >("QMap<QString,int>");
|
|
|
ui.setupUi(this);
|
|
|
this->setWindowTitle(tr("ÑÌÏä¼ì²âϵͳ"));
|
|
|
//m_pShowRltImgLabel = ui.label_showImg;
|
|
|
|
|
|
moduleLoading();
|
|
|
|
|
|
//connect(this, &SmokeBoxIdentification::sgCapture, CameraControl::instance(), &CameraControl::onCapture);
|
|
|
//connect(CameraControl::instance(), &CameraControl::sgCapturedImage, this, &SmokeBoxIdentification::onCapturedImage);
|
|
|
|
|
|
QString applicationDirPath = QCoreApplication::applicationDirPath();
|
|
|
QtConcurrent::run([=]()
|
|
|
{
|
|
|
//if (decodeSmokeInfoCsv(applicationDirPath + SMOKEINFO_XLSX_CONFIG))
|
|
|
// matchSmokeNameAndTemplateFolderName(applicationDirPath + NUM_TEMPLATE_PATH);
|
|
|
m_pDataProcess = std::make_shared<dataPreProcessing>();
|
|
|
|
|
|
if (m_pDataProcess)
|
|
|
{
|
|
|
//dataPreProcessing * t = (dataPreProcessing*)m_pDataProcess.get();
|
|
|
m_pDataProcess->getFileDir(applicationDirPath + NUM_TEMPLATE_PATH);
|
|
|
m_pDataProcess->transmitFilePathForSampleWithItsCorresLabel();
|
|
|
m_pDataProcess->setWinSize(170);
|
|
|
//ADModule::instance()->setDataProcessObj(m_pDataProcess);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
m_pNumTemplateBuild = new QNumTemplateBuild();
|
|
|
if (m_pDataProcess)
|
|
|
{
|
|
|
m_pNumTemplateBuild->setDataProcessObj(m_pDataProcess);
|
|
|
}
|
|
|
QString filePath = applicationDirPath + NET_CONFIG;
|
|
|
m_pNetControl = new NetControl(filePath, true, this);
|
|
|
m_pTcpClientThread = new QThread();
|
|
|
m_pNetControl->moveToThread(m_pTcpClientThread);
|
|
|
connect(m_pTcpClientThread, &QThread::started,
|
|
|
m_pNetControl, &NetControl::onInitNet);
|
|
|
connect(m_pTcpClientThread, &QThread::finished,
|
|
|
this, &QObject::deleteLater);
|
|
|
m_pTcpClientThread->start();
|
|
|
connect(m_pNetControl, &NetControl::sgReceiveData, this, &SmokeBoxIdentification::onDecodeMsg, Qt::QueuedConnection);
|
|
|
connect(this, &SmokeBoxIdentification::sgSendMsg, m_pNetControl, &NetControl::onSendMsg, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
if (m_moduleParam.CodeScan != 0)
|
|
|
{
|
|
|
QString codeFilePath = applicationDirPath + COM_CONFIG;
|
|
|
CodeScanStation::instance()->loadParameters(filePath);
|
|
|
CodeScanStation::instance()->openComs();
|
|
|
}
|
|
|
|
|
|
if (m_moduleParam.Sensor != 0)
|
|
|
{
|
|
|
ADModule::instance()->loadParameters(filePath);
|
|
|
filePath = applicationDirPath + COM_CONFIG;
|
|
|
lpSerialStation::instance()->loadParameters(filePath);
|
|
|
lpSerialStation::instance()->openComs();
|
|
|
|
|
|
connect(lpSerialStation::instance(), &lpSerialStation::sgMonitorSensorTriggerStart, this
|
|
|
, &SmokeBoxIdentification::onMonitorSensorTriggerStart);
|
|
|
connect(lpSerialStation::instance(), &lpSerialStation::sgMonitorSensorTriggerStop, this
|
|
|
, &SmokeBoxIdentification::onMonitorSensorTriggerStop);
|
|
|
connect(lpSerialStation::instance(), &lpSerialStation::sgNewEmptyCheckResults, this
|
|
|
, &SmokeBoxIdentification::onSendEmptyCheckResults);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_pCategoryMatcher = new CategoryMatcher();
|
|
|
m_pHeightCalculate = new HeightCalculate();
|
|
|
|
|
|
|
|
|
connect(CodeScanStation::instance(), &CodeScanStation::sgNewCodeScanData, lpSerialStation::instance()
|
|
|
, &lpSerialStation::onNewCodeScanResults);
|
|
|
connect(this, &SmokeBoxIdentification::sgCategoryMatchFinished, this, &SmokeBoxIdentification::onNumStatistic);
|
|
|
|
|
|
|
|
|
connect(this, &SmokeBoxIdentification::sgCapture, CameraControl::instance(), &CameraControl::onCapture);
|
|
|
connect(CameraControl::instance(), &CameraControl::sgCapturedImage, this, &SmokeBoxIdentification::onCapturedImage);
|
|
|
|
|
|
|
|
|
connect(this, &SmokeBoxIdentification::sgControlSideLight, lpSerialStation::instance()
|
|
|
, &lpSerialStation::onControlSideLight);
|
|
|
connect(this, &SmokeBoxIdentification::sgStartEmptyPlaceCheck, lpSerialStation::instance()
|
|
|
, &lpSerialStation::onStartEmptyPlaceCheck);
|
|
|
connect(this, &SmokeBoxIdentification::sgStopEmptyPlaceCheck, lpSerialStation::instance()
|
|
|
, &lpSerialStation::onStopEmptyPlaceCheck);
|
|
|
connect(this, &SmokeBoxIdentification::sgNumDataCollectStart, ADModule::instance()
|
|
|
, &ADModule::onDataRequestStart);
|
|
|
connect(this, &SmokeBoxIdentification::sgNumDataCollectStop, ADModule::instance()
|
|
|
, &ADModule::onDataRequestStop);
|
|
|
connect(ADModule::instance(), &ADModule::sgNewNumData, this, &SmokeBoxIdentification::onNewNumData);
|
|
|
//connect(this, &SmokeBoxIdentification::sgSendData2AndAlgo, ADModule::instance(), &ADModule::onSendData2Algo);
|
|
|
//connect(this, &SmokeBoxIdentification::sgSaveSensorData2Local, ADModule::instance(), &ADModule::onSaveData2File);
|
|
|
//connect(this, &SmokeBoxIdentification::sgSendResults, this, &SmokeBoxIdentification::onSendResults);
|
|
|
connect(ui.action_templateNum, SIGNAL(triggered()), this, SLOT(onActionClicked()));
|
|
|
emit sgControlSideLight(lightCtrl::emTurnOnLight);
|
|
|
}
|
|
|
|
|
|
SmokeBoxIdentification::~SmokeBoxIdentification()
|
|
|
{
|
|
|
//emit sgControlSideLight(lightCtrl::emTurnOffLight);
|
|
|
DELETE_POINTER(m_pCategoryMatcher);
|
|
|
DELETE_POINTER(m_pHeightCalculate);
|
|
|
DELETE_POINTER(m_pNetControl);
|
|
|
if (m_pTcpClientThread)
|
|
|
{
|
|
|
m_pTcpClientThread->quit();
|
|
|
m_pTcpClientThread->wait();
|
|
|
m_pTcpClientThread = nullptr;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onActionClicked()
|
|
|
{
|
|
|
QString strObj = sender()->objectName();
|
|
|
if (strObj == "action_templateNum")
|
|
|
{
|
|
|
m_pNumTemplateBuild->setParent(this);
|
|
|
m_pNumTemplateBuild->setWindowTitle(tr("½¨Á¢ÊýÁ¿Ä£°å"));
|
|
|
m_pNumTemplateBuild->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
m_pNumTemplateBuild->setWindowModality(Qt::ApplicationModal);
|
|
|
m_pNumTemplateBuild->setAttribute(Qt::WA_ShowModal, true);
|
|
|
m_pNumTemplateBuild->show();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::captureTop(int cameraID, int floor)
|
|
|
{
|
|
|
emit sgCapture(eCameraLocation::emTop, cameraID, floor);
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::captureSide(int cameraID, int floor)
|
|
|
{
|
|
|
emit sgCapture(eCameraLocation::emSide, cameraID, floor);
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::saveImage(const cv::Mat& imgMat, const QString& filePath)
|
|
|
{
|
|
|
if (imgMat.empty())
|
|
|
{
|
|
|
qWarning() << "Image is empty";
|
|
|
return;
|
|
|
}
|
|
|
cv::imwrite(filePath.toStdString(), imgMat);
|
|
|
qDebug() << "Save image: " << filePath;
|
|
|
}
|
|
|
|
|
|
QString SmokeBoxIdentification::saveImage(ILImagePtr image, const cv::Mat& imgMat3D, const QString& filePath)
|
|
|
{
|
|
|
if (image->Void())
|
|
|
{
|
|
|
qWarning() << "Image is empty";
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
std::wstring path = filePath.toStdWString();
|
|
|
if (!imgMat3D.empty())// 3DÏà»úÊý¾Ý
|
|
|
{
|
|
|
cv::imwrite(filePath.toStdString(), imgMat3D);
|
|
|
int lastPos = filePath.lastIndexOf('.');
|
|
|
QString prePath = filePath.left(lastPos);
|
|
|
QString pclPath = prePath + ".pcd";
|
|
|
if (QFile(pclPath).exists())
|
|
|
{
|
|
|
QFile::remove(pclPath);
|
|
|
}
|
|
|
|
|
|
|
|
|
//QFile::copy("C:\\Users\\LENOVO\\Downloads\\30t.pcd",pclPath);
|
|
|
QFile::rename(".\\Cache\\1.pcd", pclPath);
|
|
|
|
|
|
qDebug() << "Save 3D image: " << pclPath;
|
|
|
return prePath + ".PNG";
|
|
|
|
|
|
}
|
|
|
else // 2DÏà»úÊý¾Ý
|
|
|
{
|
|
|
image->Save(path.c_str(), nullptr);
|
|
|
qDebug() << "Save 2D image: " << filePath;
|
|
|
return filePath;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::saveImage(const QVector<ImageInfo>& vecImageInfo, int workMode)
|
|
|
{
|
|
|
QString dataSaveFolderPath;
|
|
|
|
|
|
#if IMAGEDRAWING==LPV
|
|
|
if (m_currtIntoStockInfo.taskNum == "0")
|
|
|
{
|
|
|
dataSaveFolderPath = QString("%1\\%2\\%3\\%4").arg(FILE_INPUTSTORE_PATH)
|
|
|
.arg(m_currtIntoStockInfo.streetName).arg(m_currtIntoStockInfo.Floor).arg(m_currtIntoStockInfo.row);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dataSaveFolderPath = QString("%1\\%2\\%3").arg(FILE_STORAGE_PATH)/*.arg(ORIGIN_IMAGE_FOLDER)*/
|
|
|
.arg(m_currtIntoStockInfo.taskNum).arg(m_currtIntoStockInfo.id);
|
|
|
}
|
|
|
|
|
|
|
|
|
#elif IMAGEDRAWING==OPENCV
|
|
|
switch (workMode)
|
|
|
{
|
|
|
case WorkMode::StockCheck:
|
|
|
dataSaveFolderPath = QString("%1\\%2\\%3").arg(FILE_STORAGE_PATH).arg(m_currtStockCheckInfo.stockNum)
|
|
|
.arg(m_currtStockCheckInfo.taskNum);
|
|
|
break;
|
|
|
case WorkMode::IntoStock:
|
|
|
dataSaveFolderPath = QString("%1\\%2\\%3\\%4").arg(FILE_STORAGE_PATH).arg(INTOSTOCK_IMAGE_FOLDER)
|
|
|
.arg(m_currtIntoStockInfo.stockNum).arg(m_currtIntoStockInfo.taskNum);
|
|
|
break;
|
|
|
default:
|
|
|
qDebug() << "Mode: " << workMode << "do not save Image";
|
|
|
return;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
QDir folder(dataSaveFolderPath);
|
|
|
if (!folder.exists())
|
|
|
{
|
|
|
QDir dir;
|
|
|
if (dir.mkpath(dataSaveFolderPath))
|
|
|
{
|
|
|
qDebug() << "Create folder: " << dataSaveFolderPath << " successfully.";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
qDebug() << "Create folder:" << dataSaveFolderPath << " failed.";
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
for (int i = 0; i < vecImageInfo.size(); ++i)
|
|
|
{
|
|
|
FileInfo fileInfo = vecImageInfo.at(i).saveImgInfo;
|
|
|
|
|
|
#if IMAGEDRAWING == LPV
|
|
|
QString filePath = QString("%1\\%2").arg(dataSaveFolderPath).arg(fileInfo.name);
|
|
|
QString imgPath = saveImage(vecImageInfo.at(i).imageOrigin, vecImageInfo.at(i).image3D, filePath);
|
|
|
m_currtIntoStockInfo.correctness = 1;
|
|
|
if (!vecImageInfo.at(i).image3D.empty())
|
|
|
{
|
|
|
m_currtIntoStockInfo.imagesPathList.push_back(imgPath);
|
|
|
}
|
|
|
|
|
|
#elif IMAGEDRAWING == OPENCV
|
|
|
if (workMode == WorkMode::IntoStock)
|
|
|
{
|
|
|
QString filePathSend = QString("%1/%2/%3/%4").arg(INTOSTOCK_IMAGE_FOLDER)
|
|
|
.arg(m_currtIntoStockInfo.stockNum).arg(m_currtIntoStockInfo.taskNum).arg(fileInfo.name);
|
|
|
m_currtIntoStockInfo.imagesPathList.push_back(filePathSend);
|
|
|
}
|
|
|
|
|
|
saveImage(vecImageInfo.at(i).image, filePath);
|
|
|
#endif
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onCapturedImage(const QVector<ImageInfo>& vecImageInfo, int cameraLocation)
|
|
|
{
|
|
|
if (vecImageInfo.length() <= 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
QString serialNumber = vecImageInfo.last().cameraSn;
|
|
|
if (cameraLocation == eCameraLocation::emTop)
|
|
|
{
|
|
|
qDebug() << "top captured";
|
|
|
QtConcurrent::run([=] {
|
|
|
saveImage(vecImageInfo, m_workMode);
|
|
|
if (m_workMode == WorkMode::StockCheck)
|
|
|
{
|
|
|
sendResults(MsgType::DataCollectionEndSC);
|
|
|
}
|
|
|
else if (m_workMode == WorkMode::IntoStock)
|
|
|
{
|
|
|
sendResults(MsgType::IntoStockResult);
|
|
|
}
|
|
|
m_workMode = WorkMode::Idle;
|
|
|
});
|
|
|
}
|
|
|
else if (cameraLocation == eCameraLocation::emSide)
|
|
|
{
|
|
|
qDebug() << "[Camera{" << m_currtIntoStockInfo.stockLocation << "}]: Captured.";
|
|
|
saveImage(vecImageInfo, m_workMode);
|
|
|
|
|
|
m_imageList.insert(m_currtIntoStockInfo.id.toInt(), vecImageInfo);
|
|
|
sendResults(MsgType::IntoStockResult);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onDecodeMsg(const QString& msg)
|
|
|
{
|
|
|
QString msgContent = msg;
|
|
|
if (msgContent.right(1) == END_SYMBOL)
|
|
|
{
|
|
|
msgContent.chop(1);
|
|
|
}
|
|
|
qDebug() << "msg: " << msg << " content: " << msgContent;
|
|
|
|
|
|
switch (m_moduleParam.COMMRules)
|
|
|
{
|
|
|
case eCommunicationRules::emNJ:
|
|
|
{
|
|
|
QStringList strList = msgContent.split(SPLIT_RULE);
|
|
|
qDebug() << "strlist length: " << strList.length() << " head: " << strList.at(0);
|
|
|
|
|
|
if (strList[0] == EMPTY_CHECK_HEAD)
|
|
|
{
|
|
|
if (strList.length() == 4)
|
|
|
{
|
|
|
EmptyCheckInfo emptyCheckInfo;
|
|
|
emptyCheckInfo.streetName = strList[1];
|
|
|
emptyCheckInfo.taskNum = strList[2];
|
|
|
m_currtEmptyCheckInfo = emptyCheckInfo;
|
|
|
if (strList[3] == "START")
|
|
|
{
|
|
|
m_workMode = WorkMode::EmptyCheck;
|
|
|
emit sgStartEmptyPlaceCheck(m_currtEmptyCheckInfo.streetName);
|
|
|
}
|
|
|
else if (strList[3] == "END")
|
|
|
{
|
|
|
if (m_workMode == WorkMode::EmptyCheck)
|
|
|
{
|
|
|
emit sgStopEmptyPlaceCheck();
|
|
|
m_workMode = WorkMode::Idle;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (strList.at(0) == STOCK_CHECK_HEAD)
|
|
|
{
|
|
|
if (strList.length() == 7)
|
|
|
{
|
|
|
qDebug() << "¿ªÊ¼»õλÅ̵ã";
|
|
|
m_workMode = WorkMode::StockCheck;
|
|
|
StockCheckInfo stockCheckInfo;
|
|
|
stockCheckInfo.streetName = strList.at(1);
|
|
|
stockCheckInfo.stockNum = strList.at(2);
|
|
|
stockCheckInfo.taskNum = strList.at(3);
|
|
|
stockCheckInfo.smokeTypeNum = strList.at(4);
|
|
|
stockCheckInfo.smokeQuantity = strList.at(5);
|
|
|
m_currtStockCheckInfo = stockCheckInfo;
|
|
|
}
|
|
|
else if (strList.length() == 3)
|
|
|
{
|
|
|
qDebug() << "È¡»õµ½Î»";
|
|
|
QString taskNum = strList.at(2);
|
|
|
QString currentTaskNum = m_currtStockCheckInfo.taskNum;
|
|
|
if (m_workMode == WorkMode::StockCheck)
|
|
|
{
|
|
|
captureSide(1,0);
|
|
|
captureTop(1,0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else if (strList.at(0) == INTO_STOCK_HEAD)
|
|
|
{
|
|
|
if (strList.length() == 4)
|
|
|
{
|
|
|
qDebug() << "Èë¿â¶¥²¿ÅÄÕÕ";
|
|
|
m_workMode = WorkMode::IntoStock;
|
|
|
IntoStockInfo intoStockInfo;
|
|
|
intoStockInfo.streetName = strList.at(1);
|
|
|
intoStockInfo.taskNum = strList.at(2);
|
|
|
intoStockInfo.stockNum = strList.at(3);
|
|
|
m_currtIntoStockInfo = intoStockInfo;
|
|
|
captureTop(1,0);
|
|
|
}
|
|
|
}
|
|
|
else if (strList.at(0) == LIGHT_CONTROL_HEAD)
|
|
|
{
|
|
|
if (strList.length() == 3)
|
|
|
{
|
|
|
qDebug() << "¿ª¹ØµÆ";
|
|
|
if (strList.at(2) == "0")
|
|
|
{
|
|
|
emit sgControlSideLight(lightCtrl::emTurnOffLight);
|
|
|
}
|
|
|
else if (strList.at(2) == "1")
|
|
|
{
|
|
|
emit sgControlSideLight(lightCtrl::emTurnOnLight);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case eCommunicationRules::emSJZ:
|
|
|
{
|
|
|
QStringList msgList = msgContent.split(END_SYMBOL);
|
|
|
for (int i = 0; i < msgList.length(); i++)
|
|
|
{
|
|
|
QStringList strList = msgList[i].split(SPLIT_RULE);
|
|
|
qDebug() << "strlist length: " << strList.length() << " head: " << strList.at(0);
|
|
|
if (strList.at(0) == START_CAPTURE && strList.length() == 7)
|
|
|
{
|
|
|
|
|
|
//m_workMode = WorkMode::Capture;
|
|
|
m_currtIntoStockInfo.taskNum = strList.at(3);
|
|
|
if (m_currtIntoStockInfo.taskNum == "0")
|
|
|
{
|
|
|
qDebug() << "Èë¿âȡͼ¿ªÊ¼";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
qDebug() << "µ½Î»È¡Í¼¿ªÊ¼";
|
|
|
}
|
|
|
|
|
|
QStringList streetInfo = strList.at(1).split("/");
|
|
|
m_currtIntoStockInfo.streetName = streetInfo.at(0);
|
|
|
m_currtIntoStockInfo.Floor = streetInfo.at(1).toInt();
|
|
|
m_currtIntoStockInfo.row = streetInfo.at(2).toInt();
|
|
|
|
|
|
m_currtIntoStockInfo.id = strList.at(2);
|
|
|
m_currtIntoStockInfo.stockLocation = strList.at(4);
|
|
|
m_currtIntoStockInfo.smokeTypeNum = strList.at(5);
|
|
|
m_currtIntoStockInfo.smokeQuantity = strList.at(6);
|
|
|
m_currtIntoStockInfo.imagesPathList.clear();
|
|
|
captureSide(m_currtIntoStockInfo.stockLocation.toInt(),m_currtIntoStockInfo.Floor);
|
|
|
}
|
|
|
else if (strList.at(0) == START_CALCULATE && strList.length() == 7)
|
|
|
{
|
|
|
qDebug() << "Æ·¹æ¼ÆÊý¿ªÊ¼";
|
|
|
//m_workMode = WorkMode::StockCheck;
|
|
|
QStringList streetInfo = strList.at(1).split("/");
|
|
|
m_currtStockCheckInfo.streetName = streetInfo.at(0);
|
|
|
m_currtStockCheckInfo.Floor = streetInfo.at(1).toInt();
|
|
|
m_currtStockCheckInfo.row = streetInfo.at(2).toInt();
|
|
|
|
|
|
m_currtStockCheckInfo.id = strList.at(2);
|
|
|
m_currtStockCheckInfo.taskNum = strList.at(3);
|
|
|
m_currtStockCheckInfo.stockLocation = strList.at(4);
|
|
|
m_currtStockCheckInfo.smokeTypeNum = strList.at(5);
|
|
|
m_currtStockCheckInfo.smokeQuantity = strList.at(6);
|
|
|
m_currtStockCheckInfo.imagesPathList.clear();
|
|
|
m_stocketList.insert(m_currtStockCheckInfo.id.toInt(), m_currtStockCheckInfo);
|
|
|
calculate(m_currtStockCheckInfo.id.toInt());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::calculate(int stocketID)
|
|
|
{
|
|
|
QtConcurrent::run([=] {
|
|
|
|
|
|
bool bRlt = false;
|
|
|
bool bRlt3D = false;
|
|
|
StockCheckInfo stocket = m_stocketList.value(stocketID);
|
|
|
if (!m_stocketList.contains(stocketID))
|
|
|
{
|
|
|
qCritical() << "Don't Save stocketID[" << stocketID << "] Message!";
|
|
|
return;
|
|
|
}
|
|
|
QString typeNum = stocket.smokeTypeNum;
|
|
|
cv::Mat imgRltMat;
|
|
|
|
|
|
QString dataSaveFolder = QString("%1\\%2\\%3").arg(FILE_STORAGE_PATH)
|
|
|
.arg(stocket.taskNum).arg(stocket.id);
|
|
|
|
|
|
|
|
|
QVector<ImageInfo> vecImageInfo = m_imageList.value(stocket.id.toInt());
|
|
|
|
|
|
// ÓÉÓÚ֮ǰÊǶà¸öÏà»úÅÄÒ»¸ö¿â£¬Èôǰһ¸öÏà»úµÄͼÏñΪOK£¬Ôò²»ÔËÐÐÏÂÒ»¸ö
|
|
|
|
|
|
bool bIsMatch = false;
|
|
|
for each (const ImageInfo& imgInfo in vecImageInfo)
|
|
|
{
|
|
|
|
|
|
if (imgInfo.bIs2D && !bIsMatch)
|
|
|
{
|
|
|
QString str = QString("[%1]:Camera %2 Match Start ...").arg(stocket.id).arg(imgInfo.cameraSn);
|
|
|
qDebug() << str;
|
|
|
|
|
|
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);
|
|
|
qDebug() << str;
|
|
|
bRlt = true;
|
|
|
m_stocketList[stocketID].smokeTypeNumRlt = typeNum;
|
|
|
FileInfo fileInfo = imgInfo.saveImgInfo;
|
|
|
QString fileName = QString("%1_%2_rlt%3").arg(fileInfo.strId)
|
|
|
.arg(m_currtStockCheckInfo.smokeTypeNum).arg(".jpg");
|
|
|
QString filePath = QString("%1\\%2").arg(dataSaveFolder).arg(fileName);
|
|
|
m_pCategoryMatcher->saveResultsImage(filePath);
|
|
|
|
|
|
bIsMatch = true;
|
|
|
m_stocketList[stocketID].imagesPathList.append(filePath.right(filePath.length() - 1));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = QString("[%1]:Camera %2 Match Failed!").arg(stocket.id).arg(imgInfo.cameraSn);
|
|
|
qWarning() << str;
|
|
|
QString filePath = dataSaveFolder + QString("\\%1_error.jpg")
|
|
|
.arg(stocket.smokeTypeNum);
|
|
|
m_pCategoryMatcher->saveResultsImage(filePath);
|
|
|
m_stocketList[stocketID].imagesPathList.append(filePath.right(filePath.length() - 1));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = QString("[%1]:imgInfo.image is Empty!").arg(stocket.id);
|
|
|
qDebug() << str;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
|
|
|
if (bIsMatch)
|
|
|
{
|
|
|
QString str = QString("[%1]:3DCamera %2 Start Calculate...").arg(stocket.id).arg(imgInfo.cameraSn);
|
|
|
qDebug() << str;
|
|
|
|
|
|
FileInfo fileInfo = imgInfo.saveImgInfo;
|
|
|
//¸ù¾ÝÏà»ú±àºÅ£¬¶ÔÓ¦ÕÒµ½3D»ù×¼ÎļþÈ¥¼ÆËã²ã¸ß
|
|
|
|
|
|
int lastPos = fileInfo.name.lastIndexOf('.');
|
|
|
QString pcdName = fileInfo.name.left(lastPos);
|
|
|
pcdName.append(".pcd");
|
|
|
|
|
|
|
|
|
QString storeDir = QString("%1\\%2\\%3\\%4").arg(FILE_INPUTSTORE_PATH)
|
|
|
.arg(m_currtIntoStockInfo.streetName).arg(m_currtIntoStockInfo.Floor).arg(m_currtIntoStockInfo.row);
|
|
|
|
|
|
QString pcdPath = dataSaveFolder + "\\" + pcdName;
|
|
|
QString pcdPath2 = storeDir + "\\" + pcdName;
|
|
|
|
|
|
|
|
|
QString pcdDeepPath = dataSaveFolder + "\\" + fileInfo.name;
|
|
|
QString pcdDeepPath2 = storeDir + "\\" + fileInfo.name;
|
|
|
if (QFile(pcdDeepPath).exists())
|
|
|
{
|
|
|
m_stocketList[stocketID].imagesPathList.append(pcdDeepPath);
|
|
|
}
|
|
|
|
|
|
|
|
|
QFile pcdFile(pcdPath);
|
|
|
QFile pcdFile2(pcdPath);
|
|
|
if (pcdFile.exists())
|
|
|
{
|
|
|
m_stocketList[stocketID].pcdSrc = pcdPath;
|
|
|
}
|
|
|
|
|
|
if (pcdFile.exists() && pcdFile2.exists())
|
|
|
{
|
|
|
//ÓÉÓÚ¸ßÅàËã·¨ÄÚÒªÇó´«Èë¾ø¶ÔµØÖ·£¬µ«ÊÇͨѶÄÚ֮ǰ´«µÄ¶¼ÊÇÏà¶Ô·¾¶£¬¹Ê¶øÔÚ´«Èëǰ£¬½«Ïà¶Ô·¾¶¸Ä³É¾ø¶Ô·¾¶¡£
|
|
|
|
|
|
QString absolutePclPath = QCoreApplication::applicationDirPath()
|
|
|
+ QString("%1\\%2\\%3\\%4").arg("\\fileData").arg(stocket.taskNum).arg(stocket.id).arg(pcdName);
|
|
|
|
|
|
QString absolutePclPath2 = QCoreApplication::applicationDirPath()
|
|
|
+ QString("%1\\%2\\%3\\%4\\%5").arg("\\storeData").arg(m_currtIntoStockInfo.streetName)
|
|
|
.arg(m_currtIntoStockInfo.Floor).arg(m_currtIntoStockInfo.row).arg(pcdName);
|
|
|
|
|
|
|
|
|
str = QString("[%1]:3DCamera %2 -- PointCould = %3; Store PointCloud = %4").arg(stocket.id)
|
|
|
.arg(imgInfo.cameraSn).arg(absolutePclPath).arg(absolutePclPath2);
|
|
|
qInfo() << str;
|
|
|
|
|
|
//Èë¿âʱµÄµãÔÆµØÖ·£º.\\storeData\\ÏïµÀºÅ\\²ã¸ß\\ÁÐÊý\\*.pcd
|
|
|
// FILE_INPUTSTORE_PATH \\ m_stocketList[stocketID].streetName\\m_stocketList[stocketID].Floor\\m_stocketList[stocketID].row\\ *.pcd;
|
|
|
|
|
|
QString jsonPath = QCoreApplication::applicationDirPath();
|
|
|
|
|
|
if (imgInfo.saveImgInfo.location == 1)
|
|
|
{
|
|
|
jsonPath.append("\\config\\1_param3d.json");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
jsonPath.append("\\config\\2_param3d.json");
|
|
|
}
|
|
|
|
|
|
try
|
|
|
{
|
|
|
bRlt3D = compare(absolutePclPath2.toStdString(), absolutePclPath.toStdString(), jsonPath.toStdString());
|
|
|
str = QString("[%1]:3DCamera %2 -- 3D compare Result = %3").arg(stocket.id)
|
|
|
.arg(imgInfo.cameraSn).arg(QString::number(bRlt3D));
|
|
|
qInfo() << str;
|
|
|
}
|
|
|
catch (const std::exception& e)
|
|
|
{
|
|
|
qWarning() << e.what();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (pcdFile.exists())
|
|
|
{
|
|
|
str = QString("[%1]:3DCamera %2 -- PointCould[%3] can't Find!").arg(stocket.id)
|
|
|
.arg(imgInfo.cameraSn).arg(pcdPath2);
|
|
|
}
|
|
|
else if(pcdFile2.exists())
|
|
|
{
|
|
|
str = QString("[%1]:3DCamera %2 -- PointCould[%3] can't Find!").arg(stocket.id)
|
|
|
.arg(imgInfo.cameraSn).arg(pcdPath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = QString("[%1]:3DCamera %2 -- PointCould[%3; %4] can't Find!").arg(stocket.id)
|
|
|
.arg(imgInfo.cameraSn).arg(pcdPath).arg(pcdPath2);
|
|
|
}
|
|
|
|
|
|
qWarning() << str;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
QString str = QString("[%1]:Pre 2D Camera don't Match. Now Camera %2.").arg(stocket.id).arg(imgInfo.cameraSn);
|
|
|
qDebug() << str;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
QSet<QString> set = QSet<QString>::fromList(m_stocketList[stocketID].imagesPathList); // ½« QStringList ת»»Îª QSet
|
|
|
|
|
|
m_stocketList[stocketID].imagesPathList = set.toList(); // ½« QSet ת»»Îª QStringList
|
|
|
|
|
|
if (bRlt3D)
|
|
|
{
|
|
|
m_stocketList[stocketID].smokeQuantityRlt = m_stocketList[stocketID].smokeQuantity;
|
|
|
m_stocketList[stocketID].correctness = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m_stocketList[stocketID].smokeQuantityRlt = "0";
|
|
|
m_stocketList[stocketID].correctness = false;
|
|
|
}
|
|
|
|
|
|
if (!bRlt)
|
|
|
{
|
|
|
m_stocketList[stocketID].smokeTypeNumRlt = "0";
|
|
|
m_stocketList[stocketID].smokeQuantityRlt = "0";
|
|
|
m_stocketList[stocketID].correctness = false;
|
|
|
}
|
|
|
|
|
|
sendResults(MsgType::StockCheckResult,stocketID);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onNumStatistic(QString typeNum)
|
|
|
{
|
|
|
qDebug() << "start num statistic";
|
|
|
if (!m_bDataCollection)
|
|
|
{
|
|
|
qDebug() << "typeNum: " << typeNum;
|
|
|
if (typeNum == "0")
|
|
|
{
|
|
|
m_currtStockCheckInfo.smokeQuantityRlt = "0";
|
|
|
m_currtStockCheckInfo.correctness = false;
|
|
|
sendResults(MsgType::StockCheckResult);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
QString smokeCnName = m_mapSmokeCode2Name.value(typeNum);
|
|
|
QString templateName;
|
|
|
if (m_mapSmokeName2TemplateFolderName.contains(smokeCnName))
|
|
|
{
|
|
|
templateName = m_mapSmokeName2TemplateFolderName.value(smokeCnName);
|
|
|
QtConcurrent::run([=]() {
|
|
|
dataPreProcessing::QStandardnormFileMapLabelSample m = m_pDataProcess->getDataStructure();
|
|
|
int matchLabel = -2;
|
|
|
if (m.contains(templateName))
|
|
|
{
|
|
|
qDebug() << "template find " << templateName;
|
|
|
matchLabel = m_pDataProcess->dataRepeatMatch(templateName);
|
|
|
qDebug() << "match label: " << matchLabel;
|
|
|
m_pDataProcess->clearComData();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
qWarning() << "template not find " << templateName;
|
|
|
m_pDataProcess->clearComData();
|
|
|
matchLabel = -1;
|
|
|
}
|
|
|
int quantityReceive = m_currtStockCheckInfo.smokeQuantity.toInt();
|
|
|
if (matchLabel < 0 /*|| matchLabel != quantityReceive*/)
|
|
|
{
|
|
|
m_currtStockCheckInfo.smokeQuantityRlt = "0";
|
|
|
m_currtStockCheckInfo.correctness = false;
|
|
|
}
|
|
|
else if (matchLabel != quantityReceive)
|
|
|
{
|
|
|
m_currtStockCheckInfo.smokeQuantityRlt = QString::number(matchLabel);
|
|
|
m_currtStockCheckInfo.correctness = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m_currtStockCheckInfo.smokeQuantityRlt = QString::number(matchLabel);
|
|
|
m_currtStockCheckInfo.correctness = true;
|
|
|
}
|
|
|
sendResults(MsgType::StockCheckResult);
|
|
|
});
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
qWarning() << "Template folder not find: " << smokeCnName;
|
|
|
m_currtStockCheckInfo.smokeQuantityRlt = "0";
|
|
|
m_currtStockCheckInfo.correctness = false;
|
|
|
sendResults(MsgType::StockCheckResult);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::sendResults(int mode, int id)
|
|
|
{
|
|
|
QString resultInfoMsg;
|
|
|
switch (mode)
|
|
|
{
|
|
|
case EmptyCheckResult:
|
|
|
break;
|
|
|
case DataCollectionEndSC:
|
|
|
resultInfoMsg.append(STOCK_CHECK_HEAD).append(SPLIT_RULE).append(m_currtStockCheckInfo.streetName)
|
|
|
.append(SPLIT_RULE).append(m_currtStockCheckInfo.taskNum).append(END_SYMBOL);
|
|
|
break;
|
|
|
case StockCheckResult:
|
|
|
switch (m_moduleParam.COMMRules)
|
|
|
{
|
|
|
case eCommunicationRules::emNJ:
|
|
|
if (QString::compare(m_currtStockCheckInfo.smokeTypeNum, m_currtStockCheckInfo.smokeTypeNumRlt) < 0
|
|
|
&& QString::compare("0", m_currtStockCheckInfo.smokeTypeNumRlt) < 0)
|
|
|
{
|
|
|
resultInfoMsg.append(STOCK_CHECK_HEAD).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.streetName).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.stockNum).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.taskNum).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.smokeTypeNumRlt).append(SPLIT_RULE)
|
|
|
.append(QString::number(0)).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.smokeTypeNumRlt).append(SPLIT_RULE)
|
|
|
.append(QString::number(0)).append(SPLIT_RULE)
|
|
|
.append(QString::number(0)).append(END_SYMBOL);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
resultInfoMsg.append(STOCK_CHECK_HEAD).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.streetName).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.stockNum).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.taskNum).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.smokeTypeNum).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.smokeQuantity).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.smokeTypeNumRlt).append(SPLIT_RULE)
|
|
|
.append(m_currtStockCheckInfo.smokeQuantityRlt).append(SPLIT_RULE)
|
|
|
.append(QString::number(m_currtStockCheckInfo.correctness)).append(END_SYMBOL);
|
|
|
}
|
|
|
break;
|
|
|
case eCommunicationRules::emSJZ:
|
|
|
resultInfoMsg.append(RETURN_CALCULATE).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).streetName).append("/").append(QString::number(m_stocketList.value(id).Floor))
|
|
|
.append("/").append(QString::number(m_stocketList.value(id).row)).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).id).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).taskNum).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).stockLocation).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).smokeTypeNumRlt).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).smokeQuantityRlt).append(SPLIT_RULE)
|
|
|
.append(QString::number(m_stocketList.value(id).correctness)).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).imagesPathList.join(";")).append(SPLIT_RULE)
|
|
|
.append(m_stocketList.value(id).pcdSrc).append(END_SYMBOL);
|
|
|
m_stocketList.remove(id);
|
|
|
qInfo() << "m_stocketList.remove(id) = " << id <<"; Next ="<<m_stocketList.size();
|
|
|
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
case IntoStockResult:
|
|
|
switch (m_moduleParam.COMMRules)
|
|
|
{
|
|
|
case eCommunicationRules::emNJ:
|
|
|
{
|
|
|
resultInfoMsg.append(INTO_STOCK_HEAD).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.streetName).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.taskNum).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.stockNum).append(SPLIT_RULE);
|
|
|
QStringList imagesPathList = m_currtIntoStockInfo.imagesPathList;
|
|
|
for (int i = 0; i < imagesPathList.length() - 1; ++i)
|
|
|
{
|
|
|
resultInfoMsg.append(imagesPathList.at(i)).append(CONTENT_SPLIT);
|
|
|
}
|
|
|
resultInfoMsg.append(imagesPathList.last()).append(END_SYMBOL);
|
|
|
break;
|
|
|
}
|
|
|
case eCommunicationRules::emSJZ:
|
|
|
{
|
|
|
resultInfoMsg.append(END_CAPTURE).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.streetName).append("/").append(QString::number(m_currtIntoStockInfo.Floor))
|
|
|
.append("/").append(QString::number(m_currtIntoStockInfo.row)).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.id).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.taskNum).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.stockLocation).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.smokeTypeNum).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.smokeQuantity).append(SPLIT_RULE)
|
|
|
.append(QString::number(m_currtIntoStockInfo.correctness)).append(SPLIT_RULE)
|
|
|
.append(m_currtIntoStockInfo.imagesPathList.join(";")).append(END_SYMBOL);
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
emit sgSendMsg(resultInfoMsg);
|
|
|
qDebug() << "send msg: " << resultInfoMsg;
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onShowImage(QLabel* labelPtr, const QImage& qImage)
|
|
|
{
|
|
|
qDebug() << "Showing image";;
|
|
|
QRect rect = labelPtr->rect();
|
|
|
if (qImage.isNull())
|
|
|
{
|
|
|
qWarning() << "QImage is empty";
|
|
|
return;
|
|
|
}
|
|
|
QImage imgShow = qImage.scaled(QSize(rect.size()));
|
|
|
labelPtr->setPixmap(QPixmap::fromImage(imgShow));
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onMonitorSensorTriggerStart(int sideId)
|
|
|
{
|
|
|
if (m_workMode == WorkMode::StockCheck)
|
|
|
{
|
|
|
qDebug() << "start collect data";
|
|
|
emit sgNumDataCollectStart(sideId);
|
|
|
m_bDataCollection = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onMonitorSensorTriggerStop(int sideId)
|
|
|
{
|
|
|
if (m_workMode == WorkMode::StockCheck)
|
|
|
{
|
|
|
qDebug() << "stop collect data";
|
|
|
emit sgNumDataCollectStop();
|
|
|
m_bDataCollection = false;
|
|
|
//emit sgSendData2AndAlgo();
|
|
|
//QString dataSaveFolder = QString("%1\\%2\\%3\\%4").arg(FILE_STORAGE_PATH)
|
|
|
// .arg(m_currtStockCheckInfo.stockNum).arg(m_currtStockCheckInfo.taskNum)
|
|
|
// .arg(m_currtStockCheckInfo.smokeQuantity);
|
|
|
//dataPreProcessing::mkDir(dataSaveFolder);
|
|
|
//emit sgSaveSensorData2Local(dataSaveFolder);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool SmokeBoxIdentification::decodeSmokeInfoCsv(const QString& filePath)
|
|
|
{
|
|
|
m_mapSmokeCode2Name.clear();
|
|
|
QXlsx::Document* pXlsxDoc = new QXlsx::Document(filePath);
|
|
|
if (pXlsxDoc == NULL)
|
|
|
{
|
|
|
qWarning() << "Load " << filePath << " error";
|
|
|
return false;
|
|
|
}
|
|
|
QString currentSheetName;
|
|
|
QStringList sheetNames = pXlsxDoc->sheetNames();
|
|
|
if (sheetNames.length() == 0)
|
|
|
{
|
|
|
qWarning() << "The quantity of xlsx's sheet is 0";
|
|
|
return false;
|
|
|
}
|
|
|
QXlsx::AbstractSheet* currentSheet = pXlsxDoc->sheet(sheetNames.at(0));
|
|
|
if (currentSheet == NULL)
|
|
|
return false;
|
|
|
|
|
|
// get full cells of current sheet
|
|
|
currentSheet->workbook()->setActiveSheet(0);
|
|
|
QXlsx::Worksheet* wsheet = (QXlsx::Worksheet*)currentSheet->workbook()->activeSheet();
|
|
|
if (wsheet == NULL)
|
|
|
return false;
|
|
|
|
|
|
QXlsx::CellRange cellRange = wsheet->dimension();
|
|
|
int rowStart = cellRange.firstRow();
|
|
|
int colStart = cellRange.firstColumn();
|
|
|
|
|
|
int rowEnd = cellRange.lastRow();
|
|
|
int colEnd = cellRange.lastColumn();
|
|
|
for (int i = rowStart + 1; i <= rowEnd; ++i)
|
|
|
{
|
|
|
QString smokeCode = wsheet->read(i, colStart).toString();
|
|
|
QString smokeName = wsheet->read(i, colStart + 1).toString();
|
|
|
if (smokeCode.isEmpty() || smokeName.isEmpty())
|
|
|
continue;
|
|
|
m_mapSmokeCode2Name.insert(smokeCode, smokeName);
|
|
|
//qDebug() << "insert: " << smokeCode << " and " << smokeName;
|
|
|
}
|
|
|
qDebug() << "Decode smokeInfo from " << filePath << " successed";
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool SmokeBoxIdentification::matchSmokeNameAndTemplateFolderName(const QString& folderPath)
|
|
|
{
|
|
|
m_mapSmokeName2TemplateFolderName.clear();
|
|
|
QDir fileDir(folderPath);
|
|
|
if (!fileDir.exists())
|
|
|
{
|
|
|
qWarning() << folderPath << " is not exist";
|
|
|
return false;
|
|
|
}
|
|
|
if (m_mapSmokeCode2Name.empty())
|
|
|
{
|
|
|
qWarning() << "Decode smokeInfo csv first!";
|
|
|
return false;
|
|
|
}
|
|
|
QStringList smokeCNNameList = m_mapSmokeCode2Name.values();
|
|
|
QFileInfoList listInfoList = fileDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
if (listInfoList.empty())
|
|
|
{
|
|
|
qDebug() << folderPath << " has not folder";
|
|
|
return false;
|
|
|
}
|
|
|
for each (QFileInfo typeFolder in listInfoList)
|
|
|
{
|
|
|
QString typeFolderName = typeFolder.fileName();
|
|
|
bool bFind = false;
|
|
|
for (int i = 0; i < smokeCNNameList.length(); ++i)
|
|
|
{
|
|
|
QString smokeCNName = smokeCNNameList.at(i);
|
|
|
if (typeFolderName.contains(smokeCNName))
|
|
|
{
|
|
|
m_mapSmokeName2TemplateFolderName.insert(smokeCNName, typeFolderName);
|
|
|
//qDebug() << "find " << typeFolderName << " in excel";
|
|
|
//qDebug() << "insert " << smokeCNName << " and " << typeFolderName;
|
|
|
smokeCNNameList.removeAt(i);
|
|
|
bFind = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!bFind)
|
|
|
{
|
|
|
qDebug() << "Not find: " << typeFolderName << " in excel";
|
|
|
}
|
|
|
}
|
|
|
qDebug() << "match smokeName and templateFolderName successed";
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onSendEmptyCheckResults(const QMap<QString, int>& mapEmptyCheckResults)
|
|
|
{
|
|
|
QString emptyAll;
|
|
|
for each (QString code in mapEmptyCheckResults.keys())
|
|
|
{
|
|
|
int emptyStatus = mapEmptyCheckResults[code];
|
|
|
emptyAll.append(code).append(CODE_CONTENT_SPLIT).append(QString::number(emptyStatus))
|
|
|
.append(CONTENT_SPLIT);
|
|
|
}
|
|
|
QString emptyResult;
|
|
|
emptyResult.append(EMPTY_CHECK_HEAD).append(SPLIT_RULE).append(m_currtEmptyCheckInfo.streetName)
|
|
|
.append(SPLIT_RULE).append(m_currtEmptyCheckInfo.taskNum).append(SPLIT_RULE).append(emptyAll)
|
|
|
.append(END_SYMBOL);
|
|
|
emit sgSendMsg(emptyResult);
|
|
|
qDebug() << "send msg: " << emptyResult;
|
|
|
}
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onNewNumData(const QVector<QVector<double>>& vec, const QVector<QString>& strVec, int side)
|
|
|
{
|
|
|
if (vec[0].size() <= 0)
|
|
|
{
|
|
|
qWarning() << "signal stopped but i didnt get data";
|
|
|
return;
|
|
|
}
|
|
|
QString szSide = side == emTopLeft ? "left" : "right";
|
|
|
m_pDataProcess->sensorValTransformationTemp(vec, szSide);
|
|
|
QString dataSaveFolder = QString("%1\\%2\\%3\\%4").arg(FILE_STORAGE_PATH)
|
|
|
.arg(m_currtStockCheckInfo.stockNum).arg(m_currtStockCheckInfo.taskNum)
|
|
|
.arg(m_currtStockCheckInfo.smokeQuantity);
|
|
|
dataPreProcessing::mkDir(dataSaveFolder);
|
|
|
saveData2File(strVec, dataSaveFolder, side);
|
|
|
}
|
|
|
|
|
|
void SmokeBoxIdentification::saveData2File(const QVector<QString>& strVec, QString folderPath, int side)
|
|
|
{
|
|
|
if (!QDir(folderPath).exists())
|
|
|
{
|
|
|
qWarning() << folderPath << " is not exist";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
QString timeStr = QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss");
|
|
|
if (strVec.size() <= 0)
|
|
|
{
|
|
|
qWarning() << "sensor raw data is empty";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
auto savefile = [&](const QString& path, QVector<QString>& vec)->bool
|
|
|
{
|
|
|
ofstream mfile;
|
|
|
mfile.open(path.toStdString(), std::ios::out | std::ios::app | std::ios::ate);
|
|
|
if (!mfile.is_open()) return false;
|
|
|
for (int i = 0; i < vec.size(); ++i)
|
|
|
{
|
|
|
const QString& ls = vec[i];
|
|
|
std::string ss = ls.toStdString() + "\n";
|
|
|
//std::string ss = ls.toStdString();
|
|
|
mfile << ss;
|
|
|
}
|
|
|
mfile.flush();
|
|
|
mfile.close();
|
|
|
};
|
|
|
|
|
|
QString strSide = side == emTopLeft ? "left" : "right";
|
|
|
QString filePath = QString("%1\\%2_%3.txt").arg(folderPath).arg(timeStr).arg(strSide);
|
|
|
qDebug() << "find path" << filePath;
|
|
|
|
|
|
if (strVec.size() >= mimumDataSize)
|
|
|
{
|
|
|
QVector<QString> vec;
|
|
|
m_pDataProcess->sensorValTransformationTemp(strVec, vec, strSide);
|
|
|
savefile(filePath, vec);
|
|
|
qDebug() << "save " << strSide << " data to txt successfully";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void SmokeBoxIdentification::moduleLoading()
|
|
|
{
|
|
|
QString fileMyself = QCoreApplication::applicationDirPath() + MODULE_CONFIG;
|
|
|
QFile file(fileMyself);
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
|
{
|
|
|
qWarning() << "´ò¿ªÎļþʧ°Ü£¡";
|
|
|
return;
|
|
|
}
|
|
|
QByteArray arr = file.readAll();
|
|
|
file.close();
|
|
|
if (arr.isEmpty())
|
|
|
{
|
|
|
qWarning() << "ÄÚÈÝΪ¿Õ";
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
QJsonParseError err;
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(arr, &err);
|
|
|
if (doc.isEmpty())
|
|
|
{
|
|
|
qWarning() << err.errorString(); //´òӡʧ°ÜÐÅÏ¢
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
QJsonObject jsMyself = doc.object();
|
|
|
QJsonObject ModuleParamObj = jsMyself.value("ModuleParam").toObject();
|
|
|
if (!ModuleParamObj.isEmpty()) {
|
|
|
m_moduleParam.CodeScan = ModuleParamObj.value("CodeScan").toInt();
|
|
|
m_moduleParam.Sensor = ModuleParamObj.value("Sensor").toInt();
|
|
|
m_moduleParam.Camera2D = ModuleParamObj.value("Camera2D").toInt();
|
|
|
m_moduleParam.Camera3D = ModuleParamObj.value("Camera3D").toInt();
|
|
|
m_moduleParam.COMMRules = (eCommunicationRules)ModuleParamObj.value("COMMRules").toInt();
|
|
|
}
|
|
|
} |