1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <string>
 
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/cudafeatures2d.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudafilters.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/cudawarping.hpp>
 
using namespace cv;
using namespace std;
 
int main(int argc, char** argv)
{
 
    while (1)
    {
 
        Mat frameMat01 = imread("frame01.jpg");
        Mat frameMat02 = imread("frame02.jpg");
        
        clock_t beginend;
        begin = clock();
 
        cuda::GpuMat cuFrameMat01, cuFrameMat02;
        cuFrameMat01.upload(frameMat01);
        cuFrameMat02.upload(frameMat02);
        
        cuda::cvtColor(cuFrameMat01, cuFrameMat01, CV_BGR2GRAY);
        cuda::cvtColor(cuFrameMat02, cuFrameMat02, CV_BGR2GRAY);
 
        Ptr<cuda::ORB> orb = cuda::ORB::create(10001.2f, 83102, ORB::HARRIS_SCORE, 3120false);
 
        cuda::GpuMat cuMask01(frameMat01.rows, frameMat01.cols, CV_8UC1, cv::Scalar::all(1)); //330,215
        cuda::GpuMat cuMask02(frameMat02.rows, frameMat02.cols, CV_8UC1, cv::Scalar::all(1)); //315,235
 
        cuda::GpuMat cuKeyPoints01, cuKeyPoints02;
        cuda::GpuMat cuDescriptors01, cuDescriptors02;
 
        orb->detectAndComputeAsync(cuFrameMat01, cuMask01, cuKeyPoints01, cuDescriptors01);
        orb->detectAndComputeAsync(cuFrameMat02, cuMask02, cuKeyPoints02, cuDescriptors02); 
 
        Ptr<cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_HAMMING);
        cuda::GpuMat gpuMatchesMat;
        matcher->knnMatchAsync(cuDescriptors01, cuDescriptors02, gpuMatchesMat, 2, noArray());
        vector<vector<DMatch>> knnMatchesVec;
        
 
        waitKey();
    }
 
 
    waitKey(0);
    return 0;
}
cs