Ask Your Question

michael6688's profile - activity

2020-07-16 23:21:24 -0600 received badge  Famous Question (source)
2019-04-18 20:15:21 -0600 received badge  Popular Question (source)
2017-04-28 04:16:27 -0600 received badge  Notable Question (source)
2016-05-18 06:53:50 -0600 received badge  Popular Question (source)
2015-02-11 10:42:11 -0600 received badge  Student (source)
2014-11-05 13:58:50 -0600 asked a question Rotation Detection based on Template Matching

I have a source image and several template images. These template images are rotated by different degrees. If the template image is not rotated (or rotated by 0 degree), I can use the attached code to find the matched pattern in the source image. However, if the template image is rotated, the template matching method in OpenCV might not work. How can I revise the code to enable it to detect the matched rotated pattern, as well as the angle that it is rotated by?

Thanks in advance.

Source image: C:\fakepath\O.jpg Template image: C:\fakepath\T.jpg Template image rotated by 30 degrees: C:\fakepath\Tr30.jpg

cpp file: #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> #include <math.h>

using namespace std;
using namespace cv;

/// Global Variables
Mat img; Mat templ; Mat result;

char* result_window = "Result window";

int main( int argc, char** argv )
{
  /// Load image and template
  img = imread( argv[1], 1 );
  templ = imread( argv[2], 1 );

  /// Create windows
  namedWindow( result_window, CV_WINDOW_AUTOSIZE );

  int result_cols =  img.cols - templ.cols + 1;
  int result_rows = img.rows - templ.rows + 1;

  result.create( result_cols, result_rows, CV_32FC1 );

  /// Do the Matching and Normalize
  matchTemplate( img, templ, result, CV_TM_SQDIFF_NORMED );
  normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );


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


  /// Show me what you got
  rectangle( result, minLoc, Point( minLoc.x + templ.cols , minLoc.y + templ.rows ), Scalar::all(0), 2, 8, 0 );


  imshow( result_window, result );

  waitKey(0);
  return 0;
}
2014-10-23 13:26:47 -0600 received badge  Scholar (source)
2014-10-20 11:59:51 -0600 asked a question Detailed code of matchTemplate

Hi all,

I am just curious about whether it is possible for us to access the detailed codes of the OpenCV functions? For example, I am currently working on a project that involves the function of matchTemplate. I know how to use it, but I would like to know the detailed code of this function, and maybe make some modifications to it to better cater to my needs. So is it possible to access the code?

Thanks in advance!