|
|
|
|
@ -18,9 +18,12 @@
|
|
|
|
|
#include "saveimgthread.h"
|
|
|
|
|
#include "lpGlobalData.h"
|
|
|
|
|
#include "qpulpewidget.h"
|
|
|
|
|
#define VERSION_HUB "3.0.0.1"
|
|
|
|
|
#define VERSION_ALG "3.0.0.1"
|
|
|
|
|
#define UPDATE_TIME "2021-02-20"
|
|
|
|
|
|
|
|
|
|
#include "QZkJsonParser.h"
|
|
|
|
|
|
|
|
|
|
#define VERSION_HUB "3.0.0.2"
|
|
|
|
|
#define VERSION_ALG "3.0.0.2"
|
|
|
|
|
#define UPDATE_TIME "2021-05-08"
|
|
|
|
|
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
lpMainWin::lpMainWin(QWidget *parent)
|
|
|
|
|
@ -251,6 +254,10 @@ lpMainWin::lpMainWin(QWidget *parent)
|
|
|
|
|
|
|
|
|
|
m_timerID = startTimer(1000);
|
|
|
|
|
//m_PulseTimer.start(1000);
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(sgAutoExposure()), this, SLOT(onAutoExposure()));
|
|
|
|
|
QString strPath = QApplication::applicationDirPath();
|
|
|
|
|
readExposureTimeConfig(strPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lpMainWin::~lpMainWin()
|
|
|
|
|
@ -395,6 +402,8 @@ bool lpMainWin::onInitCoreCtrl()
|
|
|
|
|
|
|
|
|
|
FuncCallBack_StrImg strImgfunc = std::bind(&lpMainWin::INewCameraImage, this, std::placeholders::_1, std::placeholders::_2);
|
|
|
|
|
m_pCoreCtrl->IRegisterImageCallBack(strImgfunc);
|
|
|
|
|
|
|
|
|
|
m_camKey = m_pCoreCtrl->ICameraKeys().first();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -523,18 +532,97 @@ void lpMainWin::INewCameraImage(const QString& camKey, QImage img)
|
|
|
|
|
|
|
|
|
|
/*多线程发送算法结果*/
|
|
|
|
|
void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
emit(sgShowImgState(tr("显示识别结果")));
|
|
|
|
|
Result2Ui *pResult = (Result2Ui*)vMap.value("result").toLongLong();
|
|
|
|
|
if (pResult == nullptr)
|
|
|
|
|
{
|
|
|
|
|
pResult = new Result2Ui();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 当没抠出轮毂和NG时自动调整曝光时间重新拍照,最多调整的次数为5次
|
|
|
|
|
if (m_autoExposureSwitch)
|
|
|
|
|
{
|
|
|
|
|
if (vMap.contains("noCircle"))
|
|
|
|
|
{
|
|
|
|
|
if (m_exposureTimeCount == 0)
|
|
|
|
|
{
|
|
|
|
|
int curExposure = getCurExposureTime();
|
|
|
|
|
if (curExposure != m_exposureTimeArray[0])
|
|
|
|
|
{
|
|
|
|
|
emit(sgShowMsgdlg(tr("当前曝光时间未识别到轮毂!")));
|
|
|
|
|
emit sgAutoExposure();
|
|
|
|
|
m_exposureTimeCount++;
|
|
|
|
|
delete pResult;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_exposureTimeCount++;
|
|
|
|
|
if (m_exposureTimeCount >= m_exposureTimeArray.size())
|
|
|
|
|
{
|
|
|
|
|
// m_exposureTimeCount = 0;
|
|
|
|
|
emit(sgShowMsgdlg(tr("调整5次曝光时间后依然未能识别到轮毂!")));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
emit(sgShowMsgdlg(tr("当前曝光时间未识别到轮毂!")));
|
|
|
|
|
emit sgAutoExposure();
|
|
|
|
|
delete pResult;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool ngFlag = (pResult->m_strModel.isEmpty()) && (m_exposureTimeCount < m_exposureTimeArray.size());
|
|
|
|
|
if (ngFlag)
|
|
|
|
|
{
|
|
|
|
|
if (m_exposureTimeCount == 0)
|
|
|
|
|
{
|
|
|
|
|
int curExposure = getCurExposureTime();
|
|
|
|
|
if (curExposure != m_exposureTimeArray[0])
|
|
|
|
|
{
|
|
|
|
|
emit(sgShowMsgdlg(tr("当前曝光时间未识别到轮毂!")));
|
|
|
|
|
emit sgAutoExposure();
|
|
|
|
|
pResult->m_strModel = "NG";
|
|
|
|
|
saveImage(pResult);
|
|
|
|
|
m_exposureTimeCount++;
|
|
|
|
|
delete pResult;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_exposureTimeCount++;
|
|
|
|
|
if (m_exposureTimeCount >= m_exposureTimeArray.size())
|
|
|
|
|
{
|
|
|
|
|
// m_exposureTimeCount = 0;
|
|
|
|
|
emit(sgShowMsgdlg(tr("调整5次曝光时间后依然未能识别到轮毂!")));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
emit(sgShowMsgdlg(tr("当前曝光时间未识别到轮毂!")));
|
|
|
|
|
emit sgAutoExposure();
|
|
|
|
|
pResult->m_strModel = "NG";
|
|
|
|
|
saveImage(pResult);
|
|
|
|
|
delete pResult;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (vMap.contains("error"))
|
|
|
|
|
{
|
|
|
|
|
m_exposureTimeCount = 0;
|
|
|
|
|
emit(sgShowMsgdlg(tr("相机图像和背景图不一样,请更换检测背景!")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Result2Ui *pResult = (Result2Ui*)vMap.value("result").toLongLong();
|
|
|
|
|
onShowResult(pResult);
|
|
|
|
|
if (m_pDebugDlg) {
|
|
|
|
|
m_pDebugDlg->onShowResult(pResult);
|
|
|
|
|
}
|
|
|
|
|
saveImage(pResult);
|
|
|
|
|
if (m_autoExposureSwitch)
|
|
|
|
|
{
|
|
|
|
|
m_exposureTimeCount = 0;
|
|
|
|
|
int exp = m_exposureTimeArray[m_exposureTimeCount];
|
|
|
|
|
m_pCoreCtrl->ISetExposureTime(m_camKey, exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// m_pUi->processResult(pResult);
|
|
|
|
|
static int ErrorNum = 0;
|
|
|
|
|
if (m_pNet) {
|
|
|
|
|
@ -561,6 +649,7 @@ void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
|
|
|
|
|
SendResultBee(LIGHT_BEE, 3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DetectState::instance()->m_SendDetectStr2Net)
|
|
|
|
|
SendResultStr2PLC(pResult);//发送检测结果字符到PLC
|
|
|
|
|
if (DetectState::instance()->m_SendChannelRes2COM)
|
|
|
|
|
@ -569,7 +658,6 @@ void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
|
|
|
|
|
SendResultChannel2PLC(pResult);//发送检测结果通道到PLC
|
|
|
|
|
|
|
|
|
|
m_pCtrl->saveResult(pResult);
|
|
|
|
|
saveImage(pResult);
|
|
|
|
|
|
|
|
|
|
delete pResult;
|
|
|
|
|
}
|
|
|
|
|
@ -1134,7 +1222,11 @@ Q_SLOT void lpMainWin::onTrigRecv(int m_value)
|
|
|
|
|
//if (DetectState::instance()->m_CameraTrigeType == 0)//软件触发模式
|
|
|
|
|
{
|
|
|
|
|
if (DetectState::instance()->IsDetect == true) {
|
|
|
|
|
//CC_Action(CC_AC_NEXT);
|
|
|
|
|
// if (m_exposureTimeCount != 0)
|
|
|
|
|
// {
|
|
|
|
|
// m_pCoreCtrl->ISetExposureTime(m_camKey, m_exposureTimeArray[m_exposureTimeCount]);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
onTriggerCam();
|
|
|
|
|
qWarning() << "soft ctrol camera :" << "(" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz") << ")";
|
|
|
|
|
}
|
|
|
|
|
@ -1484,6 +1576,8 @@ void lpMainWin::saveImage(Result2Ui* pRes)
|
|
|
|
|
if (pRes == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
qDebug() << "satrt tread save Image";
|
|
|
|
|
QString curExposureTimeStr = QString::number(getCurExposureTime());
|
|
|
|
|
|
|
|
|
|
QDir testDir;
|
|
|
|
|
bool IsTestDir = testDir.exists(DetectState::instance()->m_SaveImgDirPath);
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
@ -1520,6 +1614,7 @@ void lpMainWin::saveImage(Result2Ui* pRes)
|
|
|
|
|
QString errorSourceDir = fileSavePath + "\\Error";
|
|
|
|
|
filename += QString("_%1_%2_").arg((int)pRes->m_dThickness).arg((int)pRes->m_dDiameter);
|
|
|
|
|
filename += QDateTime::currentDateTime().toString("hhmmsszzz");
|
|
|
|
|
filename = filename + "_" + curExposureTimeStr;
|
|
|
|
|
if (DetectState::instance()->saveBad == 1) {
|
|
|
|
|
errorSourceDir += "\\Source";
|
|
|
|
|
QString resultpath = errorSourceDir + "\\" + filename + ".png";
|
|
|
|
|
@ -1573,4 +1668,48 @@ Q_SLOT void lpMainWin::onwfPulseTimer()
|
|
|
|
|
// frame.data2 = 0;
|
|
|
|
|
// frame.data8 = 50;
|
|
|
|
|
// SendDataToCom(0x43, frame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool lpMainWin::readExposureTimeConfig(const QString& strPath)
|
|
|
|
|
{
|
|
|
|
|
QString filePath = strPath + "\\config\\exposure.json";
|
|
|
|
|
QJsonObject jsonObj = QZkJsonParser::ReadJsonAuto(filePath);
|
|
|
|
|
if (jsonObj.empty())
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "Json file parsing failed!";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QJsonObject exposureObj = jsonObj.value("exposureTime").toObject();
|
|
|
|
|
|
|
|
|
|
QJsonObject::iterator objIterEnd = exposureObj.end();
|
|
|
|
|
for (auto objIter = exposureObj.begin(); objIter != objIterEnd; objIter++)
|
|
|
|
|
{
|
|
|
|
|
int exposureTime = objIter.value().toInt();
|
|
|
|
|
m_exposureTimeArray.emplace_back(exposureTime);
|
|
|
|
|
}
|
|
|
|
|
m_autoExposureSwitch = jsonObj.value("switch").toInt();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lpMainWin::getCurExposureTime()
|
|
|
|
|
{
|
|
|
|
|
TP_CAMERA_OPTION camOpt;
|
|
|
|
|
m_pCoreCtrl->IGetCameraOption(m_camKey, camOpt);
|
|
|
|
|
return camOpt.exposure;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onAutoExposure()
|
|
|
|
|
{
|
|
|
|
|
if (m_exposureTimeCount >= 0)
|
|
|
|
|
{
|
|
|
|
|
if (m_exposureTimeArray.size() <= m_exposureTimeCount)
|
|
|
|
|
return;
|
|
|
|
|
int exp = m_exposureTimeArray[m_exposureTimeCount];
|
|
|
|
|
qDebug() << "exp:" << exp;
|
|
|
|
|
m_pCoreCtrl->ISetExposureTime(m_camKey, exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onTriggerCam();
|
|
|
|
|
}
|