diff --git a/tpvs17/valveDetector/valveDetector.cpp b/tpvs17/valveDetector/valveDetector.cpp index 632a63c..6bb130c 100644 --- a/tpvs17/valveDetector/valveDetector.cpp +++ b/tpvs17/valveDetector/valveDetector.cpp @@ -366,7 +366,7 @@ double tempScoreShoot(Mat &_img, Mat &template_img, detectMode mode) calcHist(&normTemplateDir, 1, 0, Mat(), templateHist, 1, &histSize, &histRange, true, false); calcHist(&normTemporaryDir, 1, 0, Mat(), temporaryHist, 1, &histSize, &histRange, true, false); -//#ifdef VEIW_HISTGRAM +#ifdef VEIW_HISTGRAM Mat dstImage = Mat::zeros(512, 800, CV_8UC3); //normalize(templateHist, templateHist, 0, histImage.rows, NORM_MINMAX, -1, Mat()); @@ -410,7 +410,7 @@ double tempScoreShoot(Mat &_img, Mat &template_img, detectMode mode) cv::putText(dstImage, string, Point(xAxis*(dstImage.cols / 360), dstImage.rows), 1, 1, Scalar(0, 255, 255)); } -//#endif // VEIW_HISTGRAM +#endif // VEIW_HISTGRAM switch (mode) { case shootWheelExist: @@ -1364,17 +1364,17 @@ bool ValveDetector::detect(Mat & imgSrc, InputParam ¶mIn, OutputParam ¶m float fMin = 1000; int nIndex = 0; - //std::map scoreMapIndex; + std::map scoreMapIndex; for (int i = 0; i < ret.cols; i++) { float fSum = sum(ret.col(i))[0]; - //scoreMapIndex[fSum] = i; + scoreMapIndex[fSum] = i; if (fSum < fMin) { fMin = fSum; nIndex = i; } } - /* std::map::iterator it = scoreMapIndex.begin(); + std::map::iterator it = scoreMapIndex.begin(); int candidateIndex = 0; int ni = 0; for (; it != scoreMapIndex.end(); ++it, ++ni) @@ -1383,18 +1383,30 @@ bool ValveDetector::detect(Mat & imgSrc, InputParam ¶mIn, OutputParam ¶m { candidateIndex = it->second; } - }*/ + } //FOR MOTORCIRCLE END double mcutOffset = 1.0; float ss = 0.0; if (paramIn.wheelType == 0) { + mcutOffset = 2.0; + + // FOR MOTORCIRCLE PROGRAM START Mat imgTemplate = paramIn.imgTemplate(Rect(0, 0, paramIn.imgTemplate.cols, paramIn.imgTemplate.rows / mcutOffset)); - Mat identicalImg = vecImg[nIndex](Rect(10, 0, imgTemplate.cols, imgTemplate.rows)); + Mat ret0; + matchTemplate(vecImg[nIndex], imgTemplate, ret0, CV_TM_CCORR_NORMED); + Point p0; + double v0 = luffy_math::getMinMaxData(ret0, luffy_math::emDataMax, &p0); - // FOR MOTORCIRCLE PROGRAM START + Mat ret1; + matchTemplate(vecImg[candidateIndex], imgTemplate, ret1, CV_TM_CCORR_NORMED); + Point p1; + double v1 = luffy_math::getMinMaxData(ret1, luffy_math::emDataMax, &p1); + nIndex = v1 > v0 ? candidateIndex : nIndex; + + Mat identicalImg = vecImg[nIndex](Rect(10, 0, imgTemplate.cols, imgTemplate.rows)); double disVal = tempScoreShoot(identicalImg, imgTemplate, detectMode::shootTargetMatch); std::vector vecMat; @@ -1419,13 +1431,14 @@ bool ValveDetector::detect(Mat & imgSrc, InputParam ¶mIn, OutputParam ¶m disVal = s; } } - + int targetIndex = nIndex; float maxVal = disVal; if (disVal < 0.85) { + float vMax = FLT_MIN; for (int k = 0; k < vecImg.size(); k++) { if (k == nIndex) @@ -1434,15 +1447,40 @@ bool ValveDetector::detect(Mat & imgSrc, InputParam ¶mIn, OutputParam ¶m } else { - identicalImg = vecImg[k](Rect(10, 0, imgTemplate.cols, imgTemplate.rows)); - disVal = tempScoreShoot(identicalImg, imgTemplate, detectMode::shootTargetMatch); - if (disVal > maxVal) + + Mat imgRet; + matchTemplate(vecImg[k], imgTemplate, imgRet, CV_TM_CCORR_NORMED); + Point pnt; + double v3 = luffy_math::getMinMaxData(imgRet, luffy_math::emDataMax, &pnt); + if (v3 > vMax) { - maxVal = disVal; targetIndex = k; + vMax = v3; } + } } + /*identicalImg = vecImg[targetIndex](Rect(10, 0, imgTemplate.cols, imgTemplate.rows)); + vector localMatVec; + imgCrop(vecImg[targetIndex], localMatVec); + + for each (Mat mat in localMatVec) + { + double s = tempScoreShoot(mat, imgTemplate, detectMode::shootTargetMatch); + if (s > disVal) + { + disVal = s; + } + } + */ + + /*disVal = tempScoreShoot(identicalImg, imgTemplate, detectMode::shootTargetMatch); + + if (disVal > maxVal) + { + maxVal = disVal; + targetIndex = k; + }*/ } nIndex = targetIndex; Mat imgMatchRet;