Ask Your Question

Aditya's profile - activity

2017-07-05 14:51:08 -0600 received badge  Popular Question (source)
2015-08-11 19:32:17 -0600 received badge  Popular Question (source)
2013-04-02 02:03:37 -0600 received badge  Student (source)
2013-04-02 01:59:50 -0600 asked a question template matching in multiple images

My application does the following http://answers.opencv.org/question/10388/template-matching-in-multiple-images/

When i am reading the image for the first time , it is working. But for the second time onwards, its giving the following error.

OpenCV Error: Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F) && img.type() == templ.type()) in unknown function, file ......\src\o pencv\modules\imgproc\src\templmatch.cpp, line 249.

My code is as folllows :

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <conio.h>

using namespace std;
using namespace cv;
int match_method;
Mat img;

int arr[2][2];
float MatchingMethod( int, void*, Mat i, Mat t , int p , int q, float ft)
{
  Mat img_display;
  Mat result;
  i.copyTo( img_display );

  int result_cols =  i.cols - t.cols + 1;
  int result_rows = i.rows - t.rows + 1;

  result.create( result_cols, result_rows, CV_32FC1 );

  matchTemplate( i, t, result, match_method );
  normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() );

  double minVal;
  double maxVal; 

  Point minLoc; 
  Point maxLoc;
  Point matchLoc;

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

  matchLoc = maxLoc;

  arr[p][q] = matchLoc.x;
  arr[p][q+1] = matchLoc.y;
  ft=result.at<float>(matchLoc.x, matchLoc.y);
  return ft;
}



void main (int , char** argv)
{
    FILE *fp;
    Mat temp[5];
    int i=0,j=0,z=0;
    char a[10];
    char buffer[120];
    cout<< " Program starting " << endl ;
    img = imread( argv[1], 1 );
    fp=fopen("input.txt", "r");
    waitKey(0);
    if( fp==NULL )
    {   
        printf( "Error Opening file ");
    }

    fread(buffer,80,1,fp);
    while(buffer[i]!='\0')
    {
        for(i=0;buffer[i]!= ' ' && buffer[i]!= '\0' ;i++)
        {
            a[j++]=buffer[i];
        }
        a[j]='\0';

        temp[z++] = imread (a, 1);
        cout << " image reading successful " << endl;
        Mat temp1= temp[z];
        cout << " success " ;
        i++;
        float ft1=0.0;
        ft1= MatchingMethod( 0, 0, img, temp1, 0, 0 , ft1);
        cout<< "x" <<arr[0][0] << " y "<< arr[0][1]<< "ft1 "<< ft1<<endl;
    }
    waitKey(0);
    return;
}

Any help will be appreciated.

If this doesnt work, the last thing i can do is call the program for all 5( or maybe 20) images, which will degrade the performance of my app. tremandously. and i dont want to do that.

Thank you.

2013-04-02 01:42:38 -0600 commented answer template matching in multiple images

Thanx. It helped. Cant believe people still want to help others :)

2013-03-30 01:29:55 -0600 asked a question template matching in multiple images

I am using template matching to find the source in template image. I want to check the source in multiple images and find the best available match. What template matching does is, it returns the closest available match. So even if the source ain't there in template, the application returns something as the match. and i am getting (say) 5 outputs for 5 template images, one for each. Can anybody tell me how can i see the results of the matches before printing them, so that i can select the best match and select it as the result ???

2013-03-29 07:03:39 -0600 received badge  Supporter (source)
2013-03-29 06:55:42 -0600 commented answer template matching in multiple images

And how am i supposed to do that ??? Sorry for asking such question, but i am new to this :( And thanx for replying.

2013-03-29 06:27:05 -0600 asked a question template matching in multiple images

How can i Access result from matchTemplate(InputArray image, InputArray templ, OutputArray result, int method) ???

2013-03-14 07:11:14 -0600 asked a question How to compile OpenCV 2.4.4 with MS-VS2010 and Cmake

How to Compile OpenCV 2.4.4 with Microsoft Visual Studio 2010 using CMake (any downloadable version). I want to use template matching in my Final Year project and I cant build my own libraries with deadlines approaching. Any help will be much appreciated.

Also if there is any other way to compile OpenCV 2.4.4 libraries with VS 2010, then tell me.

2013-03-14 07:07:05 -0600 asked a question How to compile OpenCV 2.4.4 with MS-VS2010 and Cmake

How to Compile OpenCV 2.4.4 with Microsoft Visual Studio 2010 using CMake (any downloadable version). I want to use template matching in my Final Year project and I cant build my own libraries with deadlines approaching. Any help will be much appreciated.

Also if there is any other way to compile OpenCV 2.4.4 libraries with VS 2010, then tell me.