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

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;
}

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

@ -133,7 +133,6 @@ bool Solution::DeleteTask(QString strName)
QMap<QString, IDetectorTask*>::iterator its = m_TaskMapByName.find(strName);
if (its != m_TaskMapByName.end())
{
int nID = (*its)->GetID();
(*its)->RemoveFile();
delete *its;
m_TaskMapByName.erase(its);
@ -211,6 +210,7 @@ bool Solution::SaveFileEx(const QString& strPath, QStringList sTaskNames)
}
QString strTaskFilePath = taskPath + "/taskinfo.json";
p->SetPath(taskPath);
if (!p->SaveFile(strTaskFilePath))
{
qWarning("save task:%s fail", p->GetTaskInfo()->strName);
@ -240,7 +240,8 @@ bool Solution::SaveFileEx(const QString& strPath)
dir.mkpath(taskPath);
}
QString strTaskFilePath = taskPath + "/" + "taskinfo.json";
QString strTaskFilePath = taskPath + "/taskinfo.json";
p->SetPath(taskPath);
if (!p->SaveFile(strTaskFilePath))
{
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;
infoObj.insert("solution_name", m_tSolutionInfo.strName);
infoObj.insert("solution_type", m_tSolutionInfo.nType);
@ -278,40 +273,63 @@ bool Solution::SaveFileEx(const QString& strPath)
infoFile.write(byteArray);
infoFile.flush();
infoFile.close();
return true;
}
return true;
}
/*
for (int i = 0; i < fileList.size(); i++)
bool Solution::SaveTaskByName(QString strName)
{
QDir dir;
if (!dir.exists(m_curRootPath))
{
if (fileList.at(i).fileName() == "." || fileList.at(i).fileName() == "..")
continue;
dir.mkdir(m_curRootPath);
}
QString strFileName = fileList.at(i).fileName();
QString strSolutionFile = strPath + "/" + strFileName;
if (fileList.at(i).fileName() == "info.json")
{
continue;
}
dir.setPath(m_curRootPath);
//保存指定的task
QMap<QString, IDetectorTask*>::iterator iter = m_TaskMapByName.find(strName);
if (iter!=m_TaskMapByName.end()) {
int nID = strFileName.mid(0, strFileName.indexOf("_")).toInt();
QString strTaskName = strFileName.mid(strFileName.indexOf("_") + 1, strFileName.lastIndexOf(".") - strFileName.indexOf("_") - 1);
CDetectorTask *p = (CDetectorTask*)*iter;
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()
{
return SaveFileEx(m_curRootPath);
QString strInfoFile = m_curRootPath + "/info.json";
QFile infoFile(strInfoFile);
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 //标定模板参数
----------
*/
bool Solution::LoadFileEx(const QString& strPath)
{
QDir dir(strPath);

@ -31,7 +31,7 @@ public:
virtual IDetectorTask* AddAndCopyTask(IDetectorTask* pSrcTask, LP_DETECTOR_TASK tTaskInfo);
virtual int GetTaskBaseID() const;
virtual bool SaveFileEx();
virtual bool SaveTaskByName(QString strName);
virtual bool SaveFileEx(const QString& strPath);
virtual bool SaveFileEx(const QString& strPath, QStringList sTaskNames);
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;
}
@ -152,8 +119,7 @@ bool CDetectorSolutionMgr::SaveByNames(QStringList strNames)
QJsonDocument document;
QString strExePath = QCoreApplication::applicationDirPath();
/*耗时过长*/
for (QMap<QString, IDetectorSolution *>::iterator iter = m_vecSolution.begin();
iter != m_vecSolution.end(); ++iter)
for (QMap<QString, IDetectorSolution *>::iterator iter = m_vecSolution.begin(); iter != m_vecSolution.end(); ++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;
}
//加载配置文件
@ -233,7 +167,6 @@ bool CDetectorSolutionMgr::Load()
if(false == finfo.exists())
continue;
LP_DETECTOR_SOLUTION solutionInfo;
solutionInfo.strName = dirList.at(i).fileName();
@ -281,7 +214,6 @@ IDetectorSolution* CDetectorSolutionMgr::GetRunSolution()
return m_vecSolution.first();
else
return nullptr;
//return GetSolutionByID(m_nRunSolutionID);
}
IDetectorSolution* CDetectorSolutionMgr::AddAndCopySolution(IDetectorSolution* pSrcSolution)

@ -2,6 +2,28 @@
#include "Roi.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()
{
m_nID = LP_DETECTOR_INVALID_ID;
@ -335,7 +357,7 @@ bool CDetectorTask::SerializeFromJson(QJsonObject* pJsonObject)
//加载模板标定图片
//QString strExePath = QCoreApplication::applicationDirPath();
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();
m_tTask.templateImg = cv::imread(strpath, CV_LOAD_IMAGE_UNCHANGED);
_strPath = strpath;
@ -386,8 +408,7 @@ bool CDetectorTask::SaveFile(const QString& strPath)
if (m_pSolution && !m_tTask.templateImg.empty())
{
//QString strExePath = m_taskPath;// QCoreApplication::applicationDirPath();
QString strFilePath = m_taskPath;// strExePath + LP_DETECTOR_BUSSINESS_IMAGE_DIR;
QString strFilePath = m_taskPath;//
QDir dir;
if (!dir.exists(strFilePath))
{
@ -395,10 +416,10 @@ bool CDetectorTask::SaveFile(const QString& strPath)
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();
if (!cv::imwrite(strpath/*strFileName.toLatin1().data()*/, m_tTask.templateImg))
if (!cv::imwrite(strpath, m_tTask.templateImg))
return false;
}
@ -461,13 +482,10 @@ bool CDetectorTask::LoadFile(const QString& strPath)
bool CDetectorTask::RemoveFile()
{
QFile::remove(strtempImgPath);
QFile::remove(strParamFilePath);
for each (QString strVar in strPathList)
{
QFile::remove(strVar);
}
strParamFilePath.clear();
/*
TODO:
*/
DelDiretory(m_taskPath);
return true;
}

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

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

Loading…
Cancel
Save