testgpu.cc

Tsung-Hsiang Chang, 2011-08-28 05:54 pm

Download (1 kB)

 
1
#include <opencv2/gpu/gpu.hpp>
2
#include <opencv2/opencv.hpp>
3
#include<iostream>
4
5
using namespace std;
6
using namespace cv;
7
8
int main(){
9
   gpu::GpuMat gSource, gTarget, gResult;
10
   Mat source, target, result;
11
   double min, max;
12
   Point min_loc, max_loc;
13
   source = imread("source-1.png");
14
   target = imread("target-1.png");
15
   gSource.upload(source);
16
   gTarget.upload(target);
17
18
   gpu::matchTemplate(gSource,gTarget,gResult,CV_TM_CCOEFF_NORMED);
19
   gpu::minMaxLoc(gResult, &min, &max, &min_loc, &max_loc);
20
   cout << "gpu min: " << min << ", max: " << max << endl;
21
   cout << "gpu min location: " << min_loc.x << "," << min_loc.y 
22
        << ", max location: "  << max_loc.x << "," << max_loc.y  << endl;
23
24
   matchTemplate(source,target,result,CV_TM_CCOEFF_NORMED);
25
   minMaxLoc(result, &min, &max, &min_loc, &max_loc);
26
   cout << "cpu min: " << min << ", max: " << max << endl;
27
   cout << "cpu min location: " << min_loc.x << "," << min_loc.y 
28
        << ", max location: "  << max_loc.x << "," << max_loc.y  << endl;
29
}