Ask Your Question
0

OpenCV CUDA matchTemplate

asked 2012-10-05 14:08:00 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Helo,

I have tried making a project with OPENCV 2.4.0 using cuda. But the result is still the same as witout cuda. Am I doing something wrong. I have done everything acording the tutorial: http://opencv.willowgarage.com/wiki/InstallGuide all si working but the result is still the same. The alghorith in 2.1 is 4 ms fast and in 2.4.0 with cuda is 4 ms fast.

Here is the code below:


//Programa

double diffclock(clock_t clock1,clock_t clock2)
{
    double diffticks=clock1-clock2;
    double diffms=(diffticks*10)/CLOCKS_PER_SEC*(-1);
    return diffms;
}

int main(int argc, CHAR* argv[])
{
    //Nuskaitomi paveikslai
    IplImage *img_main = cvLoadImage("main.jpg");
    IplImage *img_sub = cvLoadImage("sub.jpg");

    //Incializuojamas rezultato kintamasis
    int subx = img_sub->width;
    int suby = img_sub->height;
    int iwidth = img_main->width - subx + 1;
    int iheight = img_main->height - suby + 1;
    IplImage *result=cvCreateImage( cvSize(iwidth,iheight),IPL_DEPTH_32F, 1);

    //Aprasomi kintamieji reikalingi korecialijai
    CvPoint     minloc, maxloc;
    double      minval, maxval;

    //Isvedami pradiniai vaizdai
    cvNamedWindow("Main:",1);
    cvShowImage("Main:",img_main);
    cvNamedWindow("Sub:",1);
    cvShowImage("Sub:",img_sub);

    //Atliekama koreliacija ir matuojamas veikimo laikas
    clock_t start = clock();
    for(int i=0;i<1;i++)
    {
        cvMatchTemplate(img_main,img_sub,result,1);
        cvMinMaxLoc( result, &minval, &maxval, &minloc, &maxloc, 0 );
    }
    clock_t finish = clock();
    cout << "Time elapsed: " << double(diffclock(start,finish)) << " ms"<< endl;

    //Breziamas keturkampis didziausia koreliacija turincioje vietoje
    cvRectangle( img_main, cvPoint( minloc.x, minloc.y ), cvPoint( minloc.x + subx, minloc.y + suby ), cvScalar( 0, 255, 0, 0 ), 1, 0, 0 );

    //Atvaizduojamas rezultatas
    cvNamedWindow("Result:",1);
    cvShowImage("Result:",img_main);

    //Pauze ir sunaikinami visi naudoti langai ir kintamieji
    cvWaitKey();
    cvDestroyWindow("Main:");
    cvDestroyWindow("Sub:");
    cvDestroyWindow("Result:");
    cvReleaseImage(&img_main);
    cvReleaseImage(&img_sub);

    return 0;
}

looking forward to your answers

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-10-06 03:37:20 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

CUDA support is implemented in separate gpu module. You should explicitly use functions and classes from gpu module to run your code in GPU. Read documentation and tutorials for more information:

http://docs.opencv.org/modules/gpu/doc/gpu.html

http://docs.opencv.org/doc/tutorials/gpu/table_of_content_gpu/table_of_content_gpu.html

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-10-05 14:08:00 -0500

Seen: 581 times

Last updated: Oct 06 '12