main.cpp

The code i have used - Tim Zaman, 2012-03-25 05:45 pm

Download (1.4 kB)

 
1
#include <iostream>
2
#include <string.h>
3
#include <algorithm> //max_element and min_element
4
#include <math.h>
5
#include <stdio.h>
6
#include <stdlib.h>
7
#include <cstdio>
8
#include <ctime>
9
#include <time.h>
10
#include <libgen.h>
11
#include "opencv2/core/core.hpp"
12
#include "opencv2/features2d/features2d.hpp"
13
#include "opencv2/highgui/highgui.hpp"
14
#include "opencv2/calib3d/calib3d.hpp"
15
#include "opencv2/imgproc/imgproc.hpp"
16
#include "opencv2/opencv.hpp"
17
#include "opencv2/gpu/gpu.hpp"
18
19
20
#include "/usr/local/cuda/include/cuda_runtime_api.h"
21
22
23
using namespace std;
24
using namespace cv;
25
26
27
int main( int argc, char** argv )
28
{
29
30
        Mat scene = imread ( "scene.jpg",1);
31
        Mat templ = imread ( "template.jpg",1);
32
        
33
        //Split to 1 channel
34
        vector<Mat> rgbImg(3);
35
        split(scene, rgbImg);
36
        Mat scene1chan=rgbImg[0];
37
        
38
        vector<Mat> rgbImg2(3);
39
        split(templ, rgbImg2);
40
        Mat templ1chan=rgbImg2[0];
41
        
42
        //Upload to GPU mem
43
        gpu::GpuMat gpu_scene, gpu_templ;
44
        gpu_scene.upload(scene1chan);
45
        gpu_templ.upload(templ1chan);
46
        
47
        double minVal; double maxVal; Point minLoc; Point maxLoc;
48
        
49
        gpu::GpuMat gpu_result;
50
        gpu_result.create(gpu_scene.rows-gpu_templ.rows+1 , gpu_scene.cols-gpu_templ.cols+1 , CV_32F);
51
        gpu::matchTemplate(gpu_scene, gpu_templ, gpu_result,CV_TM_SQDIFF);
52
        gpu::minMaxLoc(gpu_result, &minVal, &maxVal, &minLoc, &maxLoc );
53
        
54
        Mat result=gpu_result;
55
        namedWindow("result", 0);
56
        imshow( "result", result );
57
        waitKey(0);
58
        
59
        return(0);
60
}
61
62
63
64
65
66
67
68