Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7025333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:57:39+00:00 2026-05-27T23:57:39+00:00

I am using openCV’s cvMatchTemplate method to find a smaller image in a bigger

  • 0

I am using openCV’s cvMatchTemplate method to find a smaller image in a bigger image. The \ method below is matching the existing pattern object with the given ‘current’ image, the found pattern is marked by a rectangle drawn on the current image. When the pattern is visible its finding it reliably, when not its drawing somewhere “random” which makes sense.

I have trouble computing the score of the template matching. Is there an easy to determine that? I was looking on various sites but could not find a solution and also been looking at the values computed by cvMinMaxLoc but could not find a way to determine the quality of the match.

- (void)detect:(IplImage *)current
{
int patchx = pattern->width;
int patchy = pattern->height;
int iwidth = current->width - patchx + 1;
int iheight = current->height - patchy + 1;

IplImage *result=cvCreateImage( cvSize(iwidth,iheight),IPL_DEPTH_32F, 1);
cvMatchTemplate( current, pattern, result, CV_TM_SQDIFF     );

CvPoint     minloc, maxloc;
double      minval, maxval;

cvMinMaxLoc( result, &minval, &maxval, &minloc, &maxloc, 0 );

/* draw red rectangle */
cvRectangle( current, 
            cvPoint( minloc.x, minloc.y ), 
            cvPoint( minloc.x + patchx, minloc.y + patchy ),
            cvScalar( 0, 255, 0, 0 ), 1, 0, 0 );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:57:39+00:00Added an answer on May 27, 2026 at 11:57 pm

    Use a normed metric like CV_TM_CCORR_NORMED or CV_TM_SQDIFF_NORMED and compare the minimum value to a threshold (between 0 and 1.0).

    cvMatchTemplate( current, pattern, result, CV_TM_SQDIFF_NORMED);
    
    if (minval < THRESHOLD) {
        /* draw red rectangle */
        cvRectangle( current, 
                cvPoint( minloc.x, minloc.y ), 
                cvPoint( minloc.x + patchx, minloc.y + patchy ),
                cvScalar( 0, 255, 0, 0 ), 1, 0, 0 );
    } else {
        //not found
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im using opencv's HaarDetectObjects(...) to detect an object in an image. The function returns
I am trying to do some image matching using OpenCV and am using the
I'm using OpenCV to iterate through an image and find the colour of each
I'm doing background subtraction using opencv. The problem is the foreground object is not
How can I subtract one image from another using openCV? Ps.: I coudn't use
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am using opencv for real-time template matching. The camera yields at 52fps grayscale
I'm trying to display an image using OpenCV. I have the following very basic
I am using OpenCV 2.3.1 in Android. I need to crop the image into
I am using OpenCV Haar Algorithm to track the Head and overlay an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.