diff --git a/3part/tadpole/include/tpBase/iAlgorithm.h b/3part/tadpole/include/tpBase/iAlgorithm.h index 6931a79..5d2252a 100644 --- a/3part/tadpole/include/tpBase/iAlgorithm.h +++ b/3part/tadpole/include/tpBase/iAlgorithm.h @@ -175,7 +175,7 @@ protected: #endif #endif -ALGORITHM_API IAlgorithm* Algorithm_Create(class IDetectorEngine*); +ALGORITHM_API IAlgorithm* Algorithm_Create(); ALGORITHM_API void Algorithm_Delete(IAlgorithm* pAlg); #endif \ No newline at end of file diff --git a/3part/tadpole/include/tpBase/iCoreCtrl.h b/3part/tadpole/include/tpBase/iCoreCtrl.h index 5095197..b65760c 100644 --- a/3part/tadpole/include/tpBase/iCoreCtrl.h +++ b/3part/tadpole/include/tpBase/iCoreCtrl.h @@ -68,7 +68,7 @@ public: virtual bool IRegisterResultCallBack(FuncCallBack_StrMap callback) = 0; //注册算法结果回调函数 可获取算法检测结果 virtual bool IRegisterCamEventCallBack(FuncCallBack_StrInt callback) = 0;//注册相机事件回调函数 可获取相机打开关闭等相关事件 public://private: //use private when the old main is discarded; - virtual int IInitCore(class IDetectorEngine* pDE = NULL) = 0; + virtual int IInitCore() = 0; virtual void IFreeCore() = 0; virtual void IStartImageProcess() = 0; virtual void IEndImageProcess() = 0; diff --git a/3part/tadpole/include/tpBase/lpbengine.h b/3part/tadpole/include/tpBase/lpbengine.h index 87ec912..cf00c37 100644 Binary files a/3part/tadpole/include/tpBase/lpbengine.h and b/3part/tadpole/include/tpBase/lpbengine.h differ diff --git a/3part/tadpole/include/tpBase/lpdesigner.h b/3part/tadpole/include/tpBase/lpdesigner.h index f445d97..c4094fb 100644 --- a/3part/tadpole/include/tpBase/lpdesigner.h +++ b/3part/tadpole/include/tpBase/lpdesigner.h @@ -4,7 +4,6 @@ #include "lpdsgdefine.h" #include "SystemStateInfo.h" #include -//#include "vld.h" class IDetectorEngine; class IDetectorTask; diff --git a/src/algorithm/tpAlgorithm.cpp b/src/algorithm/tpAlgorithm.cpp index 86196a8..b319b41 100644 --- a/src/algorithm/tpAlgorithm.cpp +++ b/src/algorithm/tpAlgorithm.cpp @@ -1,15 +1,6 @@ -/****************************************************************************** - Copyright(C):2015~2018 hzleaper - FileName:tpAlgorithm.cpp - Author:zhikun wu - Email:zk.wu@hzleaper.com - Tools:vs2010 pc on company - Created:2015/05/15 - History:15:5:2015 17:56 - *******************************************************************************/ -#include "iAlgorithm.h" +#include "iAlgorithm.h" #include "AlgorithmFluorescence.h" -ALGORITHM_API IAlgorithm* Algorithm_Create(class IDetectorEngine*) +ALGORITHM_API IAlgorithm* Algorithm_Create() { return new CAlgorithmFluorescence(); } diff --git a/src/lpbdesigner/DsgRoiDlg.cpp b/src/lpbdesigner/DsgRoiDlg.cpp index e493b98..8c1e7e9 100644 --- a/src/lpbdesigner/DsgRoiDlg.cpp +++ b/src/lpbdesigner/DsgRoiDlg.cpp @@ -94,9 +94,6 @@ bool CDsgRoiDlg::Initialize(IDetectorEngine* pDE, IDetectorAlgorithm* pAlgo, IDe m_pDE = pDE; m_pTask = pTask; - void* p; - m_pDE->GetDataInterface(DEVICEMGR, &p); - m_pDeviceMgr = (IDetectorDeviceMgr*)p; if (!InitGraphView()) return false; @@ -212,12 +209,12 @@ void __stdcall RoiImageEventHandler(void * callBackOwner, QImage& img, int nDevi void CDsgRoiDlg::OnSnapCameraImage() { - DeviceType type; - IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)m_pDeviceMgr->GetDevice(m_pTask->GetTaskInfo()->nCameraID, type); - if (!pCamera && type != CAMERA) - return; - - pCamera->SnapImage(this, RoiImageEventHandler); +// DeviceType type; +// IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)m_pDeviceMgr->GetDevice(m_pTask->GetTaskInfo()->nCameraID, type); +// if (!pCamera && type != CAMERA) +// return; +// +// pCamera->SnapImage(this, RoiImageEventHandler); } void CDsgRoiDlg::OnSelectImage() diff --git a/src/lpbdesigner/DsgRoiDlg.h b/src/lpbdesigner/DsgRoiDlg.h index 73243ad..ebc5671 100644 --- a/src/lpbdesigner/DsgRoiDlg.h +++ b/src/lpbdesigner/DsgRoiDlg.h @@ -52,10 +52,8 @@ private: Ui::RoiDlg *ui; IDetectorEngine* m_pDE{ nullptr }; - IDetectorDeviceMgr* m_pDeviceMgr{ nullptr }; IDetectorTask* m_pTask{ nullptr }; RoiScene* m_pRoiScene{ nullptr }; - LP_DETECTOR_ROI_DATA m_tempRoiData; }; diff --git a/src/lpbdesigner/MainFrame.cpp b/src/lpbdesigner/MainFrame.cpp index e73e7d9..17c59c1 100644 --- a/src/lpbdesigner/MainFrame.cpp +++ b/src/lpbdesigner/MainFrame.cpp @@ -112,7 +112,6 @@ CMainFrame::CMainFrame(QWidget *parent) { m_pDE = NULL; m_pSolutionMgr = NULL; - m_pDeviceMgr = NULL; m_pCurrentSolution = NULL; m_pCurrentTask = NULL; m_pCurrentAlgo = NULL; @@ -196,11 +195,11 @@ bool CMainFrame::OnMainMenuTrigger(QAction* pAction) if (!oldMat.empty()) _pOldTask->GetTaskInfo()->templateImg = oldMat; } - if (m_pDE && m_pDE->SaveTasks(m_TaskChangeList)) - { - m_TaskChangeList.clear(); - return true; - } +// if (m_pDE && m_pDE->SaveTasks(m_TaskChangeList)) +// { +// m_TaskChangeList.clear(); +// return true; +// } return false; } @@ -218,28 +217,28 @@ void CMainFrame::OnTrigger() if (!oldMat.empty()) _pOldTask->GetTaskInfo()->templateImg = oldMat; } - if (m_pDE && m_pDE->SaveTasks(m_TaskChangeList)) - { - if (_pSaveStatus) - { - _pSaveStatus->setText(QObject::tr(" 标定数据保存完成!")); - QTimer::singleShot(1500, [&](){ - _pSaveStatus->setText(""); - update(); - }); - m_TaskChangeList.clear(); - SystemStateInfo::bParamStateFlag = false; - } - } - else - { - if (_pSaveStatus) - { - _pSaveStatus->setText(QObject::tr(" 保存失败!")); - QTimer::singleShot(2000, [&](){_pSaveStatus->setText(""); }); - update(); - } - } +// if (m_pDE && m_pDE->SaveTasks(m_TaskChangeList)) +// { +// if (_pSaveStatus) +// { +// _pSaveStatus->setText(QObject::tr(" 标定数据保存完成!")); +// QTimer::singleShot(1500, [&](){ +// _pSaveStatus->setText(""); +// update(); +// }); +// m_TaskChangeList.clear(); +// SystemStateInfo::bParamStateFlag = false; +// } +// } +// else +// { +// if (_pSaveStatus) +// { +// _pSaveStatus->setText(QObject::tr(" 保存失败!")); +// QTimer::singleShot(2000, [&](){_pSaveStatus->setText(""); }); +// update(); +// } +// } } } @@ -249,16 +248,9 @@ bool CMainFrame::Initialize(IDetectorEngine* lpDE) return false; m_pDE = lpDE; - void * p; - m_pDE->GetDataInterface(SOLUTIONMGR, &p); - m_pSolutionMgr = (IDetectorSolutionMgr*)p; + m_pSolutionMgr = m_pDE->getSolutionMgr(); if (!m_pSolutionMgr) return false; - - m_pDE->GetDataInterface(DEVICEMGR, &p); - m_pDeviceMgr = (IDetectorDeviceMgr*)p; - if (!m_pDeviceMgr) - return false; return true; } @@ -656,15 +648,15 @@ void __stdcall ImageEventHandler(void * callBackOwner, QImage& img, int nDeviceI bool CMainFrame::OnSnapImage() { - if (!currentTask()) - return false; - - DeviceType type; - IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)m_pDeviceMgr->GetDevice(m_pCurrentTask->GetTaskInfo()->nCameraID, type); - if (!pCamera && type != CAMERA) - return false; - - pCamera->SnapImage(this, ImageEventHandler); +// if (!currentTask()) +// return false; +// +// DeviceType type; +// IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)m_pDeviceMgr->GetDevice(m_pCurrentTask->GetTaskInfo()->nCameraID, type); +// if (!pCamera && type != CAMERA) +// return false; +// +// pCamera->SnapImage(this, ImageEventHandler); return true; } @@ -1867,10 +1859,7 @@ void CMainFrame::closeEvent(QCloseEvent *event) msgBox.addButton(QObject::tr("否"), QMessageBox::RejectRole); if (msgBox.exec() == QMessageBox::AcceptRole) { - m_pDE->Save(); - } - else - { + //m_pDE->Save(); } SystemStateInfo::bParamStateFlag = false; } diff --git a/src/lpbdesigner/MainFrame.h b/src/lpbdesigner/MainFrame.h index a0f08af..dad3b1a 100644 --- a/src/lpbdesigner/MainFrame.h +++ b/src/lpbdesigner/MainFrame.h @@ -103,7 +103,6 @@ private: IDetectorEngine* m_pDE{ nullptr }; IDetectorSolutionMgr* m_pSolutionMgr{ nullptr }; - IDetectorDeviceMgr* m_pDeviceMgr{ nullptr }; IDetectorSolution* m_pCurrentSolution{ nullptr }; IDetectorTask* m_pCurrentTask{ nullptr }; diff --git a/src/lpbengine/Algorithm.cpp b/src/lpbengine/Algorithm.cpp index cc9f0f0..b6edbe2 100644 --- a/src/lpbengine/Algorithm.cpp +++ b/src/lpbengine/Algorithm.cpp @@ -12,7 +12,6 @@ CDetectorAlgorithm::CDetectorAlgorithm() : m_mutex(QReadWriteLock::Recursive) m_mapOutParams.clear(); m_pAlgo = NULL; m_pTask = NULL; - m_pAlgoShare = NULL; m_bIsFinished = false; m_bIsExec = true; m_dExecTime = 0.0; @@ -23,13 +22,12 @@ CDetectorAlgorithm::~CDetectorAlgorithm() CleanUp(); } -bool CDetectorAlgorithm::Initialize(IDetectorTask* pTask, IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr) +bool CDetectorAlgorithm::Initialize(IDetectorTask* pTask, IAlgorithmLibMgr* pAlgoLibMgr) { if (!pTask) return false; m_pTask = pTask; - m_pAlgoShare = pAlgoShare; m_pAlgoLibMgr = pAlgoLibMgr; return true; @@ -112,9 +110,6 @@ bool CDetectorAlgorithm::SetAlgorithmInfo(const PLP_DETECTOR_ALGORITHM pAlgorith m_tAlgorithmInfo.strLibName = pAlgorithmInfo->strLibName; m_tAlgorithmInfo.strFuncName = pAlgorithmInfo->strFuncName; - //if (!Load(m_tAlgorithmInfo.strName)) - // return false; - return true; } @@ -162,28 +157,6 @@ PLP_ALGORITHM_PARAM CDetectorAlgorithm::AddParam(const PLP_ALGORITHM_PARAM pPara m_mapParams[pParam->strName] = (*its); return (*its); } - - - //else - { -// LP_ALGORITHM_PARAM* p = new LP_ALGORITHM_PARAM; -// -// p->nID = ++m_nParamBaseID; -// p->nTaskID = pParam->nTaskID; -// p->nSrcAlgoID = pParam->nSrcAlgoID; -// p->nSrcParamID = pParam->nSrcParamID; -// p->strName = pParam->strName; -// p->type = pParam->type; -// p->value = pParam->value; -// p->strDescription = pParam->strDescription; -// p->bIsSave = pParam->bIsSave; -// p->bIsLock = pParam->bIsLock; -// -// //m_vecParams.push_back(p); -// m_mapParams.insert(p->strName, p); -// m_vecParams[p->strName] = p; -// return p; - } } return NULL; } @@ -204,7 +177,6 @@ bool CDetectorAlgorithm::DeleteParam(int nParamID) delete *iter; return true; } - } } @@ -222,9 +194,7 @@ PLP_ALGORITHM_PARAM CDetectorAlgorithm::GetParam(int nParamID) if (p->nID == nParamID) return p; } - } - return NULL; } @@ -284,23 +254,6 @@ PLP_ALGORITHM_PARAM CDetectorAlgorithm::AddOutParam(const PLP_ALGORITHM_PARAM pP m_mapOutParams[pParam->strName] = (*its); return (*its); } -// else -// { -// PLP_ALGORITHM_PARAM p = new LP_ALGORITHM_PARAM; -// -// p->nID = ++m_nOutParamBaseID; -// p->nTaskID = pParam->nTaskID; -// p->nSrcAlgoID = pParam->nSrcAlgoID; -// p->nSrcParamID = pParam->nSrcParamID; -// p->strName = pParam->strName; -// p->type = pParam->type; -// p->value = pParam->value; -// p->strDescription = pParam->strDescription; -// p->bIsSave = pParam->bIsSave; -// -// m_vecOutParams[p->strName] = p; -// m_mapOutParams.insert(p->strName, p); -// } } return NULL; } @@ -409,7 +362,6 @@ bool CDetectorAlgorithm::SerializeParamPropertyToJson(QJsonObject* pJsonObject, PropertyArray.push_back(propertys); } - } pJsonObject->insert("property", PropertyArray); @@ -1111,7 +1063,6 @@ bool CDetectorAlgorithm::SerializeFromJson(QJsonObject* pJsonObject) { LP_DETECTOR_ROI_DATA roiData; - //roiData.img = m_pTask->GetTaskInfo()->templateImg; QJsonArray recordArray = jsonObject.value("out_param_value").toArray(); int nRecordCount = recordArray.size(); @@ -1633,16 +1584,6 @@ bool CDetectorAlgorithm::InitRoiInfo() QVariant CDetectorAlgorithm::GetParamValue(QString strKey, AlgoParamType type) { - //for (QVector::iterator iter = m_vecParams.begin(); - // iter != m_vecParams.end(); ++iter) - //{ - // PLP_ALGORITHM_PARAM param = *iter; - // if (param && param->type ==type && param->strName == strKey) - // { - // return param->value; - // } - //} - if (m_mapParams.value(strKey)) { return m_mapParams.value(strKey)->value; @@ -1653,16 +1594,6 @@ QVariant CDetectorAlgorithm::GetParamValue(QString strKey, AlgoParamType type) QVariant CDetectorAlgorithm::GetOutParamValue(QString strKey, AlgoParamType type) { - //for (QVector::iterator iter = m_vecOutParams.begin(); - // iter != m_vecOutParams.end(); ++iter) - //{ - // PLP_ALGORITHM_PARAM param = *iter; - // if (param && param->type == type && param->strName == strKey) - // { - // return param->value; - // } - //} - if (m_mapOutParams.value(strKey)) { return m_mapOutParams.value(strKey)->value; @@ -1673,26 +1604,6 @@ QVariant CDetectorAlgorithm::GetOutParamValue(QString strKey, AlgoParamType type bool CDetectorAlgorithm::SetOutParamValue(QString strKey, QVariant value) { - //for (QVector::iterator iter = m_vecOutParams.begin(); - // iter != m_vecOutParams.end(); ++iter) - //{ - // PLP_ALGORITHM_PARAM param = *iter; - // if (param && param->strName == strKey) - // { - // if (param->type == LP_IMAGE) - // { - // QImage img = value.value(); - // param->value = img; - // } - // else - // { - // param->value = value; - // } - - // return true; - // } - //} - PLP_ALGORITHM_PARAM pParam = m_mapOutParams.value(strKey); if (pParam) { @@ -1927,7 +1838,7 @@ bool CDetectorAlgorithm::ImportParam(QJsonArray paramArray)//导入参数 { QString strFileName = jsonObject.value("param_value").toString(); std::string strpath = strFileName.toLocal8Bit().toStdString(); - cv::Mat resultFile = cv::imread(strpath/*strFileName.toLatin1().data()*/, CV_LOAD_IMAGE_UNCHANGED); + cv::Mat resultFile = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED); param.value.setValue(resultFile); if (m_pTask) m_pTask->AppendOtherFile(QString(strpath.c_str())); @@ -1942,7 +1853,7 @@ bool CDetectorAlgorithm::ImportParam(QJsonArray paramArray)//导入参数 QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR; QString strFileName = strFilePath + QString::number(param.nID) + ".bmp"; std::string strpath = strFileName.toLocal8Bit().toStdString(); - roiData.img = cv::imread(strpath/*strFileName.toLatin1().data()*/, CV_LOAD_IMAGE_UNCHANGED); + roiData.img = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED); QJsonArray recordArray = jsonObject.value("param_value").toArray(); @@ -2002,8 +1913,6 @@ bool CDetectorAlgorithm::ImportParam(QJsonArray paramArray)//导入参数 } param.value.setValue(roiData); - - break; } @@ -2013,10 +1922,7 @@ bool CDetectorAlgorithm::ImportParam(QJsonArray paramArray)//导入参数 param.strDescription = jsonObject.value("param_description").toString(); PLP_ALGORITHM_PARAM pParam = (PLP_ALGORITHM_PARAM)AddParam(¶m,false); - } - - return true; } @@ -2071,7 +1977,7 @@ QByteArray CDetectorAlgorithm::ExportParam() QString strFilePath = strExePath + "/" + "paramfiles/"; QString strFileName = strFilePath + QString::number(p->nID) + ".bmp"; std::string strpath = strFileName.toLocal8Bit().toStdString(); - if (!matResult.empty() && !cv::imwrite(strpath/*strFileName.toLatin1().data()*/, matResult)) + if (!matResult.empty() && !cv::imwrite(strpath, matResult)) return false; jsonParam.insert("param_value", strFileName); @@ -2086,7 +1992,7 @@ QByteArray CDetectorAlgorithm::ExportParam() QString strFilePath = strExePath + "/" + "images/"; QString strFileName = strFilePath + QString::number(p->nID) + ".bmp"; std::string strpath = strFileName.toLocal8Bit().toStdString(); - if (!roiData.img.empty() && !cv::imwrite(strpath/*strFileName.toLatin1().data()*/, roiData.img)) + if (!roiData.img.empty() && !cv::imwrite(strpath, roiData.img)) return false; int nCount = roiData.records.size(); @@ -2219,7 +2125,7 @@ bool CDetectorAlgorithm::ImportOutParam(QJsonArray outParamArray)//导入参数 QString strFileName = jsonObject.value("param_value").toString(); std::string strpath = strFileName.toLocal8Bit().toStdString(); - cv::Mat resultFile = cv::imread(strpath/*strFileName.toLatin1().data()*/); + cv::Mat resultFile = cv::imread(strpath); param.value.setValue(resultFile); if (m_pTask) m_pTask->AppendOtherFile(QString(strpath.c_str())); @@ -2234,7 +2140,7 @@ bool CDetectorAlgorithm::ImportOutParam(QJsonArray outParamArray)//导入参数 QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR; QString strFileName = strFilePath + QString::number(param.nID) + ".bmp"; std::string strpath = strFileName.toLocal8Bit().toStdString(); - roiData.img = cv::imread(strpath/*strFileName.toLatin1().data()*/, CV_LOAD_IMAGE_UNCHANGED); + roiData.img = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED); QJsonArray recordArray = jsonObject.value("param_value").toArray(); @@ -2361,7 +2267,7 @@ QByteArray CDetectorAlgorithm::ExportOutParam()//导出参数 QString strFilePath = strExePath + "/" + "paramfiles/"; QString strFileName = strFilePath + QString::number(p->nID) + ".bmp"; std::string strpath = strFileName.toLocal8Bit().toStdString(); - if (!matResult.empty() && !cv::imwrite(strpath/*strFileName.toLatin1().data()*/, matResult)) + if (!matResult.empty() && !cv::imwrite(strpath, matResult)) return false; jsonParam.insert("param_value", strFileName); @@ -2376,7 +2282,7 @@ QByteArray CDetectorAlgorithm::ExportOutParam()//导出参数 QString strFilePath = strExePath + "/" + "images/"; QString strFileName = strFilePath + QString::number(p->nID) + ".bmp"; std::string strpath = strFileName.toLocal8Bit().toStdString(); - if (!roiData.img.empty() && !cv::imwrite(strpath/*strFileName.toLatin1().data()*/, roiData.img)) + if (!roiData.img.empty() && !cv::imwrite(strpath, roiData.img)) return false; int nCount = roiData.records.size(); @@ -2546,14 +2452,6 @@ bool CDetectorAlgorithm::UpdateParamValueByName(QString strName, QVariant& value return bRet; } -PLP_ALGORITHM_PARAM CDetectorAlgorithm::GetShareParam(QString strName, int idx /* = -1 */) -{ - if (!m_pAlgoShare || !m_pTask) - return NULL; - - return m_pAlgoShare->GetParam(strName, m_pTask->GetTaskInfo()->nGroupParamID); -} - void CDetectorAlgorithm::LoadUserParamValue(int nParamID /*= LP_DETECTOR_INVALID_ID*/) { if (!m_pAlgo) @@ -2570,7 +2468,6 @@ void CDetectorAlgorithm::LoadUserParamValue(int nParamID /*= LP_DETECTOR_INVALID if (p->type == LP_USER) m_pAlgo->LoadUserParamValue(m_pTask, this, p->strName, p->value); } - } } else @@ -2631,7 +2528,6 @@ void CDetectorAlgorithm::ClearUserParamValue(int nParamID /*= LP_DETECTOR_INVALI if (p->type == LP_USER) p->value.clear(); } - } } else @@ -2654,4 +2550,5 @@ bool CDetectorAlgorithm::HandleEvent(QString strParamName /*= ""*/, int event/* } return false; -} \ No newline at end of file +} + diff --git a/src/lpbengine/Algorithm.h b/src/lpbengine/Algorithm.h index e528249..8089c3c 100644 Binary files a/src/lpbengine/Algorithm.h and b/src/lpbengine/Algorithm.h differ diff --git a/src/lpbengine/AlgorithmLib.cpp b/src/lpbengine/AlgorithmLib.cpp index b2e1354..56d2dec 100644 --- a/src/lpbengine/AlgorithmLib.cpp +++ b/src/lpbengine/AlgorithmLib.cpp @@ -64,43 +64,9 @@ bool CAlgorithmLib::InitAlgo(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgori { lpAlgorithm->AddOutParam(¶m); } - //switch (descParam.type) - //{ - //case LP_INT: - //case LP_BOOLEAN: - //case LP_STRING: - //case LP_DOUBLE: - //case LP_IMAGE: - //case LP_POINT: - //case LP_POINTF: - //case LP_RECT: - //case LP_RECTF: - //case LP_ROI: - //case LP_MAT: - //case LP_LIST_INT: - //case LP_LIST_BOOLEAN: - //case LP_LIST_STRING: - //case LP_LIST_DOUBLE: - //case LP_USER: - //case LP_LINE: - //case LP_LINEF: - //case LP_CIRCLE: - //case LP_CIRCLEF: - //case LP_POLYGON: - //case LP_POLYGONF: - //case LP_TRANSFORM: - //{ - - - // break; - //} - //default: - // break; - //} } return m_pAlgo->Init(lpTask, lpAlgorithm);; -// return m_pAlgo->Init(lpTask, lpAlgorithm); } bool CAlgorithmLib::Load(const QString& strPath) diff --git a/src/lpbengine/AlgorithmLibMgr.cpp b/src/lpbengine/AlgorithmLibMgr.cpp index cbe5a21..5bfcee6 100644 --- a/src/lpbengine/AlgorithmLibMgr.cpp +++ b/src/lpbengine/AlgorithmLibMgr.cpp @@ -5,7 +5,6 @@ CAlgorithmLibMgr::CAlgorithmLibMgr() { m_mapAlgoLib.clear(); - m_pSysInfo = NULL; } CAlgorithmLibMgr::~CAlgorithmLibMgr() @@ -13,20 +12,12 @@ CAlgorithmLibMgr::~CAlgorithmLibMgr() CleanUp(); } -bool CAlgorithmLibMgr::Initialize(IDetectorSystemInfo* pSysInfo) -{ - m_pSysInfo = pSysInfo; - return true; -} - void CAlgorithmLibMgr::CleanUp() { QMap::Iterator it; - for (it = m_mapAlgoLib.begin(); it != m_mapAlgoLib.end(); ++it) - { + for (it = m_mapAlgoLib.begin(); it != m_mapAlgoLib.end(); ++it) { IAlgorithmLib* p = it.value(); - if (p) - { + if (p) { delete p; } } @@ -40,8 +31,7 @@ bool CAlgorithmLibMgr::AddAlgorithmLib(const QString& strName, const QString& st return false; CAlgorithmLib* pLib = new CAlgorithmLib(strName); - if (!pLib->Load(strPath)) - { + if (!pLib->Load(strPath)) { delete pLib; return false; } @@ -85,21 +75,5 @@ bool CAlgorithmLibMgr::Save() bool CAlgorithmLibMgr::Load() { - m_pSysInfo->BeginGroup("AlgoLibInfo"); - - QStringList libList = m_pSysInfo->allKeys(); - for (int i = 0; i < libList.size(); i++) - { - QString strKey = libList.at(i); - if (!AddAlgorithmLib(strKey, m_pSysInfo->GetValue(strKey).toString())) - { - m_pSysInfo->EndGroup(); - qErrnoWarning("load algorithmlib: %s fail", strKey.toLocal8Bit().data()); - return false; - } - } - - m_pSysInfo->EndGroup(); return true; - } \ No newline at end of file diff --git a/src/lpbengine/AlgorithmLibMgr.h b/src/lpbengine/AlgorithmLibMgr.h index 4156f38..061e38f 100644 --- a/src/lpbengine/AlgorithmLibMgr.h +++ b/src/lpbengine/AlgorithmLibMgr.h @@ -9,8 +9,6 @@ public: CAlgorithmLibMgr(); virtual ~CAlgorithmLibMgr(); - bool Initialize(IDetectorSystemInfo* pSysInfo); - virtual bool Save(); virtual bool Load(); @@ -21,8 +19,6 @@ public: virtual void CleanUp(); private: QMap m_mapAlgoLib; - - IDetectorSystemInfo* m_pSysInfo; }; #endif // ALGORITHMLIBMGR_H \ No newline at end of file diff --git a/src/lpbengine/AlgorithmShare.cpp b/src/lpbengine/AlgorithmShare.cpp deleted file mode 100644 index 3f22f90..0000000 --- a/src/lpbengine/AlgorithmShare.cpp +++ /dev/null @@ -1,608 +0,0 @@ -#include "AlgorithmShare.h" - -CAlgorithmShare::CAlgorithmShare() : m_mutex(QMutex::Recursive) -{ - m_mapParamGroup.clear(); -} - -CAlgorithmShare::~CAlgorithmShare() -{ -// CleanUp(); -} - -bool CAlgorithmShare::Initialize() -{ - return true; -} - -PLP_ALGORITHM_PARAM CAlgorithmShare::AddParam(const PLP_ALGORITHM_PARAM pParam, int idx /* = -1 */) -{ - if (NULL == pParam) - return NULL; - - LP_ALGORITHM_PARAM* p = new LP_ALGORITHM_PARAM; - - p->nID = LP_DETECTOR_INVALID_ID; - p->nSrcAlgoID = LP_DETECTOR_INVALID_ID; - p->nSrcParamID = LP_DETECTOR_INVALID_ID; - p->strName = pParam->strName; - p->type = pParam->type; - p->value = pParam->value; - p->strDescription = ""; - p->bIsSave = false; - - - QVector* pGroup = m_mapParamGroup[idx]; - if (!pGroup) - { - m_mapParamGroup.remove(idx); - pGroup = new QVector < PLP_ALGORITHM_PARAM >; - m_mapParamGroup.insert(idx, pGroup); - } - - pGroup->push_back(p); - - return p; -} - -bool CAlgorithmShare::DeleteParam(QString strName, int idx /* = -1 */) -{ - QVector* pGroup = m_mapParamGroup.value(idx); - if (!pGroup) - return false; - - for (QVector::iterator iter = pGroup->begin(); - iter != pGroup->end(); ++iter) - { - PLP_ALGORITHM_PARAM p = *iter; - - if (NULL != p) - { - if (p->strName == strName) - { - delete *iter; - iter = pGroup->erase(iter); - if (pGroup->empty()) - { - delete pGroup; - m_mapParamGroup.remove(idx); - } - return true; - } - - } - } - - return false; -} - -PLP_ALGORITHM_PARAM CAlgorithmShare::GetParam(QString strName, int idx /* = -1 */) -{ - QVector* pGroup = m_mapParamGroup.value(idx); - if (!pGroup) - return NULL; - - for (QVector::iterator iter = pGroup->begin(); - iter != pGroup->end(); ++iter) - { - if (NULL != *iter) - { - PLP_ALGORITHM_PARAM p = *iter; - if (p->strName == strName) - return p; - } - - } - - return NULL; -} - -QStringList CAlgorithmShare::GroupList() -{ - QStringList groupList; - groupList.clear(); - - QMap*>::Iterator it; - for (it = m_mapParamGroup.begin(); it != m_mapParamGroup.end(); ++it) - { - groupList.append(QString::number(it.key())); - } - - return groupList; -} - -QStringList CAlgorithmShare::ParamList(int idx /* = -1 */) -{ - QStringList paramList; - paramList.clear(); - - QVector* pGroup = m_mapParamGroup.value(idx); - if (!pGroup) - return paramList; - - for (QVector::iterator iter = pGroup->begin(); - iter != pGroup->end(); ++iter) - { - if (NULL != *iter) - { - PLP_ALGORITHM_PARAM p = *iter; - paramList.append(p->strName); - } - - } - - return paramList; -} - -bool CAlgorithmShare::Save() -{ - QJsonDocument document; - QJsonArray groupArray; - - QMap*>::Iterator it; - for (it = m_mapParamGroup.begin(); it != m_mapParamGroup.end(); ++it) - { - int groupID = it.key(); - QVector* pGroup = it.value(); - - if (!SerializeToJson(&groupArray, groupID, pGroup)) - return false; - } - - document.setArray(groupArray); - QByteArray byteArray = document.toJson(); - - if (byteArray.isNull()) - return false; - - QString strExePath = QCoreApplication::applicationDirPath(); - QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_PARAMSHARE_FILE; - QFile file(strFilePath); - if (file.open(QFile::WriteOnly | QFile::Text)) - { - file.write(byteArray); - file.flush(); - file.close(); - return true; - } - - return false; -} - -bool CAlgorithmShare::Load() -{ - QByteArray byteArray; - QString strExePath = QCoreApplication::applicationDirPath(); - QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_PARAMSHARE_FILE; - QFile file(strFilePath); - - if (!file.exists()) - { - file.open(QIODevice::ReadWrite); - file.close(); - return true; - } - - if (!file.open(QIODevice::ReadOnly)) - { - qErrnoWarning("load algorithmshare: %s fail", strFilePath.toLocal8Bit().data()); - return false; - } - - byteArray = file.readAll(); - - if (byteArray.size() == 0) - return true; - - QJsonParseError parse_error; - QJsonDocument document = QJsonDocument::fromJson(byteArray, &parse_error); - - if (parse_error.error == QJsonParseError::NoError) - { - if (!document.isEmpty() && !document.isNull()) - { - if (document.isArray()) - { - QJsonArray groupArray = document.array(); - - for (int i = 0; i < groupArray.size(); i++) - { - QJsonObject jsonObject = groupArray[i].toObject(); - if (!SerializeFromJson(&jsonObject)) - { - qErrnoWarning("load algorithmshare: %s fail", strFilePath.toLocal8Bit().data()); - return false; - } - } - - return true; - } - } - } - - return false; -} - -bool CAlgorithmShare::SerializeToJson(QJsonArray* pGroupArray, int nGroupID, QVector* pGroup) -{ - if (!pGroupArray || !pGroup) - return false; - - QJsonObject jsonObject; - jsonObject.insert("group_id", nGroupID); - - QJsonArray paramArray; - - for (QVector::iterator iter = pGroup->begin(); - iter != pGroup->end(); ++iter) - { - if (*iter) - { - PLP_ALGORITHM_PARAM p = (PLP_ALGORITHM_PARAM)*iter; - QJsonObject jsonParam; - jsonParam.insert("param_id", p->nID); - jsonParam.insert("param_src_task_id", p->nTaskID); - jsonParam.insert("param_src_algo_id", p->nSrcAlgoID); - jsonParam.insert("param_src_param_id", p->nSrcParamID); - jsonParam.insert("param_name", p->strName); - jsonParam.insert("param_type", p->type); - switch (p->type) - { - case LP_INT: - { - jsonParam.insert("param_value", p->value.toInt()); - break; - } - case LP_BOOLEAN: - { - jsonParam.insert("param_value", p->value.toBool()); - break; - } - case LP_STRING: - { - jsonParam.insert("param_value", p->value.toString()); - break; - } - case LP_DOUBLE: - { - jsonParam.insert("param_value", p->value.toDouble()); - break; - } - case LP_IMAGE: - { - break; - } - case LP_MAT: - { - break; - } - case LP_ROI: - { - - LP_DETECTOR_ROI_DATA roiData = p->value.value(); - - QString strExePath = QCoreApplication::applicationDirPath(); - QString strFilePath = strExePath + "/" + "images/"; - QDir dir; - if (!dir.exists(strFilePath)) - { - if (!dir.mkdir(strFilePath)) - return false; - } - - QString strName = QString("%1_%2").arg(QString::number(nGroupID)).arg(p->strName); - - QString strFileName = strFilePath + strName + ".bmp"; - std::string strpath = strFileName.toLocal8Bit().toStdString(); - if (!roiData.img.empty() && !cv::imwrite(strpath/*strFileName.toLatin1().data()*/, roiData.img)) - return false; - - int nCount = roiData.records.size(); - if (nCount > 0) - { - QJsonArray recordArray; - for (int i = 0; i < nCount; i++) - { - QJsonArray itemArray; - Item_List record = roiData.records.at(i); - int nItemCount = record.size(); - for (int j = 0; j < nItemCount; j++) - { - QJsonObject itemJson; - Feature_List item = record.at(j); - - itemJson.insert("roi_item_type", item.first); - switch (item.first) - { - case RECTANGLE: - case ELLIPSE: - { - itemJson.insert("roi_item_value1", item.second.at(0)); - itemJson.insert("roi_item_value2", item.second.at(1)); - itemJson.insert("roi_item_value3", item.second.at(2)); - itemJson.insert("roi_item_value4", item.second.at(3)); - break; - } - case CIRCLE: - { - itemJson.insert("roi_item_value1", item.second.at(0)); - itemJson.insert("roi_item_value2", item.second.at(1)); - itemJson.insert("roi_item_value3", item.second.at(2)); - break; - } - case POLY: - { - break; - } - default: - break; - } - - - itemArray.push_back(itemJson); - } - - recordArray.push_back(itemArray); - } - - jsonParam.insert("param_value", recordArray); - } - - break; - } - default: - break; - } - - jsonParam.insert("param_description", p->strDescription); - paramArray.push_back(jsonParam); - - } - - } - - if (paramArray.size() > 0) - jsonObject.insert("paramArray", paramArray); - - - pGroupArray->push_back(jsonObject); - - return true; -} - -bool CAlgorithmShare::SerializeFromJson(QJsonObject* pJsonObject) -{ - - int nGroupID = pJsonObject->value("group_id").toInt(); - QJsonArray paramArray = pJsonObject->value("paramArray").toArray(); - for (int i = 0; i < paramArray.size(); i++) - { - - LP_ALGORITHM_PARAM param; - QJsonObject jsonObject = paramArray[i].toObject(); - - param.nTaskID = jsonObject.value("param_src_task_id").toInt(LP_DETECTOR_INVALID_ID); - param.nSrcAlgoID = jsonObject.value("param_src_algo_id").toInt(); - param.nSrcParamID = jsonObject.value("param_src_param_id").toInt(); - param.strName = jsonObject.value("param_name").toString(); - param.type = (AlgoParamType)jsonObject.value("param_type").toInt(); - switch (param.type) - { - case LP_INT: - { - param.value = jsonObject.value("param_value").toInt(); - break; - } - case LP_BOOLEAN: - { - param.value = jsonObject.value("param_value").toBool(); - break; - } - case LP_STRING: - { - param.value = jsonObject.value("param_value").toString(); - break; - } - case LP_DOUBLE: - { - param.value = jsonObject.value("param_value").toDouble(); - break; - } - case LP_IMAGE: - { - break; - } - case LP_MAT: - { - break; - } - case LP_ROI: - { - LP_DETECTOR_ROI_DATA roiData; - - - QString strExePath = QCoreApplication::applicationDirPath(); - QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR; - QString strName = QString("%1_%2").arg(QString::number(nGroupID)).arg(param.strName); - - QString strFileName = strFilePath + strName + ".bmp"; - std::string strpath = strFileName.toLocal8Bit().toStdString(); - roiData.img = cv::imread(strpath/*strFileName.toLatin1().data()*/); - - - QJsonArray recordArray = jsonObject.value("param_value").toArray(); - - int nRecordCount = recordArray.size(); - if (nRecordCount > 0) - { - Record_List recordList; - for (int i = 0; i < nRecordCount; i++) - { - QJsonArray itemArray = recordArray.at(i).toArray(); - int nItemCount = itemArray.size(); - if (nItemCount > 0) - { - Item_List itemList; - for (int j = 0; j < nItemCount; j++) - { - QJsonObject itemJson = itemArray.at(j).toObject(); - - Feature_List item; - item.first = itemJson.value("roi_item_type").toInt(); - switch (item.first) - { - case RECTANGLE: - case ELLIPSE: - { - item.second.push_back(itemJson.value("roi_item_value1").toDouble()); - item.second.push_back(itemJson.value("roi_item_value2").toDouble()); - item.second.push_back(itemJson.value("roi_item_value3").toDouble()); - item.second.push_back(itemJson.value("roi_item_value4").toDouble()); - break; - } - case CIRCLE: - { - item.second.push_back(itemJson.value("roi_item_value1").toDouble()); - item.second.push_back(itemJson.value("roi_item_value2").toDouble()); - item.second.push_back(itemJson.value("roi_item_value3").toDouble()); - break; - } - case POLY: - { - break; - } - default: - break; - } - - itemList.push_back(item); - } - - recordList.push_back(itemList); - } - - roiData.records = recordList; - - } - } - - param.value.setValue(roiData); - - - break; - } - - default: - break; - } - - param.strDescription = jsonObject.value("param_description").toString(); - PLP_ALGORITHM_PARAM pParam = (PLP_ALGORITHM_PARAM)AddParam(¶m, nGroupID); - pParam->nID = jsonObject.value("param_id").toInt(); - - } - - - return true; -} - -void CAlgorithmShare::CleanUp() -{ - QMap*>::Iterator it; - for (it = m_mapParamGroup.begin(); it != m_mapParamGroup.end(); ++it) - { - QVector* pGroup = it.value(); - for (QVector::iterator iter = pGroup->begin(); - iter != pGroup->end(); ++iter) - { - PLP_ALGORITHM_PARAM p = *iter; - if (p) - { - delete p; - } - } - - pGroup->clear(); - delete pGroup; - } - - m_mapParamGroup.clear(); -} - -bool CAlgorithmShare::RegisterCoreCtrl(class ICoreCtrl* pCoreCtrl /* = NULL */) -{ - if (!pCoreCtrl) - return false; - - m_pCoreCtrl = pCoreCtrl; - return true; -} - -bool CAlgorithmShare::GetIntValue(int nAlgorithm, const QString& skey, QString& value, int nDefault) -{ -// IAlgorithmOption* p = m_pCoreCtrl->IGetAlgorithmOption(nAlgorithm); -// if (!p) -// return false; -// -// value = p->GetIntValue(skey, nDefault); - return true; -} - -bool CAlgorithmShare::GetStringValue(int nAlgorithm, const QString& skey, QString& value, const QString& default) -{ -// IAlgorithmOption* p = m_pCoreCtrl->IGetAlgorithmOption(nAlgorithm); -// if (!p) -// return false; -// -// value = p->GetStringValue(skey, default); - return true; -} -//void CAlgorithmShare::SetValue(const QString& key, const QVariant& value, AlgoParamType type, int idx /* = -1 */) -//{ -// LP_ALGORITHM_PARAM* p = new LP_ALGORITHM_PARAM; -// -// p->nID = LP_DETECTOR_INVALID_ID; -// p->nSrcAlgoID = LP_DETECTOR_INVALID_ID; -// p->nSrcParamID = LP_DETECTOR_INVALID_ID; -// p->strName = key; -// p->type = type; -// p->value = value; -// p->strDescription = ""; -// p->bIsSave = false; -// -// -// QVector* pGroup = m_mapParamGroup[idx]; -// if (!p) -// { -// m_mapParamGroup.remove(idx); -// pGroup = new QVector < PLP_ALGORITHM_PARAM > ; -// m_mapParamGroup.insert(idx, pGroup); -// } -// -// pGroup->push_back(p); -//} -// -//QVariant CAlgorithmShare::GetValue(const QString& key, AlgoParamType& type, int idx /* = -1 */) -//{ -// QVector* pGroup = m_mapParamGroup[idx]; -// if (!pGroup) -// return false; -// -// for (QVector::iterator iter = pGroup->begin(); -// iter != pGroup->end(); ++iter) -// { -// if (NULL != *iter) -// { -// PLP_ALGORITHM_PARAM p = *iter; -// if (p->strName == key) -// { -// type = p->type; -// return p->value; -// } -// -// } -// -// } -// -// return NULL; -//} \ No newline at end of file diff --git a/src/lpbengine/AlgorithmShare.h b/src/lpbengine/AlgorithmShare.h deleted file mode 100644 index d4630b8..0000000 --- a/src/lpbengine/AlgorithmShare.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef ALGORITHMSHARE_H -#define ALGORITHMSHARE_H -#include "lpbengine.h" -#include "iCoreCtrl.h" - - -class CAlgorithmShare : public IAlgorithmShare -{ -public: - CAlgorithmShare(); - virtual ~CAlgorithmShare(); - - virtual bool Initialize(); - - virtual PLP_ALGORITHM_PARAM AddParam(const PLP_ALGORITHM_PARAM pParam, int idx = -1 ); - virtual bool DeleteParam(QString strName, int idx = -1); - virtual PLP_ALGORITHM_PARAM GetParam(QString strName, int idx = -1); - virtual QStringList GroupList(); - virtual QStringList ParamList(int idx = -1); - - virtual bool RegisterCoreCtrl(class ICoreCtrl* pCoreCtrl = NULL); - virtual bool GetIntValue(int nAlgorithm, const QString& skey, QString& value, int nDefault); - virtual bool GetStringValue(int nAlgorithm, const QString& skey, QString& value, const QString& default = ""); - - //virtual void SetValue(const QString& key, const QVariant& value, AlgoParamType type, int idx = -1); - //virtual QVariant GetValue(const QString& key, AlgoParamType& type, int idx = -1); - bool SerializeToJson(QJsonArray* pGroupArray, int nGroupID, QVector* pGroup); - bool SerializeFromJson(QJsonObject* pJsonObject); - virtual bool Save(); - virtual bool Load(); - - void CleanUp(); -private: - QMutex m_mutex; - QMap*> m_mapParamGroup; - - class ICoreCtrl* m_pCoreCtrl; -}; - - - -#endif // ALGORITHMSHARE_H \ No newline at end of file diff --git a/src/lpbengine/BEApp.cpp b/src/lpbengine/BEApp.cpp deleted file mode 100644 index 3986f8b..0000000 --- a/src/lpbengine/BEApp.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "BEApp.h" - -CBEApp::CBEApp() : m_mutex(QMutex::Recursive), m_pEngine(NULL), m_pSink(NULL) -{ - -} - -CBEApp::~CBEApp() -{ - -} - -bool CBEApp::Initialize(IDetectorEngine** lppBE, IDetectorEngineSink* lpSink) -{ - QMutexLocker locker(&m_mutex); - if (!lppBE) - return false; - - if (m_pEngine) - { - *lppBE = (IDetectorEngine*)m_pEngine; - return true; - } - - m_pEngine = new CDetectorEngine(); - - if (!m_pEngine) - return false; - - if (!m_pEngine->Initialize()) - return false; - - *lppBE = (IDetectorEngine*)m_pEngine; - - if (!m_pSink) - m_pSink = lpSink; - - qWarning("load engine success"); - return true; - -} - -bool CBEApp::Quit() -{ - QMutexLocker locker(&m_mutex); - if (m_pEngine) - { - delete m_pEngine; - m_pEngine = NULL; - } - - return true; -} \ No newline at end of file diff --git a/src/lpbengine/BEApp.h b/src/lpbengine/BEApp.h deleted file mode 100644 index 68bb986..0000000 --- a/src/lpbengine/BEApp.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef BEAPP_H -#define BEAPP_H - -#include "lpbengine.h" -#include "BusinessEngine.h" - -class CBEApp -{ -public: - CBEApp(); - virtual ~CBEApp(); - bool Initialize(IDetectorEngine** lppBE, IDetectorEngineSink* lpSink); - bool Quit(); - const CDetectorEngine *GetEngine() const { return m_pEngine; } - -private: - - CDetectorEngine* m_pEngine; - QMutex m_mutex; - - IDetectorEngineSink* m_pSink; -}; - - -#endif // BEAPP_H \ No newline at end of file diff --git a/src/lpbengine/BusinessEngine.cpp b/src/lpbengine/CDetectorEngine.cpp similarity index 52% rename from src/lpbengine/BusinessEngine.cpp rename to src/lpbengine/CDetectorEngine.cpp index e6aeec6..f23b85e 100644 --- a/src/lpbengine/BusinessEngine.cpp +++ b/src/lpbengine/CDetectorEngine.cpp @@ -1,6 +1,23 @@ -#include "BusinessEngine.h" +#include "CDetectorEngine.h" -LP_GLOBAL_DETECTOR_ENGINE gpEngine; +LPBENGINE_EXPORT IDetectorEngine* Lib_Engine_Init(void) +{ + CDetectorEngine* gpDetectEngine = nullptr; + if (nullptr == gpDetectEngine) + { + gpDetectEngine = new CDetectorEngine(); + } + return gpDetectEngine; +} + +LPBENGINE_EXPORT void Lib_Engine_Free(IDetectorEngine* ptr) +{ + if (ptr != nullptr) + { + delete ptr; + ptr = nullptr; + } +} CDetectorEngine::CDetectorEngine() { @@ -12,34 +29,14 @@ CDetectorEngine::~CDetectorEngine() } -bool CDetectorEngine::GetDataInterface(InterfaceType type, void **lppInterface) +IAlgorithmLibMgr* CDetectorEngine::getAlgorithmLibMgr() const { - if (!lppInterface) - return false; - - if (type == SOLUTIONMGR) - { - *lppInterface = (void**)&m_SolutionMgr; - } - else if (type == DEVICEMGR) - { - *lppInterface = (void**)&m_DeviceMgr; - } - else if (type == SYSTEMINFO) - { - *lppInterface = (void**)&m_SystemInfo; - } - else if (type == SHAREAPARAM) - { - *lppInterface = (void **)&m_AlgoShare; - } - else if (type == ALGORITHMLIBMGR) - { - *lppInterface = (void**)&m_AlgoLibMgr; - } - + return (IAlgorithmLibMgr*)&m_AlgoLibMgr; +} - return true; +IDetectorSolutionMgr* CDetectorEngine::getSolutionMgr() const +{ + return (IDetectorSolutionMgr*)&m_SolutionMgr; } bool CDetectorEngine::CheckConfigFolder() @@ -47,10 +44,8 @@ bool CDetectorEngine::CheckConfigFolder() QString strExePath = QCoreApplication::applicationDirPath(); QString strDirPath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_SOLUTION_DIR; QDir dir(strDirPath); - if (!dir.exists()) - { - if (!dir.mkdir(strDirPath)) - { + if (!dir.exists()) { + if (!dir.mkdir(strDirPath)) { qErrnoWarning("create solution dir fail"); return false; } @@ -58,10 +53,8 @@ bool CDetectorEngine::CheckConfigFolder() strDirPath = strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR; dir.setPath(strDirPath); - if (!dir.exists()) - { - if (!dir.mkdir(strDirPath)) - { + if (!dir.exists()) { + if (!dir.mkdir(strDirPath)) { qErrnoWarning("create images dir fail"); return false; } @@ -69,10 +62,8 @@ bool CDetectorEngine::CheckConfigFolder() strDirPath = strExePath + LP_DETECTOR_BUSSINESS_IN_PARAM_FILE_DIR; dir.setPath(strDirPath); - if (!dir.exists()) - { - if (!dir.mkdir(strDirPath)) - { + if (!dir.exists()) { + if (!dir.mkdir(strDirPath)) { qErrnoWarning("create paramfiles dir fail"); return false; } @@ -80,42 +71,24 @@ bool CDetectorEngine::CheckConfigFolder() strDirPath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_ALGO_DIR; dir.setPath(strDirPath); - if (!dir.exists()) - { - if (!dir.mkdir(strDirPath)) - { + if (!dir.exists()) { + if (!dir.mkdir(strDirPath)) { qErrnoWarning("create algorithmLib dir fail"); return false; } } - return true; } bool CDetectorEngine::Initialize() { - if (!m_AlgoLibMgr.Initialize(&m_SystemInfo)) - return false; - - if (!m_AlgoShare.Initialize()) - return false; - - if (!m_SolutionMgr.Initialize(&m_SystemInfo,&m_AlgoShare, &m_AlgoLibMgr)) - return false; - - if (!m_DeviceMgr.Initialize()) + if (!m_SolutionMgr.Initialize(&m_AlgoLibMgr)) return false; if (!Load()) { qWarning() << "Initialize, m_AlgoLibMgr load failed"; return false; } - - gpEngine.pSolutionMgr = &m_SolutionMgr; - gpEngine.pAlgoLibMgr = &m_AlgoLibMgr; - gpEngine.pAlgoShare = &m_AlgoShare; - gpEngine.pDeviceMgr = &m_DeviceMgr; - gpEngine.pSystemInfo = &m_SystemInfo; return true; } @@ -129,10 +102,6 @@ bool CDetectorEngine::Save() if (!m_SolutionMgr.Save()) return false; - - if (!m_AlgoShare.Save()) - return false; - return true; } @@ -145,15 +114,10 @@ bool CDetectorEngine::SaveTasks(QStringList strTaskNames) bool CDetectorEngine::Load() { - //临时通过camera.json加载设备信息 if (!m_AlgoLibMgr.Load()) return false; - if (!m_SolutionMgr.Load()) return false; - - if (!m_AlgoShare.Load()) - return false; - return true; -} \ No newline at end of file +} + diff --git a/src/lpbengine/BusinessEngine.h b/src/lpbengine/CDetectorEngine.h similarity index 54% rename from src/lpbengine/BusinessEngine.h rename to src/lpbengine/CDetectorEngine.h index 689393d..a1f81ea 100644 --- a/src/lpbengine/BusinessEngine.h +++ b/src/lpbengine/CDetectorEngine.h @@ -3,17 +3,15 @@ #include "lpbengine.h" #include "SolutionMgr.h" -#include "DeviceMgr.h" -#include "SystemInfo.h" -#include "AlgorithmShare.h" #include "AlgorithmLibMgr.h" -class CDetectorEngine : IDetectorEngine +class CDetectorEngine:public IDetectorEngine { public: CDetectorEngine(); ~CDetectorEngine(); - virtual bool GetDataInterface(InterfaceType type, void **lppInterface); + IAlgorithmLibMgr* getAlgorithmLibMgr() const; + IDetectorSolutionMgr* getSolutionMgr() const; bool Initialize(); virtual bool Save(); virtual bool SaveTasks(QStringList strTaskNames); @@ -22,13 +20,7 @@ public: bool CheckConfigFolder(); private: CDetectorSolutionMgr m_SolutionMgr; - CDetectorDeviceMgr m_DeviceMgr; - CDetectorSystemInfo m_SystemInfo; - CAlgorithmShare m_AlgoShare; CAlgorithmLibMgr m_AlgoLibMgr; - - ICoreCtrl* m_pCoreCtrl; }; - #endif // BUSINESSENGINE_H \ No newline at end of file diff --git a/src/lpbengine/Camera.cpp b/src/lpbengine/Camera.cpp deleted file mode 100644 index 9cebe72..0000000 --- a/src/lpbengine/Camera.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "Camera.h" - -CDetectorCameraDevice::CDetectorCameraDevice() : m_mutexLocker(QMutex::Recursive) -{ - m_pCoreCtrl = NULL; - m_callBackOwner = NULL; - m_pFunc = NULL; -} - -CDetectorCameraDevice::~CDetectorCameraDevice() -{ - -} - -bool CDetectorCameraDevice::Initialize(IDetectorEngineSink* lpSink) -{ - m_pSink = lpSink; - return true; -} - -bool CDetectorCameraDevice::RegisterCoreCtrl(class ICoreCtrl* pCoreCtrl) -{ - if (!pCoreCtrl) - return false; - - m_pCoreCtrl = pCoreCtrl; - return true; -} - -void CDetectorCameraDevice::AddParam(const QString &key, const QVariant &value) -{ - m_mapParam.insert(key, value); -} - -bool CDetectorCameraDevice::DeleteParam(const QString &key) -{ - m_mapParam.remove(key); - return true; -} - -QMap CDetectorCameraDevice::GetParamMap() -{ - return m_mapParam; -} - -bool CDetectorCameraDevice::SetID(int nID) -{ - m_nID = nID; - return true; -} - -int CDetectorCameraDevice::GetID() -{ - return m_nID; -} - -bool CDetectorCameraDevice::SetType(DeviceType type) -{ - m_type = type; - return true; -} - -DeviceType CDetectorCameraDevice::GetType() -{ - return m_type; -} - -bool CDetectorCameraDevice::SetName(QString strName) -{ - m_strName = strName; - return true; -} - -QString CDetectorCameraDevice::GetName() -{ - return m_strName; -} - -bool CDetectorCameraDevice::SetDescription(QString strDescription) -{ - m_strDescription = strDescription; - return true; -} - -QString CDetectorCameraDevice::GetDescription() -{ - return m_strDescription; -} - -void CDetectorCameraDevice::SnapImage(void* callBackOwner, NewImageHandler pFunc) -{ - RegisterImageHandler(callBackOwner, pFunc); - QStringList strKeys; - strKeys.append(m_strName); - return m_pCoreCtrl->ISnapImage(strKeys); -} - -void CDetectorCameraDevice::RegisterImageHandler(void* callBackOwner, NewImageHandler pFunc) -{ - QMutexLocker locker(&m_mutexLocker); - m_callBackOwner = callBackOwner; - m_pFunc = pFunc; -} - -void CDetectorCameraDevice::UnRegisterImageHandler() -{ - m_callBackOwner = NULL; - m_pFunc = NULL; -} - -bool CDetectorCameraDevice::HandleNewImage(cv::Mat& img, int nDeviceID) -{ - QMutexLocker locker(&m_mutexLocker); - if (!m_pFunc) - return false; - - - m_pFunc(m_callBackOwner, EngineBase::convMat2QImage(img), nDeviceID); - UnRegisterImageHandler(); - return true; -} - -bool CDetectorCameraDevice::OpenDevice() -{ - if (!m_pCoreCtrl) - return false; - - return m_pCoreCtrl->IOpenCamera(m_strName); -} - -bool CDetectorCameraDevice::CloseDevice() -{ - if (!m_pCoreCtrl) - return false; - - return m_pCoreCtrl->ICloseCamera(m_strName); -} - -bool CDetectorCameraDevice::StartDevice() -{ - if (!m_pCoreCtrl) - return false; - - return m_pCoreCtrl->IStartCamera(m_strName); -} - -bool CDetectorCameraDevice::StopDevice() -{ - if (!m_pCoreCtrl) - return false; - - return m_pCoreCtrl->IStopCamera(m_strName); -} - -void CDetectorCameraDevice::Release() -{ - delete this; -} - -bool CDetectorCameraDevice::SerializeToJson(QJsonDocument* pJsonDocument, QJsonArray* pDeviceArray) -{ - if (!pDeviceArray) - return false; - - QJsonObject jsonObject; - jsonObject.insert("device_id", m_nID); - jsonObject.insert("device_type", m_type); - jsonObject.insert("device_name", m_strName); - jsonObject.insert("device_description", m_strDescription); - - pDeviceArray->push_back(jsonObject); - - return true; -} - -bool CDetectorCameraDevice::SerializeFromJson(QJsonObject* pJsonObject) -{ - if (!pJsonObject) - return false; - - m_nID = pJsonObject->value("device_id").toInt(); - m_type = (DeviceType)pJsonObject->value("device_type").toInt(); - m_strName = pJsonObject->value("device_name").toString(); - m_strDescription = pJsonObject->value("device_description").toString(); - - return true; -} \ No newline at end of file diff --git a/src/lpbengine/Camera.h b/src/lpbengine/Camera.h deleted file mode 100644 index a0cdc43..0000000 --- a/src/lpbengine/Camera.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef CAMERA_H -#define CAMERA_H - -#include "lpbengine.h" -#include "iCoreCtrl.h" - -class CDetectorCameraDevice : public IDetectorCameraDevice -{ -public: - CDetectorCameraDevice(); - virtual ~CDetectorCameraDevice(); - bool Initialize(IDetectorEngineSink* lpSink); - - virtual bool SetID(int nID); - virtual int GetID(); - virtual bool SetType(DeviceType type); - virtual DeviceType GetType(); - virtual bool SetName(QString strName); - virtual QString GetName(); - virtual bool SetDescription(QString strDescription); - virtual QString GetDescription(); - - virtual void Release(); - bool SerializeToJson(QJsonDocument* pJsonDocument, QJsonArray* pDeviceArray); - bool SerializeFromJson(QJsonObject* pJsonObject); - - virtual void AddParam(const QString &key, const QVariant &value); - virtual bool DeleteParam(const QString &key); - virtual QMap GetParamMap(); - - bool RegisterCoreCtrl(class ICoreCtrl* pCoreCtrl); - - virtual void SnapImage(void* callBackOwner, NewImageHandler pFunc); - virtual void RegisterImageHandler(void* callBackOwner, NewImageHandler pFunc); - virtual void UnRegisterImageHandler(); - virtual bool HandleNewImage(cv::Mat& img, int nDeviceID); - - virtual bool OpenDevice(); - virtual bool CloseDevice(); - virtual bool StartDevice(); - virtual bool StopDevice(); -private: - int m_nID; - QString m_strName; - QString m_strDescription; - DeviceType m_type; - - IDetectorEngineSink* m_pSink; - QMap m_mapParam; - - ICoreCtrl* m_pCoreCtrl; - NewImageHandler m_pFunc; - void* m_callBackOwner; - - QMutex m_mutexLocker; -}; - -#endif // CAMERA_H \ No newline at end of file diff --git a/src/lpbengine/DeviceMgr.cpp b/src/lpbengine/DeviceMgr.cpp deleted file mode 100644 index ab30aa8..0000000 --- a/src/lpbengine/DeviceMgr.cpp +++ /dev/null @@ -1,274 +0,0 @@ -#include "DeviceMgr.h" -#include "Camera.h" - -CDetectorDeviceMgr::CDetectorDeviceMgr() -{ - m_nBaseID = 0; - m_vecDevice.clear(); - m_pCoreCtrl = NULL; -} - -CDetectorDeviceMgr::~CDetectorDeviceMgr() -{ - while (m_vecDevice.size()>0) - { - IDetectorDevice *pItem = m_vecDevice.takeFirst(); - delete pItem; - pItem = NULL; - } -} - -bool CDetectorDeviceMgr::Initialize() -{ - return true; -} - -bool CDetectorDeviceMgr::RegisterCoreCtrl(class ICoreCtrl* pCoreCtrl /* = NULL */) -{ - if (!pCoreCtrl) - return false; - - m_pCoreCtrl = pCoreCtrl; - return true; -} - -IDetectorDevice* CDetectorDeviceMgr::AddDevice(DeviceType type) -{ - switch (type) - { - case CAMERA: - { - CDetectorCameraDevice* p = new CDetectorCameraDevice(); - p->SetID(NewID()); - p->SetType(type); - p->RegisterCoreCtrl(m_pCoreCtrl); - m_vecDevice.push_back(p); - return p; - } - default: - break; - } - return NULL; -} - -bool CDetectorDeviceMgr::DeleteDevice(int nDeviceID) -{ - for (QVector::iterator iter = m_vecDevice.begin(); iter != m_vecDevice.end(); ++iter) - { - if (iter) - { - IDetectorDevice* p = *iter; - if (p->GetID() == nDeviceID) - { - p->Release(); - iter = m_vecDevice.erase(iter); - return true; - } - } - } - - return false; -} - -IDetectorDevice* CDetectorDeviceMgr::GetDevice(int nDeviceID, DeviceType &type) -{ - for (QVector::iterator iter = m_vecDevice.begin(); - iter != m_vecDevice.end(); ++iter) - { - if (*iter) - { - IDetectorDevice *p = *iter; - if (p->GetID() == nDeviceID) - { - type = p->GetType(); - return *iter; - } - } - - } - - return NULL; -} - -IDetectorDevice* CDetectorDeviceMgr::GetDeviceByName(QString strName, DeviceType &type) -{ - for (QVector::iterator iter = m_vecDevice.begin(); - iter != m_vecDevice.end(); ++iter) - { - if (*iter) - { - IDetectorDevice *p = *iter; - if (p->GetName() == strName) - { - type = p->GetType(); - return *iter; - } - } - - } - - return NULL; -} - -int CDetectorDeviceMgr::EnumDevice(IDetectorDevice** lppDevice, int nCount) -{ - if (!lppDevice || nCount < m_vecDevice.size()) - return m_vecDevice.size(); - - int nIndex = 0; - for (QVector::iterator iter = m_vecDevice.begin(); - iter != m_vecDevice.end(); ++iter) - { - if (NULL != *iter) - { - lppDevice[nIndex] = *iter; - nIndex++; - } - } - - return nIndex; -} - -void CDetectorDeviceMgr::CleanUp() -{ - for (QVector::iterator iter = m_vecDevice.begin(); - iter != m_vecDevice.end(); ++iter) - { - if (*iter) - { - (*iter)->Release(); - } - } - - m_vecDevice.clear(); -} - -QByteArray CDetectorDeviceMgr::SerializeToJson() -{ - QJsonDocument document; - - QJsonObject jsonObject; - jsonObject.insert("device_base_id", m_nBaseID); - - QJsonArray deviceArray; - for (QVector::iterator iter = m_vecDevice.begin(); - iter != m_vecDevice.end(); ++iter) - { - if (*iter) - { - IDetectorDevice* p = (IDetectorDevice*)*iter; - switch (p->GetType()) - { - case CAMERA: - { - CDetectorCameraDevice* pCamera = (CDetectorCameraDevice*)p; - if (!pCamera->SerializeToJson(&document, &deviceArray)) - return NULL; - break; - } - default: - break; - } - - } - } - - if (deviceArray.size() > 0) - { - jsonObject.insert("deviceArray", deviceArray); - } - - document.setObject(jsonObject); - return document.toJson(); -} - -bool CDetectorDeviceMgr::SerializeFromJson(QByteArray byteArray) -{ - if (byteArray.size() == 0) - return true; - - QJsonParseError parse_error; - QJsonDocument document = QJsonDocument::fromJson(byteArray, &parse_error); - if (parse_error.error == QJsonParseError::NoError) - { - if (!document.isEmpty() && !document.isNull()) - { - if (document.isObject()) - { - QJsonObject deviceMgr = document.object(); - - QJsonArray deviceArray = deviceMgr.value("deviceArray").toArray(); - for (int i = 0; i < deviceArray.size(); i++) - { - QJsonObject jsonObject = deviceArray[i].toObject(); - DeviceType type = (DeviceType)jsonObject.value("device_type").toInt(); - - switch (type) - { - case CAMERA: - { - CDetectorCameraDevice* pCamera = (CDetectorCameraDevice*)AddDevice(type); - if (!pCamera->SerializeFromJson(&jsonObject)) - { - return false; - } - break; - } - default: - break; - } - } - - m_nBaseID = deviceMgr.value("device_base_id").toInt(); - - return true; - } - } - } - - return false; -} - -bool CDetectorDeviceMgr::Save() -{ - QByteArray byteArray = SerializeToJson(); - if (byteArray.isNull()) - return false; - - QString strExePath = QCoreApplication::applicationDirPath(); - QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_DEVICEMGR_FILE; - QFile file(strFilePath); - if (file.open(QFile::WriteOnly)) - { - file.write(byteArray); - return true; - } - - return false; -} - -bool CDetectorDeviceMgr::Load() -{ - QByteArray byteArray; - QString strExePath = QCoreApplication::applicationDirPath(); - QString strFilePath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_DEVICEMGR_FILE; - QFile file(strFilePath); - - if (!file.exists()) - { - file.open(QIODevice::ReadWrite); - file.close(); - return true; - } - - if (!file.open(QIODevice::ReadOnly)) - { - return false; - } - - byteArray = file.readAll(); - if (!SerializeFromJson(byteArray)) - return false; - - return true; -} diff --git a/src/lpbengine/DeviceMgr.h b/src/lpbengine/DeviceMgr.h deleted file mode 100644 index 6a74375..0000000 --- a/src/lpbengine/DeviceMgr.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef DEVICEMGR_H -#define DEVICEMGR_H - -#include "lpbengine.h" - -class CDetectorDeviceMgr : public IDetectorDeviceMgr -{ -public: - CDetectorDeviceMgr(); - virtual ~CDetectorDeviceMgr(); - virtual IDetectorDevice* AddDevice(DeviceType type); - virtual bool DeleteDevice(int nDeviceID); - virtual IDetectorDevice* GetDevice(int nDeviceID, DeviceType &type); - virtual IDetectorDevice* GetDeviceByName(QString strName, DeviceType &type); - virtual int EnumDevice(IDetectorDevice** lppDevice, int nCount); - virtual bool Initialize(); - - void CleanUp(); - int NewID(){return ++m_nBaseID; } - - QByteArray SerializeToJson(); - bool SerializeFromJson(QByteArray byteArray); - - virtual bool Save(); - virtual bool Load(); - - virtual bool RegisterCoreCtrl(class ICoreCtrl* pCoreCtrl = NULL); -private: - int m_nBaseID; - QVector m_vecDevice; - - class ICoreCtrl* m_pCoreCtrl; -}; - -#endif // DEVICEMGR_H \ No newline at end of file diff --git a/src/lpbengine/Solution.cpp b/src/lpbengine/Solution.cpp index b990ff6..286e060 100644 --- a/src/lpbengine/Solution.cpp +++ b/src/lpbengine/Solution.cpp @@ -7,8 +7,7 @@ CDetectorSolution::CDetectorSolution() : m_mutex(QMutex::Recursive) m_nBaseID = 0; m_bIsRun = false; m_bIsModify = false; - m_pAlgoShare = NULL; - //m_vecTask.clear(); + } CDetectorSolution::~CDetectorSolution() @@ -16,13 +15,11 @@ CDetectorSolution::~CDetectorSolution() CleanUp(); } -bool CDetectorSolution::Initialize(IDetectorSystemInfo* pSystemInfo, - IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr) +bool CDetectorSolution::Initialize(IAlgorithmLibMgr* pAlgoLibMgr) { - if ( !pAlgoShare || !pAlgoLibMgr) + if (!pAlgoLibMgr) return false; - m_pSystemInfo = pSystemInfo; - m_pAlgoShare = pAlgoShare; + m_pAlgoLibMgr = pAlgoLibMgr; return true; @@ -51,17 +48,18 @@ IDetectorTask* CDetectorSolution::AddTask(const PLP_DETECTOR_TASK pTask, QString CDetectorTask* p = new CDetectorTask(); - if (p->Initialize(this, m_pSystemInfo, m_pAlgoShare, m_pAlgoLibMgr) && p->SetTaskInfo(pTask)) + if (p->Initialize(this, m_pAlgoLibMgr) && p->SetTaskInfo(pTask)) { p->SetID(++m_nBaseID); p->LoadFile(strPath); - //m_vecTask.push_back(p); m_TaskMapByID.insert(p->GetID(), p); m_TaskMapByName.insert(p->GetTaskInfo()->strName, p); return p; } - - delete p; + else { + delete p; + } + return NULL; } @@ -71,7 +69,7 @@ bool CDetectorSolution::AddTaskByCopy(IDetectorTask* pSrc) return false; CDetectorTask* p = new CDetectorTask(); PLP_DETECTOR_TASK pTask = pSrc->GetTaskInfo(); - if (p->Initialize(this, m_pSystemInfo, m_pAlgoShare, m_pAlgoLibMgr) && p->SetTaskInfo(pTask)) + if (p->Initialize(this, m_pAlgoLibMgr) && p->SetTaskInfo(pTask)) { p->SetID(++m_nBaseID); p->Copy(pSrc); @@ -91,7 +89,7 @@ IDetectorTask* CDetectorSolution::AddTask(const PLP_DETECTOR_TASK pTask, bool bR CDetectorTask* p = new CDetectorTask(); - if (p->Initialize(this, m_pSystemInfo, m_pAlgoShare, m_pAlgoLibMgr) && p->SetTaskInfo(pTask)) + if (p->Initialize(this, m_pAlgoLibMgr) && p->SetTaskInfo(pTask)) { p->SetID(++m_nBaseID); m_TaskMapByID.insert(p->GetID(), p); @@ -525,7 +523,7 @@ IDetectorSolution* CDetectorSolution::Copy() { QMutexLocker locker(&m_mutex); CDetectorSolution* pNewSolution = new CDetectorSolution(); - pNewSolution->Initialize(m_pSystemInfo,m_pAlgoShare, m_pAlgoLibMgr); + pNewSolution->Initialize(m_pAlgoLibMgr); pNewSolution->SetID(m_nID); if (!pNewSolution->SetSolutionInfo(&m_tSolutionInfo)) diff --git a/src/lpbengine/Solution.h b/src/lpbengine/Solution.h index 09bab4b..a1d2589 100644 --- a/src/lpbengine/Solution.h +++ b/src/lpbengine/Solution.h @@ -30,7 +30,7 @@ public: virtual void SetModifyFlag(bool bModify); virtual IDetectorTask* GetTaskByCameraID(int nCameraID); - bool Initialize(IDetectorSystemInfo* pSystemInfo, IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr); + bool Initialize(/*IAlgorithmShare* pAlgoShare,*/ IAlgorithmLibMgr* pAlgoLibMgr); void CleanUp(); virtual IDetectorSolution* Copy(); virtual bool Copy(IDetectorSolution* pSrcSolution, bool bRet = true); @@ -65,8 +65,7 @@ private: QMap m_TaskMapByID; QMap m_CurRunTaskMap;//CamID(int),TaskPtr(IDetectorTask*) - IDetectorSystemInfo* m_pSystemInfo; - IAlgorithmShare* m_pAlgoShare; +// IAlgorithmShare* m_pAlgoShare; IAlgorithmLibMgr* m_pAlgoLibMgr; QMutex m_mutex; diff --git a/src/lpbengine/SolutionMgr.cpp b/src/lpbengine/SolutionMgr.cpp index 12ad032..ef0746a 100644 --- a/src/lpbengine/SolutionMgr.cpp +++ b/src/lpbengine/SolutionMgr.cpp @@ -1,13 +1,11 @@ #include "SolutionMgr.h" #include "Solution.h" -CDetectorSolutionMgr::CDetectorSolutionMgr() : m_lock(QMutex::Recursive) +CDetectorSolutionMgr::CDetectorSolutionMgr() { m_nBaseID = 0; m_nRunSolutionID = LP_DETECTOR_INVALID_ID; m_vecSolution.clear(); - m_vecSink.clear(); - m_pAlgoShare = NULL; } CDetectorSolutionMgr::~CDetectorSolutionMgr() @@ -15,13 +13,9 @@ CDetectorSolutionMgr::~CDetectorSolutionMgr() CleanUp(); } -bool CDetectorSolutionMgr::Initialize(IDetectorSystemInfo* pSystemInfo, - IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr) +bool CDetectorSolutionMgr::Initialize(IAlgorithmLibMgr* pAlgoLibMgr) { - m_pSystemInfo = pSystemInfo; - m_pAlgoShare = pAlgoShare; m_pAlgoLibMgr = pAlgoLibMgr; - return true; } @@ -32,10 +26,10 @@ IDetectorSolution* CDetectorSolutionMgr::AddSolution(const PLP_DETECTOR_SOLUTION CDetectorSolution* p = new CDetectorSolution(); - if (p->Initialize(m_pSystemInfo, m_pAlgoShare, m_pAlgoLibMgr) && p->SetSolutionInfo(pSolution)) + if (p->Initialize(m_pAlgoLibMgr) && p->SetSolutionInfo(pSolution)) { p->SetID(++m_nBaseID); - m_vecSolution.push_back(p); + m_vecSolution.insert(m_nBaseID, p); return p; } @@ -48,59 +42,29 @@ bool CDetectorSolutionMgr::DeleteSolution(int nSolutionID) if (m_nRunSolutionID == nSolutionID) m_nRunSolutionID = LP_DETECTOR_INVALID_ID; - for (QVector::iterator iter = m_vecSolution.begin(); - iter != m_vecSolution.end(); ++iter) + QMap::iterator it = m_vecSolution.find(nSolutionID); + if (it != m_vecSolution.end()) { - IDetectorSolution *p = *iter; - - if (NULL != p) - { - if (p->GetID() == nSolutionID) - { - delete *iter; - iter = m_vecSolution.erase(iter); - - if (nSolutionID == m_nRunSolutionID) - m_nRunSolutionID = LP_DETECTOR_INVALID_ID; - - return true; - } - } + m_vecSolution.erase(it); } + return false; } IDetectorSolution* CDetectorSolutionMgr::GetSolution(int nSolutionID) { -//只有一个solution且没设置启用的solution时,默认选择第一个solution - if (m_vecSolution.size() == 1){ - QVector::iterator iter = m_vecSolution.begin(); - if (*iter != NULL) - { - IDetectorSolution *p = *iter; - p->SetRunState(true); - return p; - } - } - - for (QVector::iterator iter = m_vecSolution.begin(); - iter != m_vecSolution.end(); ++iter) + QMap::iterator it = m_vecSolution.find(nSolutionID); + if (it != m_vecSolution.end()) { - if (NULL != *iter) - { - IDetectorSolution *p = *iter; - if (p->GetID() == nSolutionID) - return p; - } - + (*it)->SetRunState(true); + return (*it); } - return NULL; } bool CDetectorSolutionMgr::CheckSolution(int nSolutionID, QString strSolutionName) { - for (QVector::iterator iter = m_vecSolution.begin(); + for (QMap::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++iter) { if (NULL != *iter) @@ -109,7 +73,6 @@ bool CDetectorSolutionMgr::CheckSolution(int nSolutionID, QString strSolutionNam if (p->GetID() == nSolutionID && p->GetSolutionInfo()->strName == strSolutionName) return true; } - } return false; @@ -121,7 +84,7 @@ int CDetectorSolutionMgr::EnumSolution(IDetectorSolution** lppSolution, int nCou return m_vecSolution.size(); int nIndex = 0; - for (QVector::iterator iter = m_vecSolution.begin(); + for (QMap::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++iter) { if (NULL != *iter) @@ -136,7 +99,7 @@ int CDetectorSolutionMgr::EnumSolution(IDetectorSolution** lppSolution, int nCou void CDetectorSolutionMgr::CleanUp() { - for (QVector::iterator iter = m_vecSolution.begin(); + for (QMap::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++iter) { if (*iter) @@ -151,12 +114,9 @@ void CDetectorSolutionMgr::CleanUp() bool CDetectorSolutionMgr::Save() { QJsonDocument document; - - m_pSystemInfo->SetValue("RunSolution", m_nRunSolutionID); - QString strExePath = QCoreApplication::applicationDirPath(); /*耗时过长*/ - for (QVector::iterator iter = m_vecSolution.begin(); + for (QMap::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++iter) { if (*iter) @@ -212,12 +172,9 @@ bool CDetectorSolutionMgr::Save() bool CDetectorSolutionMgr::SaveByNames(QStringList strNames) { QJsonDocument document; - - m_pSystemInfo->SetValue("RunSolution", m_nRunSolutionID); - QString strExePath = QCoreApplication::applicationDirPath(); /*耗时过长*/ - for (QVector::iterator iter = m_vecSolution.begin(); + for (QMap::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++iter) { if (*iter) @@ -271,7 +228,6 @@ bool CDetectorSolutionMgr::SaveByNames(QStringList strNames) bool CDetectorSolutionMgr::Load() { - QString strExePath = QCoreApplication::applicationDirPath(); QString strSolutionDirPath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_SOLUTION_DIR; QDir solutionDir(strSolutionDirPath); @@ -280,7 +236,7 @@ bool CDetectorSolutionMgr::Load() solutionDir.mkdir(strSolutionDirPath); } - m_nRunSolutionID = m_pSystemInfo->GetValue("RunSolution").toInt() > 0 ? m_pSystemInfo->GetValue("RunSolution").toInt() : LP_DETECTOR_INVALID_ID; + m_nRunSolutionID = 1; solutionDir.setFilter(QDir::Dirs | QDir::Hidden | QDir::NoSymLinks); solutionDir.setSorting(QDir::Size | QDir::Reversed); @@ -328,7 +284,6 @@ bool CDetectorSolutionMgr::Load() if (pSolution) nBaseID = pSolution->GetID() > nBaseID ? pSolution->GetID() : nBaseID; } - ///// m_nBaseID = nBaseID; @@ -342,57 +297,27 @@ bool CDetectorSolutionMgr::LoadByNames(QStringList strNames) bool CDetectorSolutionMgr::ReLoad() { - QMutexLocker locker(&m_lock); CleanUp(); - m_nBaseID = 0; m_nRunSolutionID = LP_DETECTOR_INVALID_ID; m_vecSolution.clear(); - //m_vecSink.clear(); return Load(); } bool CDetectorSolutionMgr::SetRunSolution(int nSolutionID) { - QMutexLocker locker(&m_lock); - m_nRunSolutionID = nSolutionID; IDetectorSolution* pRunSolution = GetSolution(nSolutionID); - for (QVector::iterator iter = m_vecSink.begin(); - iter != m_vecSink.end(); ++iter) - { - if (*iter) - { - IDetectorEngineSink* p = *iter; - p->ResetRunSolution(pRunSolution); - } - } - - //QWriteLocker locker(&m_lock); - //m_nRunSolutionID = nSolutionID; - return true; } IDetectorSolution* CDetectorSolutionMgr::GetRunSolution() { -// QReadLocker locker(&m_lock); return GetSolution(m_nRunSolutionID); } -void CDetectorSolutionMgr::RegistSink(IDetectorEngineSink* pSink) -{ - QMutexLocker locker(&m_lock); - m_vecSink.push_back(pSink); - - qWarning() << "Current Run Solution ID:" << m_nRunSolutionID; - - IDetectorSolution* pRunSolution = GetRunSolution(); - pSink->ResetRunSolution(pRunSolution); -} - IDetectorSolution* CDetectorSolutionMgr::AddAndCopySolution(IDetectorSolution* pSrcSolution) { if (!pSrcSolution) diff --git a/src/lpbengine/SolutionMgr.h b/src/lpbengine/SolutionMgr.h index 12942b5..23afb77 100644 --- a/src/lpbengine/SolutionMgr.h +++ b/src/lpbengine/SolutionMgr.h @@ -13,14 +13,11 @@ public: IDetectorSolution* GetSolution(int nSolutionID); int EnumSolution(IDetectorSolution** lppSolution, int nCount); void CleanUp(); - bool Initialize(IDetectorSystemInfo* pSystemInfo, IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr); - //QByteArray SerializeToJson(); - //bool SerializeFromJson(QByteArray byteArray); + bool Initialize(IAlgorithmLibMgr* pAlgoLibMgr); virtual bool SetRunSolution(int nSolutionID); virtual IDetectorSolution* GetRunSolution(); - virtual void RegistSink(IDetectorEngineSink* pSink); virtual IDetectorSolution* AddAndCopySolution(IDetectorSolution* pSrcSolution); virtual bool CheckSolution(int nSolutionID, QString strSolutionName); @@ -30,15 +27,9 @@ public: virtual bool LoadByNames(QStringList strNames); virtual bool ReLoad(); private: -// QReadWriteLock m_lock; - QMutex m_lock; - QVector m_vecSolution; + QMap m_vecSolution; int m_nBaseID; int m_nRunSolutionID; - - QVector m_vecSink; - IDetectorSystemInfo* m_pSystemInfo{ NULL }; - IAlgorithmShare* m_pAlgoShare{ NULL }; IAlgorithmLibMgr* m_pAlgoLibMgr{ NULL }; }; diff --git a/src/lpbengine/SystemInfo.cpp b/src/lpbengine/SystemInfo.cpp deleted file mode 100644 index 712a0e3..0000000 --- a/src/lpbengine/SystemInfo.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "SystemInfo.h" - -CDetectorSystemInfo::CDetectorSystemInfo() : systemSetIni(LP_DETECTOR_BUSSINESS_CONFIG_FILE_NAME, QSettings::IniFormat) -{ - systemSetIni.setIniCodec(QTextCodec::codecForName("UTF-8")); -} - -CDetectorSystemInfo::~CDetectorSystemInfo() -{ -} \ No newline at end of file diff --git a/src/lpbengine/SystemInfo.h b/src/lpbengine/SystemInfo.h deleted file mode 100644 index f118faa..0000000 --- a/src/lpbengine/SystemInfo.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SYSTEMINFO_H -#define SYSTEMINFO_H - -#include "lpbengine.h" - -class CDetectorSystemInfo : public IDetectorSystemInfo -{ -public: - CDetectorSystemInfo(); - virtual ~CDetectorSystemInfo(); - - virtual void SetValue(const QString &key, const QVariant &value){ systemSetIni.setValue(key, value); } - virtual QVariant GetValue(const QString &key, const QVariant &defaultValue = QVariant()){ return systemSetIni.value(key, defaultValue);} - - virtual void BeginGroup(const QString &prefix) { return systemSetIni.beginGroup(prefix); } - virtual void EndGroup() { return systemSetIni.endGroup(); } - virtual QStringList allKeys() { return systemSetIni.allKeys(); } - -private: - LP_DETECTOR_SYSTEM_INFO m_tSystemInfo; - QSettings systemSetIni; -}; - -#endif // SYSTEMINFO_H \ No newline at end of file diff --git a/src/lpbengine/Task.cpp b/src/lpbengine/Task.cpp index 24a4614..c65de07 100644 --- a/src/lpbengine/Task.cpp +++ b/src/lpbengine/Task.cpp @@ -9,7 +9,6 @@ CDetectorTask::CDetectorTask() m_nAlgorithmBaseID = 0; m_nRunAlgoID = LP_DETECTOR_INVALID_ID; m_pSolution = NULL; - m_pAlgoShare = NULL; m_vecROI.clear(); m_vecAlgorithm.clear(); m_bRunning = false; @@ -21,15 +20,11 @@ CDetectorTask::~CDetectorTask() CleanUp(); } -bool CDetectorTask::Initialize(IDetectorSolution* pSolution, IDetectorSystemInfo* pSystemInfo, - IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr) +bool CDetectorTask::Initialize(IDetectorSolution* pSolution, IAlgorithmLibMgr* pAlgoLibMgr) { - if (!pSolution || !pAlgoShare) + if (!pSolution ) return false; - m_pSolution = pSolution; - m_pSystemInfo = pSystemInfo; - m_pAlgoShare = pAlgoShare; m_pAlgoLibMgr = pAlgoLibMgr; return true; } @@ -134,7 +129,7 @@ IDetectorAlgorithm* CDetectorTask::AddAlgorithm(const PLP_DETECTOR_ALGORITHM pAl return NULL; CDetectorAlgorithm* p = new CDetectorAlgorithm(); - if (p->Initialize(this, m_pAlgoShare, m_pAlgoLibMgr) && p->SetAlgorithmInfo(pAlgorithm)) + if (p->Initialize(this, m_pAlgoLibMgr) && p->SetAlgorithmInfo(pAlgorithm)) { ++m_nAlgorithmBaseID; p->SetID(pAlgorithm->nID); @@ -624,7 +619,7 @@ bool CDetectorTask::Copy(IDetectorTask* pSrcTask, bool bRet /* = true */) { CDetectorAlgorithm* pNewAlgo = (CDetectorAlgorithm*)AddAlgorithm(lppAlgo[i]->GetAlgorithmInfo()); IDetectorAlgorithm* p = lppAlgo[i]; - if (pNewAlgo && pNewAlgo->Initialize(this, m_pAlgoShare, m_pAlgoLibMgr) && !pNewAlgo->Copy(lppAlgo[i])) + if (pNewAlgo && pNewAlgo->Initialize(this, m_pAlgoLibMgr) && !pNewAlgo->Copy(lppAlgo[i])) { delete[] lppAlgo; return false; @@ -656,20 +651,12 @@ bool CDetectorTask::Copy(IDetectorTask* pSrcTask, bool bRet /* = true */) delete[] lppROI; } - //QString strFileName = LP_DETECTOR_BUSSINESS_IMAGE_DIR + QString::number(m_pSolution->GetID()) + "_" + QString::number(m_nID) + ".bmp"; - //IplImage* pImage = cvLoadImage(strFileName.toLatin1().data()); - //m_tTask.pImg = pImage; - //m_tTask.pImg = NULL; - m_nAlgorithmBaseID = pSrcTask->GetAlgoBaseID(); - if (pSrcTask->GetRunAlgo()) - { + if (pSrcTask->GetRunAlgo()) { m_nRunAlgoID = pSrcTask->GetRunAlgo()->GetID(); } else m_nRunAlgoID = LP_DETECTOR_INVALID_ID; - - return true; } @@ -686,22 +673,13 @@ IDetectorAlgorithm* CDetectorTask::GetRunAlgo() IDetectorSolution* CDetectorTask::GetParentSolution() { - //if (m_pSolution) - // return m_pSolution->GetID(); - - - //return LP_DETECTOR_INVALID_ID; - return m_pSolution; } -int CDetectorTask::GetProductCount() +int CDetectorTask::GetProductCount() { - for (QVector::iterator iter = m_vecAlgorithm.begin(); - iter != m_vecAlgorithm.end(); ++iter) - { - if (*iter) - { + for (QVector::iterator iter = m_vecAlgorithm.begin(); iter != m_vecAlgorithm.end(); ++iter) { + if (*iter) { IDetectorAlgorithm* pAlgo = *iter; int nParamCount = pAlgo->EnumOutParam(NULL, 0); if (nParamCount > 0) @@ -731,89 +709,57 @@ int CDetectorTask::GetProductCount() } } } - delete[] lppParam; } } - } - return 1; } QVariant CDetectorTask::GetSystemInfoValue(const QString &key) { - if (m_pSystemInfo) - { - return m_pSystemInfo->GetValue(key); - } return NULL; } bool CDetectorTask::PushImage(PLP_DETECTOR_IMAGE_CACHE_DATA pImageData) { - //if (!m_pImageSaveMgr) - return false; - - //return m_pImageSaveMgr->PushImage(pImageData); + return false; } void CDetectorTask::LoadUserParamValue() { - for (QVector::iterator iter = m_vecAlgorithm.begin(); - iter != m_vecAlgorithm.end(); ++iter) - { - if (NULL != *iter) - { + for (QVector::iterator iter = m_vecAlgorithm.begin(); iter != m_vecAlgorithm.end(); ++iter) { + if (NULL != *iter) { CDetectorAlgorithm *p = (CDetectorAlgorithm*)*iter; p->LoadUserParamValue(LP_DETECTOR_INVALID_ID); } - } } void CDetectorTask::SaveUserParamValue() { - for (QVector::iterator iter = m_vecAlgorithm.begin(); - iter != m_vecAlgorithm.end(); ++iter) - { - if (NULL != *iter) - { + for (QVector::iterator iter = m_vecAlgorithm.begin(); iter != m_vecAlgorithm.end(); ++iter) { + if (NULL != *iter) { CDetectorAlgorithm *p = (CDetectorAlgorithm*)*iter; p->SaveUserParamValue(LP_DETECTOR_INVALID_ID); } - } } void CDetectorTask::ClearUserParamValue() { - for (QVector::iterator iter = m_vecAlgorithm.begin(); - iter != m_vecAlgorithm.end(); ++iter) - { - if (NULL != *iter) - { + for (QVector::iterator iter = m_vecAlgorithm.begin(); iter != m_vecAlgorithm.end(); ++iter) { + if (NULL != *iter) { CDetectorAlgorithm *p = (CDetectorAlgorithm*)*iter; p->ClearUserParamValue(LP_DETECTOR_INVALID_ID); } - } } bool CDetectorTask::Exec() { int64 start = cv::getTickCount(); - //LARGE_INTEGER litmp; - //LONGLONG startTime, endTime; - //double dfMinus, dfFreq, dfTime; - - //QueryPerformanceFrequency(&litmp); - //dfFreq = (double)litmp.QuadPart; - - //QueryPerformanceCounter(&litmp); - //startTime = litmp.QuadPart; - //quint64 msec = QDateTime::currentMSecsSinceEpoch(); m_bRunning = true; for (QVector::iterator iter = m_vecAlgorithm.begin(); iter != m_vecAlgorithm.end(); ++iter) @@ -823,9 +769,7 @@ bool CDetectorTask::Exec() CDetectorAlgorithm *pAlgo = (CDetectorAlgorithm*)*iter; if (pAlgo->IsEnabled()) pAlgo->ExecOnce(); - } - } m_bRunning = false; @@ -841,12 +785,6 @@ bool CDetectorTask::Exec() } - //QueryPerformanceCounter(&litmp); - //endTime = litmp.QuadPart; - - //dfMinus = (double)(endTime - startTime); - //dfTime = dfMinus / dfFreq; - m_dExecTime = (cv::getTickCount() - start) / cv::getTickFrequency() * 1000; qDebug("task name:%s, task exec time: %.3f", m_tTask.strName.toLocal8Bit().data(), m_dExecTime); return true; diff --git a/src/lpbengine/Task.h b/src/lpbengine/Task.h index bdeb129..dab3cd3 100644 --- a/src/lpbengine/Task.h +++ b/src/lpbengine/Task.h @@ -30,8 +30,7 @@ public: virtual int GetID() const; virtual int GetAlgoBaseID() const; virtual void Release(); - bool Initialize(IDetectorSolution* pSolution, IDetectorSystemInfo* pSystemInfo, - IAlgorithmShare* pAlgoShare, IAlgorithmLibMgr* pAlgoLibMgr); + bool Initialize(IDetectorSolution* pSolution, /*IAlgorithmShare* pAlgoShare,*/ IAlgorithmLibMgr* pAlgoLibMgr); bool SerializePropertyToJson(QJsonObject* pJsonObject); bool SerializePropertyFromJson(QJsonObject* pJsonObject); @@ -82,8 +81,7 @@ private: QVector m_vecAlgorithm; IDetectorSolution* m_pSolution; - IDetectorSystemInfo* m_pSystemInfo; - IAlgorithmShare* m_pAlgoShare; + //IAlgorithmShare* m_pAlgoShare; IAlgorithmLibMgr* m_pAlgoLibMgr; bool m_bRunning; diff --git a/src/lpbengine/lpbengine.cpp b/src/lpbengine/lpbengine.cpp deleted file mode 100644 index 44e3631..0000000 --- a/src/lpbengine/lpbengine.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "lpbengine.h" -#include "BEApp.h" -CBEApp g_BEApp; - -void LpNewEngineInstance(IDetectorEngine** lppBE, IDetectorEngineSink* lpSink) -{ - g_BEApp.Initialize(lppBE, lpSink); -} - -bool LpDeleteEngineInstance() -{ - return g_BEApp.Quit(); -} \ No newline at end of file diff --git a/src/tpMain/WheelModel.cpp b/src/tpMain/WheelModel.cpp index 23a3df3..aa05c9c 100644 --- a/src/tpMain/WheelModel.cpp +++ b/src/tpMain/WheelModel.cpp @@ -68,7 +68,6 @@ bool WheelModel::initComModel(const QString&strBase) m_pDetectModel = new ImageCompareModel; } QString str = strBase + "template\\" + m_strModelID + "\\model.yml"; - //QString str = strBase + "模板\\" + m_strModelID + "\\model.yml"; std::string strs = str.toLocal8Bit().toStdString(); bool bFlags = m_pDetectModel->readFromFile(strs/*str.toLatin1().data()*/); if (!bFlags) { diff --git a/tpvs17/lpbengine/lpbengine.vcxproj b/tpvs17/lpbengine/lpbengine.vcxproj index 429ff88..91e3c32 100644 --- a/tpvs17/lpbengine/lpbengine.vcxproj +++ b/tpvs17/lpbengine/lpbengine.vcxproj @@ -230,127 +230,7 @@ - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - + @@ -470,36 +350,6 @@ - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - - - - - Performing Custom Build Tools - Performing Custom Build Tools - - - - - - - - - @@ -535,16 +385,10 @@ - - - - - - + - diff --git a/tpvs17/lpbengine/lpbengine.vcxproj.filters b/tpvs17/lpbengine/lpbengine.vcxproj.filters index 6ca2e72..c6efd1c 100644 --- a/tpvs17/lpbengine/lpbengine.vcxproj.filters +++ b/tpvs17/lpbengine/lpbengine.vcxproj.filters @@ -23,26 +23,11 @@ moc;h;cpp False + + {afe78acb-6e43-4d6a-aa42-5f92cb41a608} + - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - Source Files @@ -52,47 +37,23 @@ Source Files - - Source Files - Source Files - - Source Files + + algo - Source Files + algo + algo + + Source Files - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - Header Files @@ -102,10 +63,19 @@ Header Files - + Header Files - + + algo + + + algo + + + algo + + Header Files diff --git a/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.cpp b/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.cpp index 3c40f0c..119e568 100644 --- a/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.cpp +++ b/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.cpp @@ -9,7 +9,7 @@ extern "C" void Lib_CoreCtrl_Free(ICoreCtrl*); #endif #include "QZkJsonParser.h" -CDllCoreCtrl::CDllCoreCtrl(const ZStringList& szDllPaths,class IDetectorEngine* pDE /*= NULL*/) +CDllCoreCtrl::CDllCoreCtrl(const ZStringList& szDllPaths) { m_szDllPaths = szDllPaths; #ifdef _USE_LIB_CORECTRL_DLL @@ -19,7 +19,7 @@ CDllCoreCtrl::CDllCoreCtrl(const ZStringList& szDllPaths,class IDetectorEngine* m_pCoreCtrl = (ICoreCtrl*)m_pLibCoreCtrl->ModuleInit(nullptr); if (NULL != m_pCoreCtrl) { - m_pCoreCtrl->IInitCore(pDE); + m_pCoreCtrl->IInitCore(); } else { @@ -43,10 +43,6 @@ CDllCoreCtrl::~CDllCoreCtrl() #ifdef _USE_LIB_CORECTRL_DLL m_pCoreCtrl->IFreeCore(); delete m_pCoreCtrl; -// if (NULL != m_pLibCoreCtrl) -// { -// m_pLibCoreCtrl->ModuleFree(); -// } #else Lib_CoreCtrl_Free(m_pCoreCtrl); #endif diff --git a/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.h b/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.h index 1486998..702e4f6 100644 --- a/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.h +++ b/tpvs17/tpMain/CoreCtrl/CDllCoreCtrl.h @@ -7,7 +7,7 @@ class CDllCoreCtrl { public: - CDllCoreCtrl(const ZStringList& szDllPaths, class IDetectorEngine* pDE /*= NULL*/); + CDllCoreCtrl(const ZStringList& szDllPaths); ~CDllCoreCtrl(); public: class CDllLoaderM* m_pLibCoreCtrl; diff --git a/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.cpp b/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.cpp index cf86a93..43ea856 100644 --- a/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.cpp +++ b/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.cpp @@ -1,79 +1,33 @@ #include "CDllDetectorEngine.h" -#include "iCoreCtrl.h" +#include "DllLoader.h" CDllDetectorEngine::CDllDetectorEngine() { - m_pDE = NULL; -#ifdef _DEBUG - m_lib.setFileName("lpbengined.dll"); -#else - m_lib.setFileName("lpbengine.dll"); -#endif - - if (!m_lib.load()) - { - qWarning("failed to load lpbengine"); - } - - FnLpNewEngineInstance pfnLpNewInstance = (FnLpNewEngineInstance)m_lib.resolve("LpNewEngineInstance"); - if (pfnLpNewInstance) - pfnLpNewInstance(&m_pDE, NULL); - - if (!m_pDE) + m_pLibEngineCtrl = new CDllLoaderM("lpbengine", "Lib_Engine_Init", "Lib_Engine_Free", QStringList()); + if (m_pLibEngineCtrl != nullptr) { - qWarning("failed to get instance from lpbengine"); + m_pDE = (IDetectorEngine*)m_pLibEngineCtrl->ModuleInit(nullptr); + if (m_pDE){ + m_pDE->Initialize(); + } + else { + qWarning("failed to get instance from lpbengine"); + } } - } CDllDetectorEngine::~CDllDetectorEngine() { - Quit(); -} - -bool CDllDetectorEngine::Initialize(class ICoreCtrl* pCoreCtrl) -{ - if (m_pDE && pCoreCtrl) + if (nullptr != m_pDE) { - void* p = NULL; - m_pDE->GetDataInterface(DEVICEMGR, &p); - IDetectorDeviceMgr* pDeviceMgr = (IDetectorDeviceMgr*)p; - if (pDeviceMgr) - { - pDeviceMgr->RegisterCoreCtrl(pCoreCtrl); - QList strCameraKeys = pCoreCtrl->ICameraKeys(); - for (int i = 0; i < strCameraKeys.size(); i++) - { - - IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)pDeviceMgr->AddDevice(CAMERA); - if (pCamera) - { - TP_CAMERA_OPTION option; - pCoreCtrl->IGetCameraOption(strCameraKeys.at(i), option); - pCamera->SetName(strCameraKeys.at(i)); - pCamera->SetID(option.id); - } - } - } - - m_pDE->GetDataInterface(SHAREAPARAM, &p); - IAlgorithmShare* pAlgoShare = (IAlgorithmShare*)p; - if (pAlgoShare) - { - pAlgoShare->RegisterCoreCtrl(pCoreCtrl); - } - - return true; + delete m_pDE; + m_pDE = nullptr; + } + if (nullptr != m_pLibEngineCtrl) + { + delete m_pLibEngineCtrl; + m_pLibEngineCtrl = nullptr; } - return false; } -void CDllDetectorEngine::Quit() -{ - FnLpDeleteEngineInstance pfnLpDeleteInstance = (FnLpDeleteEngineInstance)m_lib.resolve("LpDeleteEngineInstance"); - if (pfnLpDeleteInstance) - pfnLpDeleteInstance(); - if (m_lib.isLoaded()) - m_lib.unload(); -} \ No newline at end of file diff --git a/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.h b/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.h index bd2150c..eee18b4 100644 --- a/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.h +++ b/tpvs17/tpMain/CoreCtrl/CDllDetectorEngine.h @@ -2,6 +2,7 @@ #define CDLLDETECTORENGINE_H #include "lpbengine.h" +#include "zclasses.h" class CDllDetectorEngine { @@ -9,11 +10,8 @@ public: CDllDetectorEngine(); ~CDllDetectorEngine(); public: - bool Initialize(class ICoreCtrl* pCoreCtrl); - void Quit(); - IDetectorEngine *m_pDE; -private: - QLibrary m_lib; + IDetectorEngine* m_pDE{ nullptr }; + class CDllLoaderM* m_pLibEngineCtrl{ nullptr }; }; #endif // CDLLDETECTORENGINE_H diff --git a/tpvs17/tpMain/lpMainWin.cpp b/tpvs17/tpMain/lpMainWin.cpp index ee61fec..199296b 100644 --- a/tpvs17/tpMain/lpMainWin.cpp +++ b/tpvs17/tpMain/lpMainWin.cpp @@ -41,6 +41,7 @@ lpMainWin::lpMainWin(QWidget *parent) qRegisterMetaType("TimeStruct"); m_screen.ShowMsg(tr("加载必要模块.....")); onInitCoreCtrl(); + onInitEngineCtrl(); ui.setupUi(this); onInitAbout(); { @@ -376,7 +377,11 @@ lpMainWin::~lpMainWin() delete m_pDllCoreCtrl; m_pDllCoreCtrl = nullptr; } - + if (m_pDllEngineCtrl) + { + delete m_pDllEngineCtrl; + m_pDllEngineCtrl = nullptr; + } } bool lpMainWin::onInitCoreCtrl() @@ -384,7 +389,7 @@ bool lpMainWin::onInitCoreCtrl() //load coretrl if (NULL == m_pDllCoreCtrl) { - m_pDllCoreCtrl = new CDllCoreCtrl(QStringList(), nullptr); + m_pDllCoreCtrl = new CDllCoreCtrl(QStringList()); if (NULL == m_pDllCoreCtrl) { return false; @@ -407,6 +412,22 @@ bool lpMainWin::onInitCoreCtrl() return false; } +bool lpMainWin::onInitEngineCtrl() +{ + if (m_pDllEngineCtrl == nullptr) + { + m_pDllEngineCtrl = new CDllDetectorEngine(); + if (m_pDllEngineCtrl != nullptr) + { + m_pEngineCtrl = m_pDllEngineCtrl->m_pDE; + return true; + } + return false; + } + + return false; +} + void lpMainWin::loadUserModel() { //userctrel @@ -1315,8 +1336,6 @@ Q_SLOT void lpMainWin::onGetImg() Q_SLOT void lpMainWin::onShowMsg(QString str) { QPulpewidget *pw = new QPulpewidget(); -// m_pw = pw; -// QMainWindow *m_pDlgMain = nullptr;// GET_WIDGET_POINTER("MainWindow", QMainWindow); pw->setParent(this); pw->showmessage(str); connect(pw, SIGNAL(finished()), pw, SLOT(deleteLater())); @@ -1467,35 +1486,6 @@ void lpMainWin::onShowResult(Result2Ui* pRlt) void lpMainWin::SendResultBee(emTypeBee m_Type, int num) { - //qDebug() << "sendResultBeeLight"; - //SComframe frame; - //if (m_Type == LIGHT_REDBEE) { - // frame.data1 = 1; - // frame.data2 = num; - // SendDataToCom(0x46, frame); - //} - //else if (m_Type == LIGHT_GREENBEE) { - // frame.data1 = 2; - // frame.data2 = 0; - // frame.data3 = num; - // SendDataToCom(0x46, frame); - //} - //else if (m_Type == LIGHT_YELLOWBEE) { - // frame.data1 = 4; - // frame.data2 = 0; - // frame.data3 = 0; - // frame.data4 = num; - // SendDataToCom(0x46, frame); - //} - //else if (m_Type == LIGHT_BEE) { - // frame.data1 = 8; - // frame.data2 = 0; - // frame.data3 = 0; - // frame.data4 = 0; - // frame.data5 = num; - // SendDataToCom(0x46, frame); - //} - if (m_Type == LIGHT_REDBEE) { m_pNet->sendLight(0, 1, 500, 500);//红灯 } diff --git a/tpvs17/tpMain/lpMainWin.h b/tpvs17/tpMain/lpMainWin.h index 5301a7e..92b961a 100644 --- a/tpvs17/tpMain/lpMainWin.h +++ b/tpvs17/tpMain/lpMainWin.h @@ -21,6 +21,8 @@ #include "qpixmapbar.h" #include "QSystemSettingDlg.h" #include "QCamSettingDlg.h" +#include "lpbengine.h" +#include "CoreCtrl/CDllDetectorEngine.h" class lpMainWin : public QMainWindow { @@ -70,6 +72,7 @@ private: protected: bool onInitCoreCtrl(); + bool onInitEngineCtrl(); void loadUserModel();//加载用户管理模块 //国际化 @@ -200,6 +203,10 @@ private: bool readExposureTimeConfig(const QString& strPath); int getCurExposureTime(); + +private: + CDllDetectorEngine* m_pDllEngineCtrl{ nullptr }; + IDetectorEngine* m_pEngineCtrl{nullptr}; }; #endif diff --git a/tpvs17/tpMain/lpMainWin.ui b/tpvs17/tpMain/lpMainWin.ui index d854b41..68c0ca2 100644 --- a/tpvs17/tpMain/lpMainWin.ui +++ b/tpvs17/tpMain/lpMainWin.ui @@ -860,6 +860,7 @@ background-color: rgb(170, 170, 127); + @@ -1031,6 +1032,11 @@ background-color: rgb(170, 170, 127); + + + 设计 + + diff --git a/tpvs17/wheel.sln b/tpvs17/wheel.sln index 8df7fe1..16c6143 100644 --- a/tpvs17/wheel.sln +++ b/tpvs17/wheel.sln @@ -19,6 +19,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tpCamBaumer", "..\..\Valve\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lpReport", "lpReport\lpReport.vcxproj", "{0E042214-1B06-40D6-9D20-C6D5FA3D7A51}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lpbengine", "lpbengine\lpbengine.vcxproj", "{DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lpdesigner", "lpdesigner\lpdesigner.vcxproj", "{616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -77,12 +81,26 @@ Global {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Release|x64.ActiveCfg = Release|x64 {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Release|x64.Build.0 = Release|x64 {0E042214-1B06-40D6-9D20-C6D5FA3D7A51}.Release|x86.ActiveCfg = Release|x64 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Debug|x64.ActiveCfg = Debug|x64 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Debug|x64.Build.0 = Debug|x64 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Debug|x86.ActiveCfg = Debug|Win32 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Debug|x86.Build.0 = Debug|Win32 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Release|x64.ActiveCfg = Release|x64 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Release|x64.Build.0 = Release|x64 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Release|x86.ActiveCfg = Release|Win32 + {DC221ADF-9D25-40E0-90AD-CC2C497F6FB9}.Release|x86.Build.0 = Release|Win32 + {616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}.Debug|x64.ActiveCfg = Debug|x64 + {616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}.Debug|x64.Build.0 = Debug|x64 + {616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}.Debug|x86.ActiveCfg = Debug|x64 + {616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}.Release|x64.ActiveCfg = Release|x64 + {616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}.Release|x64.Build.0 = Release|x64 + {616EB73F-66E3-46FF-B423-1A5B7E6AAB8B}.Release|x86.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {CD365F32-5EAC-4A16-AD47-BFB1D8E5511A} Qt5Version = qt5.9.4-msvc2017-x64 + SolutionGuid = {CD365F32-5EAC-4A16-AD47-BFB1D8E5511A} EndGlobalSection EndGlobal