|
|
|
|
@ -34,6 +34,8 @@ public:
|
|
|
|
|
bool useHeight;
|
|
|
|
|
bool useDiameter;
|
|
|
|
|
QStringList defectList;
|
|
|
|
|
double dRatioVal{0};
|
|
|
|
|
int ratioType{ 0 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CAlgorithmFluorescence::CAlgorithmFluorescence(void)
|
|
|
|
|
@ -46,9 +48,142 @@ CAlgorithmFluorescence::~CAlgorithmFluorescence(void)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//cv::BackgroundSubtractorMOG CAlgorithmFluorescence::bgSubtractor(30, 5, 0.95, false);
|
|
|
|
|
//检测算法入口函数 由corctl框架回调
|
|
|
|
|
int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGORITHM_OPTION* pOpt, class IDetectorEngine* pDE)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "start alg";
|
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
|
|
|
|
|
|
double dStart = cv::getTickCount();
|
|
|
|
|
Mat matSrc = getImage(pImgObj).clone();//获取相机原始图像
|
|
|
|
|
QVariantMap vMap = pImgObj->IVarFromUI().toMap();//获取由UI传递过来的算法参数
|
|
|
|
|
|
|
|
|
|
//解析出模板库指针 这里获取的是整个模块库
|
|
|
|
|
long long modelMapPtr = vMap.value("modelMap").toLongLong();
|
|
|
|
|
QMap<QString, IWheelModel*> *ptr = (QMap<QString, IWheelModel*>*)modelMapPtr;
|
|
|
|
|
|
|
|
|
|
//获取需要检测的列表 型号名
|
|
|
|
|
long long defectListPtr = vMap.value("defectList").toLongLong();
|
|
|
|
|
QStringList* strModelListptr = (QStringList*)defectListPtr;
|
|
|
|
|
QStringList strModelList;
|
|
|
|
|
if(strModelListptr)
|
|
|
|
|
strModelList = *(strModelListptr);
|
|
|
|
|
int IsCutedImg = vMap.value("IsCutImg", 0).toInt();//裁剪后的轮毂图 检测模式 小图
|
|
|
|
|
|
|
|
|
|
int th = vMap.value("thickness", -1).toInt();//轮毂厚度 轮毂高度数据
|
|
|
|
|
bool useThickness = vMap.value("useThickness", 0).toBool();//是否使用厚度检测判断 匹配时过滤不符合范围的模板
|
|
|
|
|
bool useDiameter = vMap.value("useDiameter", 0).toBool();//是否使用直径参数检测判断
|
|
|
|
|
double dD2H = vMap.value("d2h", -1).toDouble();
|
|
|
|
|
|
|
|
|
|
int nthreshold = vMap.value("Threshold", 15).toInt();//图像阈值参数 使用背景图抠图算法时使用
|
|
|
|
|
bool bUseBackground = vMap.value("useBackground",false).toBool();//true 使用背景图抠图 false 不使用背景
|
|
|
|
|
|
|
|
|
|
int ratioType = vMap.value("RatioType").toInt();//偏距检测模式 启用方式
|
|
|
|
|
double ratioVal = vMap.value("Ratio").toDouble();//偏距系数
|
|
|
|
|
bool bEqual = vMap.value("bEqual").toBool();//使用使用图像增强
|
|
|
|
|
int filterSize = vMap.value("filterSize").toInt();//过滤圆大小
|
|
|
|
|
|
|
|
|
|
if (nthreshold <= 0)
|
|
|
|
|
nthreshold = 15;
|
|
|
|
|
|
|
|
|
|
QVariantMap rltMap;//算法检测结果值 输出到UI用
|
|
|
|
|
rltMap.insert("ratioVal", ratioVal);
|
|
|
|
|
luffy_base::luffyCircle lCircle;
|
|
|
|
|
static bool bReload = false;//背景图加载判断
|
|
|
|
|
Mat matBack = getBackGroundImage(pImgObj, bReload);//获取背景图
|
|
|
|
|
|
|
|
|
|
Mat matMatch;//抠图后的图像 目标图像
|
|
|
|
|
if (IsCutedImg == 0) //使用的是原始图像 需要执行圆查找算法找出 轮毂
|
|
|
|
|
{
|
|
|
|
|
//原始图像的size和背景图size不匹配, 直接返回错误提示
|
|
|
|
|
if (bUseBackground == true && (matSrc.size().height != matBack.size().height || matSrc.size().width != matBack.size().width))
|
|
|
|
|
{
|
|
|
|
|
rltMap.insert("error", 0);
|
|
|
|
|
pImgObj->IVariantMapToUI(rltMap);
|
|
|
|
|
bReload = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
bReload = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bUseBackground == true)//使用背景图 做减法找圆
|
|
|
|
|
{
|
|
|
|
|
matMatch = ImageProcess::findCircleByBackground(matSrc, matBack, &lCircle);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
//不需要 背景图找圆算法
|
|
|
|
|
Point2f centerPoint;
|
|
|
|
|
double radius = 0;
|
|
|
|
|
matMatch = ImageProcess::findCircle(matSrc, centerPoint, radius, bEqual,filterSize);
|
|
|
|
|
lCircle.ptCenter = centerPoint;
|
|
|
|
|
lCircle.fRadius = radius;
|
|
|
|
|
}
|
|
|
|
|
if (matMatch.cols >= 900 || matMatch.rows >= 900)//控制检测图像大小不能超过这个范围
|
|
|
|
|
{
|
|
|
|
|
cv::resize(matMatch, matMatch, cv::Size(matMatch.cols / 2, matMatch.rows / 2));
|
|
|
|
|
lCircle.fRadius = lCircle.fRadius / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
matMatch = matSrc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result2Ui *pResult = new Result2Ui;
|
|
|
|
|
pResult->m_pixSrc = QtCVUtils::cvMatToQPixmap(matSrc);//!>原图像发送值UI 用于保存备份和调试
|
|
|
|
|
if (matMatch.empty())//抠图为空,表示抠图失败,直接返回错误
|
|
|
|
|
{
|
|
|
|
|
rltMap.insert("noCircle", 0);
|
|
|
|
|
long long varRlt = (long long)pResult;
|
|
|
|
|
rltMap.insert("result", varRlt);
|
|
|
|
|
pImgObj->IVariantMapToUI(rltMap);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CAlgorithmFluorescence::bestMatch(const QMap<QString, IWheelModel*>* modelMap, CLocalWheel*pLocal, double* pMinDis /*= NULL*/, int minDisNum /*= -1*/) const
|
|
|
|
|
double dDiameter = dD2H * lCircle.fRadius * 2;//计算轮毂直径
|
|
|
|
|
//打包相关数据
|
|
|
|
|
CLocalWheel wheelLocal;
|
|
|
|
|
wheelLocal.defectList = strModelList;
|
|
|
|
|
wheelLocal.img = matMatch.clone();
|
|
|
|
|
wheelLocal.height = th;
|
|
|
|
|
wheelLocal.diameter = dDiameter;
|
|
|
|
|
wheelLocal.useHeight = useThickness;
|
|
|
|
|
wheelLocal.useDiameter = useDiameter;
|
|
|
|
|
wheelLocal.ratioType = ratioType;
|
|
|
|
|
wheelLocal.dRatioVal = ratioVal;
|
|
|
|
|
//开始匹配
|
|
|
|
|
if (!matMatch.empty() && ptr && ptr->size() > 0) {
|
|
|
|
|
vector<double> minDisVec(ptr->size());//初始化模板匹配分数值
|
|
|
|
|
QString str = bestMatch(ptr, &wheelLocal, &(minDisVec[0]), minDisVec.size());
|
|
|
|
|
pResult->m_strModel = str;
|
|
|
|
|
pResult->m_dMinDis = minDisVec[0];
|
|
|
|
|
if (ptr->contains(str) && ptr->value(str)->getImageComModel()) {
|
|
|
|
|
ICompareModel *pModel = ptr->value(str)->getImageComModel();
|
|
|
|
|
double d = pModel->getDisThre();
|
|
|
|
|
double dValue = (d - minDisVec[0]) / d * 0.4 + 0.6;
|
|
|
|
|
pResult->m_dScore = dValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qDebug() << "pull result";
|
|
|
|
|
QImage img = QtCVUtils::cvMatToQImage(matMatch);
|
|
|
|
|
pResult->m_pixResult = QtCVUtils::cvMatToQPixmap(matMatch);// .scaled(125, 125);
|
|
|
|
|
pResult->m_dDiameter = dDiameter;
|
|
|
|
|
pResult->m_dThickness = th;
|
|
|
|
|
|
|
|
|
|
//!>传递检测结果到UI
|
|
|
|
|
//pImgObj->IDrawImage(img.scaled(300, 300));//!>显示结果图片到UI的第二个窗口上
|
|
|
|
|
double dTime = (cv::getTickCount() - dStart) / cv::getTickFrequency();
|
|
|
|
|
pResult->m_dRunTime = dTime;
|
|
|
|
|
long long varRlt = (long long)pResult;
|
|
|
|
|
rltMap.insert("result", varRlt);
|
|
|
|
|
pImgObj->IVariantMapToUI(rltMap);
|
|
|
|
|
qDebug() << "finish alg";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//模板匹配流程
|
|
|
|
|
QString CAlgorithmFluorescence::bestMatch(const QMap<QString, IWheelModel*>* modelMap, CLocalWheel* pLocal, double* pMinDis /*= NULL*/, int minDisNum /*= -1*/) const
|
|
|
|
|
{
|
|
|
|
|
double minDis = DBL_MAX;
|
|
|
|
|
QString bestName;
|
|
|
|
|
@ -68,13 +203,13 @@ QString CAlgorithmFluorescence::bestMatch(const QMap<QString, IWheelModel*>* mod
|
|
|
|
|
if (!modelMap->contains(strModelName))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
QMap<QString,IWheelModel*>::const_iterator itsModel = modelMap->find(strModelName);
|
|
|
|
|
QMap<QString, IWheelModel*>::const_iterator itsModel = modelMap->find(strModelName);
|
|
|
|
|
disVec[nIndex] = DBL_MAX;
|
|
|
|
|
IWheelModel *pWheel = itsModel.value();
|
|
|
|
|
if (!pWheel)
|
|
|
|
|
break;
|
|
|
|
|
if (pLocal->useDiameter) {
|
|
|
|
|
if (abs(pLocal->diameter-pWheel->getDiameter()) >= 15) {
|
|
|
|
|
if (abs(pLocal->diameter - pWheel->getDiameter()) >= 15) {
|
|
|
|
|
nIndex++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
@ -85,7 +220,23 @@ QString CAlgorithmFluorescence::bestMatch(const QMap<QString, IWheelModel*>* mod
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
QString name = strModelName;// i.key();
|
|
|
|
|
if (pLocal->ratioType == 1) {//开启使用偏距过滤检测模板的功能
|
|
|
|
|
//必须三个数值不为0才进行 否则可能导致不明问题
|
|
|
|
|
double curRatioVal = pLocal->dRatioVal;
|
|
|
|
|
double minRatio = pWheel->getMinRotia();
|
|
|
|
|
double maxRatio = pWheel->getMaxRotia();
|
|
|
|
|
|
|
|
|
|
if (curRatioVal > 0 && minRatio > 0 && maxRatio > 0)
|
|
|
|
|
{
|
|
|
|
|
if (curRatioVal < minRatio || curRatioVal > maxRatio)
|
|
|
|
|
{
|
|
|
|
|
nIndex++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString name = strModelName;
|
|
|
|
|
|
|
|
|
|
ICompareModel* pModel = pWheel->getImageComModel();
|
|
|
|
|
if (pModel->getBaseImg().data == NULL)
|
|
|
|
|
@ -96,7 +247,7 @@ QString CAlgorithmFluorescence::bestMatch(const QMap<QString, IWheelModel*>* mod
|
|
|
|
|
|
|
|
|
|
pModel->setIsEnableCache(false);
|
|
|
|
|
|
|
|
|
|
double dis = pModel->compare(pLocal->img, NULL, true, 1);
|
|
|
|
|
double dis = pModel->compare(pLocal->img, NULL, true, 1);
|
|
|
|
|
double disThre = pModel->getDisThre();
|
|
|
|
|
double innerCircleNum = pModel->getInnerCircleNum();
|
|
|
|
|
if (dis < disThre)
|
|
|
|
|
@ -201,187 +352,9 @@ QString CAlgorithmFluorescence::bestMatch(const QMap<QString, IWheelModel*>* mod
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGORITHM_OPTION* pOpt, class IDetectorEngine* pDE)
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker locker(&mutex);
|
|
|
|
|
qDebug() << "start alg";
|
|
|
|
|
double dStart = cv::getTickCount();
|
|
|
|
|
Mat matSrc = getImage(pImgObj).clone();
|
|
|
|
|
QVariantMap vMap = pImgObj->IVarFromUI().toMap();
|
|
|
|
|
|
|
|
|
|
long long modelMapPtr = vMap.value("modelMap").toLongLong();
|
|
|
|
|
QMap<QString, IWheelModel*> *ptr = (QMap<QString, IWheelModel*>*)modelMapPtr;
|
|
|
|
|
|
|
|
|
|
long long defectListPtr = vMap.value("defectList").toLongLong();
|
|
|
|
|
|
|
|
|
|
QStringList* strModelListptr = (QStringList*)defectListPtr;
|
|
|
|
|
QStringList strModelList;
|
|
|
|
|
if(strModelListptr)
|
|
|
|
|
strModelList = *(strModelListptr);
|
|
|
|
|
|
|
|
|
|
int th = vMap.value("thickness", -1).toInt();
|
|
|
|
|
bool useThickness = vMap.value("useThickness", 0).toBool();
|
|
|
|
|
bool useDiameter = vMap.value("useDiameter", 0).toBool();
|
|
|
|
|
double dD2H = vMap.value("d2h", -1).toDouble();
|
|
|
|
|
int nthreshold = vMap.value("Threshold", 15).toInt();
|
|
|
|
|
bool bUseBackground = vMap.value("useBackground",false).toBool();//true 使用背景图抠图 false 不使用背景
|
|
|
|
|
|
|
|
|
|
if (nthreshold <= 0)
|
|
|
|
|
nthreshold = 15;
|
|
|
|
|
int IsCutedImg = vMap.value("IsCutImg", 0).toInt();//裁剪后的轮毂图
|
|
|
|
|
QVariantMap rltMap;
|
|
|
|
|
luffy_base::luffyCircle lCircle;
|
|
|
|
|
static bool bReload = false;
|
|
|
|
|
Mat matBack = getBackGroundImage(pImgObj, bReload);//获取背景图
|
|
|
|
|
Mat matMatch;//装载抠图后的图像
|
|
|
|
|
if (IsCutedImg == 0){
|
|
|
|
|
if (bUseBackground == true && (matSrc.size().height != matBack.size().height || matSrc.size().width != matBack.size().width))
|
|
|
|
|
{
|
|
|
|
|
rltMap.insert("error", 0);
|
|
|
|
|
pImgObj->IVariantMapToUI(rltMap);
|
|
|
|
|
bReload = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
bReload = false;
|
|
|
|
|
}
|
|
|
|
|
//imageSegementation(matSrc);
|
|
|
|
|
//matMatch = ImageProcess::findCircleObject(matSrc, matBack, bUseBackground, nthreshold/*15*/, &lCircle/* NULL*/);
|
|
|
|
|
Point2f centerPoint;
|
|
|
|
|
double radius = 0;
|
|
|
|
|
matMatch = ImageProcess::findCircle(matSrc, centerPoint, radius, bUseBackground);
|
|
|
|
|
lCircle.ptCenter = centerPoint;
|
|
|
|
|
lCircle.fRadius = radius;
|
|
|
|
|
|
|
|
|
|
if (matMatch.cols >= 900 || matMatch.rows >= 900)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
cv::resize(matMatch, matMatch, cv::Size(matMatch.cols / 2, matMatch.rows / 2));
|
|
|
|
|
lCircle.fRadius = lCircle.fRadius / 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
matMatch = matSrc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result2Ui *pResult = new Result2Ui;
|
|
|
|
|
pResult->m_pixSrc = QtCVUtils::cvMatToQPixmap(matSrc);//!>原图像发送值UI 用于保存备份和调试
|
|
|
|
|
if (matMatch.empty())
|
|
|
|
|
{
|
|
|
|
|
rltMap.insert("noCircle", 0);
|
|
|
|
|
long long varRlt = (long long)pResult;
|
|
|
|
|
rltMap.insert("result", varRlt);
|
|
|
|
|
pImgObj->IVariantMapToUI(rltMap);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double dDiameter = dD2H * lCircle.fRadius * 2;
|
|
|
|
|
|
|
|
|
|
CLocalWheel wheelLocal;
|
|
|
|
|
wheelLocal.defectList = strModelList;
|
|
|
|
|
wheelLocal.img = matMatch.clone();
|
|
|
|
|
wheelLocal.height = th;
|
|
|
|
|
wheelLocal.diameter = dDiameter;
|
|
|
|
|
wheelLocal.useHeight = useThickness;
|
|
|
|
|
wheelLocal.useDiameter = useDiameter;
|
|
|
|
|
|
|
|
|
|
if (!matMatch.empty() && ptr && ptr->size() > 0) {
|
|
|
|
|
vector<double> minDisVec(ptr->size());
|
|
|
|
|
qDebug() << "start bestMatch";
|
|
|
|
|
QString str = bestMatch(ptr, &wheelLocal, &(minDisVec[0]), minDisVec.size());
|
|
|
|
|
qDebug() << "end bestMatch";
|
|
|
|
|
pResult->m_strModel = str;
|
|
|
|
|
pResult->m_dMinDis = minDisVec[0];
|
|
|
|
|
if (ptr->contains(str) && ptr->value(str)->getImageComModel()) {
|
|
|
|
|
ICompareModel *pModel = ptr->value(str)->getImageComModel();
|
|
|
|
|
double d = pModel->getDisThre();
|
|
|
|
|
double dValue = (d - minDisVec[0]) / d * 0.4 + 0.6;
|
|
|
|
|
pResult->m_dScore = dValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (matMatch.empty())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
qDebug() << "pull result";
|
|
|
|
|
QImage img = QtCVUtils::cvMatToQImage(matMatch);
|
|
|
|
|
pResult->m_pixResult = QtCVUtils::cvMatToQPixmap(matMatch);// .scaled(125, 125);
|
|
|
|
|
pResult->m_dDiameter = dDiameter;
|
|
|
|
|
pResult->m_dThickness = th;
|
|
|
|
|
|
|
|
|
|
//!>传递检测结果到UI
|
|
|
|
|
//pImgObj->IDrawImage(img.scaled(300, 300));//!>显示结果图片到UI的第二个窗口上
|
|
|
|
|
double dTime = (cv::getTickCount() - dStart) / cv::getTickFrequency();
|
|
|
|
|
pResult->m_dRunTime = dTime;
|
|
|
|
|
long long varRlt = (long long)pResult;
|
|
|
|
|
rltMap.insert("result", varRlt);
|
|
|
|
|
pImgObj->IVariantMapToUI(rltMap);
|
|
|
|
|
qDebug() << "finish alg";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList *CAlgorithmFluorescence::getDefectListPtr(class IImageObject *pImgObj)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
// IAlgorithmShared *pShare = pImgObj->IGetShared();
|
|
|
|
|
// int nMap = pShare->IGetInt("defectList");
|
|
|
|
|
// return (QStringList*)nMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMap<QString, IWheelModel*> *CAlgorithmFluorescence::getWheelMapPtr(class IImageObject *pImgObj)
|
|
|
|
|
{
|
|
|
|
|
// IAlgorithmShared *pShare = pImgObj->IGetShared();
|
|
|
|
|
// if (!pShare)
|
|
|
|
|
// return nullptr;
|
|
|
|
|
// int nMap = pShare->IGetInt("modelMap");
|
|
|
|
|
// return (QMap<QString, IWheelModel*>*)nMap;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cv::Mat CAlgorithmFluorescence::getImage(class IImageObject *pImgObj)
|
|
|
|
|
{
|
|
|
|
|
@ -409,13 +382,11 @@ cv::Mat CAlgorithmFluorescence::getBackGroundImage(class IImageObject *pObj, boo
|
|
|
|
|
{
|
|
|
|
|
static Mat matback;
|
|
|
|
|
if (matback.empty()) {
|
|
|
|
|
QString filepath = /*getPath(pObj) +*/ ".\\user\\background.png";
|
|
|
|
|
QString filepath = ".\\user\\background.png";
|
|
|
|
|
matback = cv::imread(string((const char *)filepath.toLocal8Bit()), 0);
|
|
|
|
|
//matback = cv::imread(filepath.toLatin1().data(), 0);
|
|
|
|
|
if (matback.empty()) {
|
|
|
|
|
QString filepath = getPath(pObj) + "\\user\\background_r.png";
|
|
|
|
|
matback = cv::imread(string((const char *)filepath.toLocal8Bit()), 0);
|
|
|
|
|
//matback = cv::imread(filepath.toLatin1().data(), 0);
|
|
|
|
|
cv::flip(matback, matback, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -426,7 +397,6 @@ cv::Mat CAlgorithmFluorescence::getBackGroundImage(class IImageObject *pObj, boo
|
|
|
|
|
if (matback.empty()) {
|
|
|
|
|
QString filepath = getPath(pObj) + "\\user\\background_r.png";
|
|
|
|
|
matback = cv::imread(string((const char *)filepath.toLocal8Bit()), 0);
|
|
|
|
|
//matback = cv::imread(filepath.toLatin1().data(), 0);
|
|
|
|
|
cv::flip(matback, matback, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -445,69 +415,3 @@ QString CAlgorithmFluorescence::getPath(class IImageObject *pObj)
|
|
|
|
|
}
|
|
|
|
|
return mlist.first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//void CAlgorithmFluorescence::imageSegementation(const cv::Mat &srcImage)
|
|
|
|
|
//{
|
|
|
|
|
// Mat mask;
|
|
|
|
|
// //Mat sobelImg = srcImage.clone();
|
|
|
|
|
// //genSobelImage(sobelImg);
|
|
|
|
|
// //sobelImg.convertTo(sobelImg, CV_8UC1);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// Mat sobelX, sobelY;
|
|
|
|
|
// Sobel(srcImage, sobelX, CV_32FC1, 1, 0, 3, BORDER_REPLICATE);
|
|
|
|
|
// Sobel(srcImage, sobelY, CV_32FC1, 0, 1, 3, BORDER_REPLICATE);
|
|
|
|
|
// Mat img = sobelX.mul(sobelX) + sobelY.mul(sobelY);
|
|
|
|
|
// Mat tempImg;
|
|
|
|
|
// img.convertTo(tempImg, CV_32FC1);
|
|
|
|
|
// Mat tempImg0;
|
|
|
|
|
// sqrt(tempImg, tempImg0);
|
|
|
|
|
// img = tempImg0;
|
|
|
|
|
// img.convertTo(img, CV_8UC1);
|
|
|
|
|
// Mat blurImg;
|
|
|
|
|
// cv::medianBlur(img, blurImg, 11);
|
|
|
|
|
// bgSubtractor(img, mask, 0.001);
|
|
|
|
|
//
|
|
|
|
|
// /*cv::Mat element5(5, 5, CV_8U, cv::Scalar(1));
|
|
|
|
|
// cv::Mat closedMat;
|
|
|
|
|
// cv::morphologyEx(mask, closedMat, cv::MORPH_CLOSE, element5);*/
|
|
|
|
|
//
|
|
|
|
|
// //cv::floodFill();
|
|
|
|
|
// luffy_base::luffyCircle pCircle;
|
|
|
|
|
//
|
|
|
|
|
// vector<cv::Mat> mats= ImageProcess::findCircleObject(mask, srcImage, 15, &pCircle);
|
|
|
|
|
// if (mats.size() == 0)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// if (mats[0].size() != mats[1].size())
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// Mat dilatedImgBin;
|
|
|
|
|
// Mat imgBinary = mats[0] > 0;
|
|
|
|
|
// dilate(imgBinary, dilatedImgBin, Mat::ones(5, 5, CV_32FC1));
|
|
|
|
|
// erode(dilatedImgBin, imgBinary, Mat::ones(5, 5, CV_32FC1));
|
|
|
|
|
// imgBinary = ~imgBinary;
|
|
|
|
|
// //Mat canvas(imgBinary.size(), imgBinary.type(), Scalar::all(0));
|
|
|
|
|
// vector<vector<Point>> cons;
|
|
|
|
|
// cv::findContours(imgBinary, cons, RETR_EXTERNAL, CHAIN_APPROX_NONE);
|
|
|
|
|
// for (const vector<Point> & pContour : cons)
|
|
|
|
|
// {
|
|
|
|
|
// const int& size = pContour.size();
|
|
|
|
|
// if (size < 200)
|
|
|
|
|
// {
|
|
|
|
|
// Mat(pContour).setTo(255);
|
|
|
|
|
// //continue;
|
|
|
|
|
// }
|
|
|
|
|
// //cv::fillPoly(canvas, vector<vector<Point>>(1, pContour), Scalar(255));
|
|
|
|
|
// }
|
|
|
|
|
// //Mat tarMat = (~canvas).mul(mats[1]) / 255;
|
|
|
|
|
// //openOper(imgBinary, Mat::ones(1, 13, CV_32FC1));
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// return;
|
|
|
|
|
//
|
|
|
|
|
//}
|
|
|
|
|
|