Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Template matching giving incorrect location

When i perform the openCV template matching, i for some reason get my min location to be at the upper left corner, and my max location to be at the upper right corner, which is not where my template is.. I don't why i doesn't perform like that..

it implemented as such.

Point ImageConverter::normCrossCorrelation(Mat imgI,vector<Point2f> points1, vector<uchar> status, int method)
{
    Mat res,rec1;
    Size size(307,230);
    for(int i = 0; i <= points1.size(); i++)
    {
        if(status[i] == 1)
        {
            getRectSubPix(imgI,size,points1[i],rec1);
            matchTemplate(rec1, ROI, res, method);
            //cout << ((float *)(res.operator _IplImage().imageData))[0] << endl;
        }
    }
    normalize(res,res,0,1,NORM_MINMAX,-1,cv::Mat());
    double minVal,maxVal;
    Point minLoc,maxLoc;

    minMaxLoc(res,&minVal,&maxVal,&minLoc,&maxLoc,cv::Mat());

    cout << "new location: " << maxLoc << " Maxval: " << maxVal << endl; 
    return minLoc;
}

The image is a gray image, and it doesn't matter which method i use.. The result is always the same.. what am I doing wrong?

Template matching giving incorrect location

When i perform the openCV template matching, i for some reason get my min location to be at the upper left corner, and my max location to be at the upper right corner, which is not where my template is.. I don't why i doesn't perform like that..

it implemented as such.

Point ImageConverter::normCrossCorrelation(Mat imgI,vector<Point2f> points1, vector<uchar> status, int method)
{
    Mat res,rec1;
    Size size(307,230);
    for(int i = 0; i <= points1.size(); i++)
    {
        if(status[i] == 1)
        {
            getRectSubPix(imgI,size,points1[i],rec1);
            matchTemplate(rec1, ROI, res, method);
            //cout << ((float *)(res.operator _IplImage().imageData))[0] << endl;
        }
    }
    normalize(res,res,0,1,NORM_MINMAX,-1,cv::Mat());
    double minVal,maxVal;
    Point minLoc,maxLoc;

    minMaxLoc(res,&minVal,&maxVal,&minLoc,&maxLoc,cv::Mat());

    cout << "new location: " << maxLoc << " Maxval: " << maxVal << endl; 
    return minLoc;
}

The image is a gray image, and it doesn't matter which method i use.. The result is always the same.. what am I doing wrong?

Here is some test images http://imgur.com/2iooqbI

Template matching giving incorrect location

When i perform the openCV template matching, i for some reason get my min location to be at the upper left corner, and my max location to be at the upper right corner, which is not where my template is.. I don't why i doesn't perform like that..

it implemented as such.

Point ImageConverter::normCrossCorrelation(Mat imgI,vector<Point2f> points1, vector<uchar> status, int method)
{
    Mat res,rec1;
    Size size(307,230);
    for(int i = 0; i <= points1.size(); i++)
    {
        if(status[i] == 1)
        {
            getRectSubPix(imgI,size,points1[i],rec1);
            matchTemplate(rec1, ROI, res, method);
            //cout << ((float *)(res.operator _IplImage().imageData))[0] << endl;
        }
    }
    normalize(res,res,0,1,NORM_MINMAX,-1,cv::Mat());
    double minVal,maxVal;
    Point minLoc,maxLoc;

    minMaxLoc(res,&minVal,&maxVal,&minLoc,&maxLoc,cv::Mat());

    cout << "new location: " << maxLoc << " Maxval: " << maxVal << endl; 
    return minLoc;
}

The image is a gray image, and it doesn't matter which method i use.. The result is always the same.. what am I doing wrong?

Here is some test images http://imgur.com/2iooqbI http://imgur.com/2iooqbI

Template matching giving incorrect location

When i perform the openCV template matching, i for some reason get my min location to be at the upper left corner, and my max location to be at the upper right corner, which is not where my template is.. I don't why i doesn't perform like that..

it implemented as such.

Point ImageConverter::normCrossCorrelation(Mat imgI,vector<Point2f> points1, vector<uchar> status, int method)
{
    Mat res,rec1;
    Size size(307,230);
    for(int i = 0; i <= points1.size(); i++)
    {
        if(status[i] == 1)
        {
            getRectSubPix(imgI,size,points1[i],rec1);
            matchTemplate(rec1, ROI, res, method);
            //cout << ((float *)(res.operator _IplImage().imageData))[0] << endl;
        }
    }
    normalize(res,res,0,1,NORM_MINMAX,-1,cv::Mat());
    double minVal,maxVal;
    Point minLoc,maxLoc;

The full code can be viewed on my github. minMaxLoc(res,&minVal,&maxVal,&minLoc,&maxLoc,cv::Mat()); cout << "new location: " << maxLoc << " Maxval: " << maxVal << endl; return minLoc; }

https://github.com/Keerthikan/PTU-Facetracker/blob/master/templateMathing/templateMathing/main.cpp

The image is a gray image, and it doesn't matter which method i use.. The result is always the same.. what am I doing wrong?

Here is some test images http://imgur.com/2iooqbI http://imgur.com/2iooqbI

Template matching giving incorrect location

When i perform the openCV template matching, i for some reason get my min location to be at the upper left corner, and my max location to be at the upper right corner, which is not where my template is.. I don't why i doesn't perform like that..

it implemented as such.

The full code can be viewed on my github. https://github.com/Keerthikan/PTU-Facetracker/blob/master/templateMathing/templateMathing/main.cpp

The image is a gray image, and it doesn't matter which method i use.. The result is always the same.. what am I doing wrong?

Here is some test images http://imgur.com/2iooqbI http://imgur.com/2iooqbI