1 | #include <opencv2/opencv.hpp>
|
2 | #include <opencv2/features2d/features2d.hpp>
|
3 | #include <iostream>
|
4 | #include <vector>
|
5 |
|
6 | using namespace cv;
|
7 | using namespace std;
|
8 | int main()
|
9 | {
|
10 |
|
11 | string test_im_file = "test_front_im.png";
|
12 |
|
13 | Mat im = imread(test_im_file);
|
14 | Mat im2;
|
15 | vector<KeyPoint> keypoints;
|
16 |
|
17 |
|
18 | cout << "Doing SIFT " <<endl;
|
19 |
|
20 | SIFT sift;
|
21 | cv::Mat descriptors;
|
22 | cv::cvtColor(im,im2,CV_RGB2GRAY);
|
23 | im2.convertTo(im2,CV_8UC1);
|
24 | sift(im2,Mat(),keypoints,descriptors,false);
|
25 |
|
26 | sift(im2,Mat(),keypoints,descriptors,true);
|
27 |
|
28 | Size s =descriptors.size() ;
|
29 | cout << "Number of keypoints found: " << keypoints.size() << endl;
|
30 | cout << "Descriptor size: " << s.width << endl;
|
31 |
|
32 | cout << "Doing SURF" <<endl;
|
33 |
|
34 | SURF surf(1.2,4,2,false,true);
|
35 | vector<float> descriptors2;
|
36 |
|
37 | surf(im2,Mat(),keypoints,descriptors2,true);
|
38 |
|
39 | int s2 =descriptors2.size() ;
|
40 | cout << "Number of keypoints found: " << keypoints.size() << endl;
|
41 | cout << "Descriptor size: " << s2/keypoints.size() << endl;
|
42 |
|
43 | cout << "Doing ORB" << endl;
|
44 |
|
45 | Mat descriptors3;
|
46 | vector<KeyPoint> keypoints3;
|
47 | ORB orb;
|
48 |
|
49 | cout << endl;
|
50 | orb(im2,Mat(),keypoints3,descriptors3,false);
|
51 | cout << "Number of keypoints found when orb detects keypoints: " << keypoints3.size() << endl;
|
52 | orb(im2,Mat(),keypoints3,descriptors3,true);
|
53 |
|
54 | s = descriptors3.size();
|
55 | cout << "Number of keypoints found when the same keypoints are provided: " << keypoints3.size() << endl;
|
56 | cout << "Descriptor size: " << s.width << endl;
|
57 |
|
58 | cout << "Done!"<< endl;
|
59 | } |