Ask Your Question
0

How to use templatematching cuda 7.5 and opencv 3.1

asked 2016-09-30 08:34:01 -0600

Lio gravatar image

Hi, I try to use template matching in c++ but it doesn't work. when I use this program, an error occur image description

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

using namespace std;
using namespace cv;

/// Global Variables
Mat img; Mat templ; Mat result; Mat img2;
//cuda::GpuMat img; cuda::GpuMat templ; cuda::GpuMat result; cuda::GpuMat img2;
char* image_window = "Source Image";
char* result_window = "Result window";

int match_method;
int max_Trackbar = 5;

/// Function Headers
void MatchingMethod(int, void*);

/** @function main */
int main(int argc, char** argv)
{
    /// Load image and template
    img = imread("../data/lena.jpg");
    templ = imread("../data/eye.jpg");

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

    imshow(image_window, img);

     //cuda::TemplateMatching *b;
    cv::Ptr<cv::cuda::TemplateMatching> b;
    b = cuda::createTemplateMatching(CV_32F, CV_TM_CCORR);// , Size(0, 0));
    b->match(img_Gpu, templ_Gpu, result_Gpu);//<--- this line create a bug



    //double minVal; double maxVal; Point minLoc; Point maxLoc;
    //Point matchLoc;

    //minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
    //rectangle(result, matchLoc, Point(matchLoc.x + templ.cols, matchLoc.y + templ.rows), Scalar::all(0), 2, 8, 0);



    imshow(result_window, img);

    waitKey(0);
    return 0;
}

Can you help me?

thank you

CONF-->GTX980M 16G RAM W10 VS2013

edit retag flag offensive close merge delete

Comments

1

you never initialize img_Gpu, or templ_Gpu.

(the definition is even commented away, the code you show won't even conpile)

please give us the real thing !

berak gravatar imageberak ( 2016-09-30 08:52:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-10-03 03:59:26 -0600

Lio gravatar image

updated 2016-10-03 06:59:25 -0600

Hello , I m sorry but its the real program , in my case the code compile ;(.

You can fin a new version of my programm with gpu mat initialization, but it still not working...

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

using namespace std;
using namespace cv;

/// Global Variables
Mat img; Mat templ; Mat result; Mat img2;
//cuda::GpuMat img; cuda::GpuMat templ; cuda::GpuMat result; cuda::GpuMat img2;
cuda::GpuMat img_Gpu;
cuda::GpuMat templ_Gpu;
cuda::GpuMat result_Gpu;

char* image_window = "Source Image";
char* result_window = "Result window"; 
char* patate = "patate";

int match_method;
int max_Trackbar = 5;

/// Function Headers
void MatchingMethod(int, void*);

/** @function main */
int main(int argc, char** argv)
{
    /// Load image and template
    img = imread("../data/lena.jpg");
    templ = imread("../data/eye.jpg");
    img_Gpu.upload(img);
    templ_Gpu.upload(templ);

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

    /// Create Trackbar
    //char* trackbar_label = "Method: \n 0: SQDIFF \n 1: SQDIFF NORMED \n 2: TM CCORR \n 3: TM CCORR NORMED \n 4: TM COEFF \n 5: TM COEFF NORMED";
    //createTrackbar(trackbar_label, image_window, &match_method, max_Trackbar, MatchingMethod);
    int bob = img.type();
    cout << "img = " << endl << " " << bob << endl << endl;

    imshow(image_window, img);

     //cuda::TemplateMatching *b;
    cv::Ptr<cv::cuda::TemplateMatching> b;
    b = cuda::createTemplateMatching(CV_32F, CV_TM_CCORR, Size(0, 0));
    //b->match(img, templ, result);
    b->match(img_Gpu, templ_Gpu, result_Gpu);
    //result_Gpu.download(result);
    //imshow(patate, result);


    //double minVal; double maxVal; Point minLoc; Point maxLoc;
    //Point matchLoc;

    //minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
    rectangle(img, Point(0 , 100 ), Point(100 ,0), Scalar::all(0), 2, 8, 0);
    //rectangle(result, matchLoc, Point(matchLoc.x + templ.cols, matchLoc.y + templ.rows), Scalar::all(0), 2, 8, 0);


    imshow(result_window, img);

    waitKey(0);
    return 0;
}

error message is : image description

Bug corrected!

edit flag offensive delete link more

Comments

Maybe a dumb question, but you did rebuild OpenCV yourself with the correct CUDA version support?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-10-03 08:31:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-30 08:34:01 -0600

Seen: 1,569 times

Last updated: Oct 03 '16