1

I am new to image processing , In my application i am detecting eye iris using template matching , So i string a standard iris and performing template matching ,The code is given below

CvInvoke.cvMatchTemplate(grayframeright_1.Ptr, templateimagegray.Ptr, templateimagesults.Ptr, TM_TYPE.CV_TM_CCORR_NORMED);

templateimagesults.MinMax(out min, out max, out Min_Loc, out MAX_Loc);

                            Location = new Point((MAX_Loc[0].X), (MAX_Loc[0].Y));

The problems is some times i get false positives , in order to eliminate false positive , i planned to calculate/get matching percentage value and use appropriate if condition.

1)So are there any functions in emgucv/opencv to get the matching percentage value? for e.g - 50% , 80% and etc

2)Are there any other ways to eliminate false positives ?

Please help me to figure this out .

Thanks in advance

gouthaman93
  • 290
  • 4
  • 19

2 Answers2

1
  1. it think the value in templateimagesults.Ptr at the location of respected location is the matching percentage you want, it is the similarity value of the template with the windowed image at the specific location. refer to: http://docs.opencv.org/modules/imgproc/doc/object_detection.html

  2. reducing false positives and improve recalling is always balanced in these job, you should not just focus on reducing false positives. maybe you can try to using standard machine learning framework for object detecting

michaeltang
  • 2,850
  • 15
  • 18
1

"opencv template matching" actually does not provide the document to determine the matching percentage value, however, if you really want to get the accuracy from matching, maybe you can use following method:

  double maxThd = 0.7;
  double minThd = 0.3;

  matchTemplate( img, templ, result, match_method );
  normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );

  /// Localizing the best match with minMaxLoc
  double minVal; double maxVal; Point minLoc(-1,-1); Point maxLoc(-1,-1);
  Point matchLoc;

  minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );

  /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better
  if( match_method == CV_TM_SQDIFF_NORMED && minVal < minThd)
    { matchLoc = minLoc; }
  else if(match_method == CV_TM_CCORR_NORMED && maxVal > maxThd)
    { matchLoc = maxLoc; }

  bool isMatch = matchLoc != cv::Point(-1,-1);
  if(isMatch) {
  // Show the result here!
  }

And the more information, you can refer to

Opencv Template Matching

The recommend Machine Learning Tutorial

Advance image matching, pls refer to matchine learning, e.g. neural network

Community
  • 1
  • 1
RyanLiu
  • 1,557
  • 2
  • 18
  • 27
  • Than you for your answer ,It was very valuable, can you please explain why do we use this code cv::Point(-1,-1)? – gouthaman93 Feb 10 '14 at 18:35
  • ok!Maybe the new edition is more easy to understand.It means that the template object was found from test image when the "matchLoc != cv::Point(-1,-1)" holds, and why using cv::Point(-1,-1), because I initialize the all matchLoc(minLoc, maxLoc) to the unreal point (-1,-1) to determine whether the object is exist or not! – RyanLiu Feb 11 '14 at 04:26
  • very clear explanation , I also want to know why do we use this code 'normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );' , I searched some documentation ,but did not understand ... Please don't mistake me for asking more explanation. – gouthaman93 Feb 11 '14 at 15:56
  • 'normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );', this code I just refer to document on opencv, and I think it can be removed that will affect nothing. – RyanLiu Feb 13 '14 at 02:34