完善检测流程,优化建模版性能

master
bob.pan 5 years ago
parent 4e540816b8
commit 11582c3db5

@ -254,48 +254,6 @@ QString CAlgorithmCompare::bestMatch(const QMap<QString, IWheelModel*>* modelMap
} }
} }
//if (similarNum == 1)
//{
// double dis = std::fabs(innerCircleNumSum - simularModelMap.begin().value());
// if (dis > INSIDE_NUM_DIS_THRE)
// {
// bestName = QString();
// }
//}
//if (similarNum > 1)
//{
// auto iterEnd = simularModelMap.constEnd();
// double disMin = DBL_MAX;
// for (auto iter = simularModelMap.constBegin(); iter != iterEnd; ++iter)
// {
// double dis = std::fabs(innerCircleNumSum - iter.value());
// if (dis < disMin)
// {
// disMin = dis;
// bestName = iter.key();
// }
// }
//}
//auto iterEnd = simularModelMap.constEnd();
//bool bestMatchFlag = false;
//for (auto iter = simularModelMap.constBegin(); iter != iterEnd; ++iter)
//{
// double dis = std::fabs(innerCircleNumSum - iter.value());
// if (dis < INSIDE_NUM_DIS_THRE)
// {
// bestName = iter.key();
// bestMatchFlag = true;
// break;
// }
//}
//if (!bestMatchFlag)
//{
// bestName = QString();
//}
return bestName; return bestName;
} }

@ -43,12 +43,13 @@ Mat findEdge2(const Mat &Src)
return ret; return ret;
} }
#define REAIZE 2 #define REAIZE 2
cv::Mat ImageProcess::findCircleObject(const Mat &src, const Mat& backgroundImg, bool useBackgroundFlag, int nThres /*= 20*/, luffy_base::luffyCircle *pCircle /*= NULL*/) cv::Mat ImageProcess::findCircleObject(const Mat &srcImg, const Mat& backgroundImg, bool useBackgroundFlag, int nThres /*= 20*/, luffy_base::luffyCircle *pCircle /*= NULL*/)
{ {
#ifdef MOTO_DETECT//摩轮型号识别抠图算法 #ifdef MOTO_DETECT//摩轮型号识别抠图算法
if (!useBackgroundFlag) if (!useBackgroundFlag)
{ {
Mat detectImg; Mat detectImg;
Mat src = srcImg(Rect(435, 53, 1721, 1824));
cv::resize(src, detectImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE)); cv::resize(src, detectImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE));
int bBaseX = detectImg.cols; int bBaseX = detectImg.cols;
int bBaseY = detectImg.rows; int bBaseY = detectImg.rows;
@ -120,6 +121,7 @@ cv::Mat ImageProcess::findCircleObject(const Mat &src, const Mat& backgroundImg,
} }
else else
{ {
Mat src = srcImg;
if (src.empty() || backgroundImg.empty() || src.rows < 500) { if (src.empty() || backgroundImg.empty() || src.rows < 500) {
return Mat(); return Mat();
} }

@ -133,7 +133,6 @@ bool Solution::DeleteTask(QString strName)
QMap<QString, IDetectorTask*>::iterator its = m_TaskMapByName.find(strName); QMap<QString, IDetectorTask*>::iterator its = m_TaskMapByName.find(strName);
if (its != m_TaskMapByName.end()) if (its != m_TaskMapByName.end())
{ {
int nID = (*its)->GetID();
(*its)->RemoveFile(); (*its)->RemoveFile();
delete *its; delete *its;
m_TaskMapByName.erase(its); m_TaskMapByName.erase(its);
@ -211,6 +210,7 @@ bool Solution::SaveFileEx(const QString& strPath, QStringList sTaskNames)
} }
QString strTaskFilePath = taskPath + "/taskinfo.json"; QString strTaskFilePath = taskPath + "/taskinfo.json";
p->SetPath(taskPath);
if (!p->SaveFile(strTaskFilePath)) if (!p->SaveFile(strTaskFilePath))
{ {
qWarning("save task:%s fail", p->GetTaskInfo()->strName); qWarning("save task:%s fail", p->GetTaskInfo()->strName);
@ -240,7 +240,8 @@ bool Solution::SaveFileEx(const QString& strPath)
dir.mkpath(taskPath); dir.mkpath(taskPath);
} }
QString strTaskFilePath = taskPath + "/" + "taskinfo.json"; QString strTaskFilePath = taskPath + "/taskinfo.json";
p->SetPath(taskPath);
if (!p->SaveFile(strTaskFilePath)) if (!p->SaveFile(strTaskFilePath))
{ {
qWarning("save task:%s fail", p->GetTaskInfo()->strName); qWarning("save task:%s fail", p->GetTaskInfo()->strName);
@ -248,12 +249,6 @@ bool Solution::SaveFileEx(const QString& strPath)
} }
} }
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList fileList = dir.entryInfoList();
QJsonObject infoObj; QJsonObject infoObj;
infoObj.insert("solution_name", m_tSolutionInfo.strName); infoObj.insert("solution_name", m_tSolutionInfo.strName);
infoObj.insert("solution_type", m_tSolutionInfo.nType); infoObj.insert("solution_type", m_tSolutionInfo.nType);
@ -278,40 +273,63 @@ bool Solution::SaveFileEx(const QString& strPath)
infoFile.write(byteArray); infoFile.write(byteArray);
infoFile.flush(); infoFile.flush();
infoFile.close(); infoFile.close();
return true;
} }
return true;
}
bool Solution::SaveTaskByName(QString strName)
/* {
for (int i = 0; i < fileList.size(); i++) QDir dir;
if (!dir.exists(m_curRootPath))
{ {
if (fileList.at(i).fileName() == "." || fileList.at(i).fileName() == "..") dir.mkdir(m_curRootPath);
continue; }
QString strFileName = fileList.at(i).fileName(); dir.setPath(m_curRootPath);
QString strSolutionFile = strPath + "/" + strFileName; //保存指定的task
if (fileList.at(i).fileName() == "info.json") QMap<QString, IDetectorTask*>::iterator iter = m_TaskMapByName.find(strName);
{ if (iter!=m_TaskMapByName.end()) {
continue;
}
int nID = strFileName.mid(0, strFileName.indexOf("_")).toInt(); CDetectorTask *p = (CDetectorTask*)*iter;
QString strTaskName = strFileName.mid(strFileName.indexOf("_") + 1, strFileName.lastIndexOf(".") - strFileName.indexOf("_") - 1); QString taskPath = m_curRootPath + "/" + p->GetTaskName();
if (!dir.exists(taskPath)) {
dir.mkpath(taskPath);
}
if (!CheckTask(nID, strTaskName)) QString strTaskFilePath = taskPath + "/taskinfo.json";
p->SetPath(taskPath);
if (!p->SaveFile(strTaskFilePath))
{ {
QFile::remove(strSolutionFile); qWarning("save task:%s fail", p->GetTaskName());
} }
} }
return true; //更新solution指定的info文件包括是否使用对于的模板
QJsonObject infoObj;
*/ infoObj.insert("solution_name", m_tSolutionInfo.strName);
} infoObj.insert("solution_type", m_tSolutionInfo.nType);
infoObj.insert("solution_description", m_tSolutionInfo.strDescription);
infoObj.insert("solution_id", m_nID);
QJsonArray tasklist;
m_tasklist = m_TaskMapByName.keys();
foreach(QString var, m_tasklist)
{
tasklist.append(var);
}
infoObj.insert("tasklist", tasklist);
QJsonDocument document;
document.setObject(infoObj);
QByteArray byteArray = document.toJson();
bool Solution::SaveFileEx() QString strInfoFile = m_curRootPath + "/info.json";
{ QFile infoFile(strInfoFile);
return SaveFileEx(m_curRootPath); if (infoFile.open(QFile::WriteOnly | QFile::Text))
{
infoFile.write(byteArray);
infoFile.flush();
infoFile.close();
}
return true;
} }
/* /*
@ -328,6 +346,7 @@ solution_1 ---------- info.json //
-----param.ts //标定模板参数 -----param.ts //标定模板参数
---------- ----------
*/ */
bool Solution::LoadFileEx(const QString& strPath) bool Solution::LoadFileEx(const QString& strPath)
{ {
QDir dir(strPath); QDir dir(strPath);

@ -31,7 +31,7 @@ public:
virtual IDetectorTask* AddAndCopyTask(IDetectorTask* pSrcTask, LP_DETECTOR_TASK tTaskInfo); virtual IDetectorTask* AddAndCopyTask(IDetectorTask* pSrcTask, LP_DETECTOR_TASK tTaskInfo);
virtual int GetTaskBaseID() const; virtual int GetTaskBaseID() const;
virtual bool SaveFileEx(); virtual bool SaveTaskByName(QString strName);
virtual bool SaveFileEx(const QString& strPath); virtual bool SaveFileEx(const QString& strPath);
virtual bool SaveFileEx(const QString& strPath, QStringList sTaskNames); virtual bool SaveFileEx(const QString& strPath, QStringList sTaskNames);
virtual bool LoadFileEx(const QString& strPath); virtual bool LoadFileEx(const QString& strPath);

@ -111,39 +111,6 @@ bool CDetectorSolutionMgr::Save()
} }
} }
QString strSolutionDirPath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_SOLUTION_DIR;
QDir solutionDir(strSolutionDirPath);
if (!solutionDir.exists())
{
return true;
}
solutionDir.setFilter(QDir::Dirs | QDir::Hidden | QDir::NoSymLinks);
solutionDir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList fileList = solutionDir.entryInfoList();
for (int i = 0; i < fileList.size(); i++)
{
if (fileList.at(i).fileName() == "." || fileList.at(i).fileName() == "..")
continue;
QString strFileName = fileList.at(i).fileName();
QString strSolutionFile = strSolutionDirPath + strFileName;
if (fileList.at(i).fileName() == "info.json")
{
continue;
}
int nID = strFileName.mid(0, strFileName.indexOf("_")).toInt();
QString strSolutionName = strFileName.mid(strFileName.indexOf("_") + 1, strFileName.indexOf(".") - strFileName.indexOf("_") - 1);
// if (!CheckSolution(nID, strSolutionName))
// {
// qWarning() << "SaveAll, remove solution file" << strSolutionName;
// EngineBase::DeleteDir(strSolutionFile);
// }
}
return true; return true;
} }
@ -152,8 +119,7 @@ bool CDetectorSolutionMgr::SaveByNames(QStringList strNames)
QJsonDocument document; QJsonDocument document;
QString strExePath = QCoreApplication::applicationDirPath(); QString strExePath = QCoreApplication::applicationDirPath();
/*耗时过长*/ /*耗时过长*/
for (QMap<QString, IDetectorSolution *>::iterator iter = m_vecSolution.begin(); for (QMap<QString, IDetectorSolution *>::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++iter)
iter != m_vecSolution.end(); ++iter)
{ {
if (*iter) if (*iter)
{ {
@ -169,38 +135,6 @@ bool CDetectorSolutionMgr::SaveByNames(QStringList strNames)
} }
} }
QString strSolutionDirPath = strExePath + LP_DETECTOR_BUSSINESS_CONFIG_SOLUTION_DIR;
QDir solutionDir(strSolutionDirPath);
if (!solutionDir.exists())
{
return true;
}
solutionDir.setFilter(QDir::Dirs | QDir::Hidden | QDir::NoSymLinks);
solutionDir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList fileList = solutionDir.entryInfoList();
for (int i = 0; i < fileList.size(); i++)
{
if (fileList.at(i).fileName() == "." || fileList.at(i).fileName() == "..")
continue;
QString strFileName = fileList.at(i).fileName();
QString strSolutionFile = strSolutionDirPath + strFileName;
if (fileList.at(i).fileName() == "info.json")
{
continue;
}
int nID = strFileName.mid(0, strFileName.indexOf("_")).toInt();
QString strSolutionName = strFileName.mid(strFileName.indexOf("_") + 1, strFileName.indexOf(".") - strFileName.indexOf("_") - 1);
// if (!CheckSolution(nID, strSolutionName))
// {
// qWarning() << "SaveAll, remove solution file" << strSolutionName;
// EngineBase::DeleteDir(strSolutionFile);
// }
}
return true; return true;
} }
//加载配置文件 //加载配置文件
@ -233,7 +167,6 @@ bool CDetectorSolutionMgr::Load()
if(false == finfo.exists()) if(false == finfo.exists())
continue; continue;
LP_DETECTOR_SOLUTION solutionInfo; LP_DETECTOR_SOLUTION solutionInfo;
solutionInfo.strName = dirList.at(i).fileName(); solutionInfo.strName = dirList.at(i).fileName();
@ -281,7 +214,6 @@ IDetectorSolution* CDetectorSolutionMgr::GetRunSolution()
return m_vecSolution.first(); return m_vecSolution.first();
else else
return nullptr; return nullptr;
//return GetSolutionByID(m_nRunSolutionID);
} }
IDetectorSolution* CDetectorSolutionMgr::AddAndCopySolution(IDetectorSolution* pSrcSolution) IDetectorSolution* CDetectorSolutionMgr::AddAndCopySolution(IDetectorSolution* pSrcSolution)

@ -2,6 +2,28 @@
#include "Roi.h" #include "Roi.h"
#include "Algorithm.h" #include "Algorithm.h"
static inline bool DelDiretory(const QString &dirPath)
{
if (dirPath.isEmpty())
return false;
QDir qDir(dirPath);
if (!qDir.exists())
return true;
qDir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
QStringList ss = qDir.entryList();
QFileInfoList qFileList = qDir.entryInfoList();
foreach(QFileInfo qFileInfo, qFileList)
{
if (qFileInfo.isFile())
qFileInfo.dir().remove(qFileInfo.fileName());
else
DelDiretory(qFileInfo.absoluteFilePath());
}
QString str = qDir.absolutePath();
//return qDir.rmpath(dirPath);
return qDir.rmdir(dirPath);
}
CDetectorTask::CDetectorTask() CDetectorTask::CDetectorTask()
{ {
m_nID = LP_DETECTOR_INVALID_ID; m_nID = LP_DETECTOR_INVALID_ID;
@ -335,7 +357,7 @@ bool CDetectorTask::SerializeFromJson(QJsonObject* pJsonObject)
//加载模板标定图片 //加载模板标定图片
//QString strExePath = QCoreApplication::applicationDirPath(); //QString strExePath = QCoreApplication::applicationDirPath();
QString strImagePath = m_taskPath;// strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR; QString strImagePath = m_taskPath;// strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR;
QString strImageName = strImagePath + "/template.png";// QString::number(m_pSolution->GetID()) + "_" + QString::number(m_nID) + ".bmp"; QString strImageName = strImagePath + "/template.png";//
std::string strpath = strImageName.toLocal8Bit().toStdString(); std::string strpath = strImageName.toLocal8Bit().toStdString();
m_tTask.templateImg = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED); m_tTask.templateImg = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED);
_strPath = strpath; _strPath = strpath;
@ -386,8 +408,7 @@ bool CDetectorTask::SaveFile(const QString& strPath)
if (m_pSolution && !m_tTask.templateImg.empty()) if (m_pSolution && !m_tTask.templateImg.empty())
{ {
//QString strExePath = m_taskPath;// QCoreApplication::applicationDirPath(); QString strFilePath = m_taskPath;//
QString strFilePath = m_taskPath;// strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR;
QDir dir; QDir dir;
if (!dir.exists(strFilePath)) if (!dir.exists(strFilePath))
{ {
@ -395,10 +416,10 @@ bool CDetectorTask::SaveFile(const QString& strPath)
return false; return false;
} }
QString strFileName = strFilePath + "/" + /*QString::number(m_pSolution->GetID()) + "_" + QString::number(m_nID)*/ + "template.png"; QString strFileName = strFilePath + "/template.png";
std::string strpath = strFileName.toLocal8Bit().toStdString(); std::string strpath = strFileName.toLocal8Bit().toStdString();
if (!cv::imwrite(strpath/*strFileName.toLatin1().data()*/, m_tTask.templateImg)) if (!cv::imwrite(strpath, m_tTask.templateImg))
return false; return false;
} }
@ -461,13 +482,10 @@ bool CDetectorTask::LoadFile(const QString& strPath)
bool CDetectorTask::RemoveFile() bool CDetectorTask::RemoveFile()
{ {
QFile::remove(strtempImgPath); /*
QFile::remove(strParamFilePath); TODO:
for each (QString strVar in strPathList) */
{ DelDiretory(m_taskPath);
QFile::remove(strVar);
}
strParamFilePath.clear();
return true; return true;
} }

@ -72,6 +72,7 @@ public:
virtual bool SyncMapResult(const QVariantMap& vMap); virtual bool SyncMapResult(const QVariantMap& vMap);
virtual QString GetPath() { return m_taskPath; } virtual QString GetPath() { return m_taskPath; }
virtual void SetPath(QString path) { m_taskPath = path; }
protected: protected:
int GetProductCount(); int GetProductCount();

@ -1907,7 +1907,7 @@ Q_SLOT void lpMainWin::onSlotAddNewModel(QString strName)
IDetectorSolution* pSolution = pMgr->GetRunSolution(); IDetectorSolution* pSolution = pMgr->GetRunSolution();
if (pSolution) { if (pSolution) {
pSolution->AddTaskByTemplate(strName); pSolution->AddTaskByTemplate(strName);
pSolution->SaveFileEx(); pSolution->SaveTaskByName(strName);
} }
} }
} }
@ -1923,7 +1923,7 @@ Q_SLOT void lpMainWin::onSlotDelOldModel(QString strName)
IDetectorSolution* pSolution = pMgr->GetRunSolution(); IDetectorSolution* pSolution = pMgr->GetRunSolution();
if (pSolution) { if (pSolution) {
pSolution->DeleteTask(strName); pSolution->DeleteTask(strName);
pSolution->SaveFileEx(); pSolution->SaveTaskByName("");
} }
} }
} }

Loading…
Cancel
Save