|
|
|
|
|
#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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ"));
|
|
|
|
|
|
//m_pShowRltImgLabel = ui.label_showImg;
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
ADModule::instance()->loadParameters(filePath);
|
|
|
|
|
|
filePath = applicationDirPath + COM_CONFIG;
|
|
|
|
|
|
lpSerialStation::instance()->loadParameters(filePath);
|
|
|
|
|
|
CodeScanStation::instance()->loadParameters(filePath);
|
|
|
|
|
|
lpSerialStation::instance()->openComs();
|
|
|
|
|
|
CodeScanStation::instance()->openComs();
|
|
|
|
|
|
m_pCategoryMatcher = new CategoryMatcher();
|
|
|
|
|
|
connect(CodeScanStation::instance(), &CodeScanStation::sgNewCodeScanData, lpSerialStation::instance()
|
|
|
|
|
|
, &lpSerialStation::onNewCodeScanResults);
|
|
|
|
|
|
connect(this, &SmokeBoxIdentification::sgCategoryMatchFinished, this, &SmokeBoxIdentification::onNumStatistic);
|
|
|
|
|
|
connect(lpSerialStation::instance(), &lpSerialStation::sgMonitorSensorTriggerStart, this
|
|
|
|
|
|
, &SmokeBoxIdentification::onMonitorSensorTriggerStart);
|
|
|
|
|
|
connect(lpSerialStation::instance(), &lpSerialStation::sgMonitorSensorTriggerStop, this
|
|
|
|
|
|
, &SmokeBoxIdentification::onMonitorSensorTriggerStop);
|
|
|
|
|
|
connect(lpSerialStation::instance(), &lpSerialStation::sgNewEmptyCheckResults, this
|
|
|
|
|
|
, &SmokeBoxIdentification::onSendEmptyCheckResults);
|
|
|
|
|
|
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_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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
|
|
|
|
|
emit sgCapture(eCameraLocation::emTop);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SmokeBoxIdentification::captureSide()
|
|
|
|
|
|
{
|
|
|
|
|
|
emit sgCapture(eCameraLocation::emSide);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SmokeBoxIdentification::saveImage(const QVector<ImageInfo>& vecImageInfo, int workMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString dataSaveFolderPath;
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
QString filePath = QString("%1\\%2").arg(dataSaveFolderPath).arg(fileInfo.name);
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void SmokeBoxIdentification::onCapturedImage(const QVector<ImageInfo>& vecImageInfo, int cameraLocation)
|
|
|
|
|
|
{
|
|
|
|
|
|
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() << "side captured";
|
|
|
|
|
|
QtConcurrent::run([=] {
|
|
|
|
|
|
saveImage(vecImageInfo, m_workMode);
|
|
|
|
|
|
bool bRlt = false;
|
|
|
|
|
|
QString typeNum = m_currtStockCheckInfo.smokeTypeNum;
|
|
|
|
|
|
cv::Mat imgRltMat;
|
|
|
|
|
|
QString dataSaveFolder = QString("%1\\%2\\%3").arg(FILE_STORAGE_PATH)
|
|
|
|
|
|
.arg(m_currtStockCheckInfo.stockNum).arg(m_currtStockCheckInfo.taskNum);
|
|
|
|
|
|
for each (const ImageInfo& imgInfo in vecImageInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pCategoryMatcher->smokeMatch(typeNum, imgInfo.image, imgRltMat))
|
|
|
|
|
|
{
|
|
|
|
|
|
bRlt = true;
|
|
|
|
|
|
FileInfo fileInfo = imgInfo.saveImgInfo;
|
|
|
|
|
|
QString fileName = QString("%1_%2_rlt%3").arg(fileInfo.strId)
|
|
|
|
|
|
.arg(m_currtStockCheckInfo.smokeTypeNum).arg(fileInfo.suffix);
|
|
|
|
|
|
QString filePath = QString("%1\\%2").arg(dataSaveFolder).arg(fileName);
|
|
|
|
|
|
saveImage(imgRltMat, filePath);
|
|
|
|
|
|
qDebug() << "Match successful";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!bRlt)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString filePath = dataSaveFolder + QString("\\%1_error.PNG")
|
|
|
|
|
|
.arg(m_currtStockCheckInfo.smokeTypeNum);
|
|
|
|
|
|
saveImage(imgRltMat, filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
QString typeNumRlt = bRlt ? typeNum : "0";
|
|
|
|
|
|
m_currtStockCheckInfo.smokeTypeNumRlt = typeNumRlt;
|
|
|
|
|
|
qDebug() << "typeNumRlt: " << typeNumRlt;
|
|
|
|
|
|
emit sgCategoryMatchFinished(typeNumRlt);
|
|
|
|
|
|
//if (!imgRltMat.empty())
|
|
|
|
|
|
//{
|
|
|
|
|
|
// cv::cvtColor(imgRltMat, imgRltMat, cv::COLOR_BGR2RGB);
|
|
|
|
|
|
// QImage resultQImg((const unsigned char*)imgRltMat.data, imgRltMat.cols, imgRltMat.rows, imgRltMat.step, QImage::Format_RGB888);
|
|
|
|
|
|
// emit sgShowImage(m_pShowRltImgLabel, resultQImg);
|
|
|
|
|
|
//}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
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() << "<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>λ<EFBFBD>̵<EFBFBD>";
|
|
|
|
|
|
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() << "ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ";
|
|
|
|
|
|
QString taskNum = strList.at(2);
|
|
|
|
|
|
QString currentTaskNum = m_currtStockCheckInfo.taskNum;
|
|
|
|
|
|
if (m_workMode == WorkMode::StockCheck)
|
|
|
|
|
|
{
|
|
|
|
|
|
captureSide();
|
|
|
|
|
|
captureTop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strList.at(0) == INTO_STOCK_HEAD)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strList.length() == 4)
|
|
|
|
|
|
{
|
|
|
|
|
|
qDebug() << "<EFBFBD><EFBFBD><EFBFBD>ⶥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strList.at(0) == LIGHT_CONTROL_HEAD)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strList.length() == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
qDebug() << "<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>";
|
|
|
|
|
|
if (strList.at(2) == "0")
|
|
|
|
|
|
{
|
|
|
|
|
|
emit sgControlSideLight(lightCtrl::emTurnOffLight);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strList.at(2) == "1")
|
|
|
|
|
|
{
|
|
|
|
|
|
emit sgControlSideLight(lightCtrl::emTurnOnLight);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
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:
|
|
|
|
|
|
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 IntoStockResult:
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
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";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|