11 #include <opencv/cv.h> 12 #include <opencv2/imgproc.hpp> 13 #include <opencv2/highgui.hpp> 14 #include <opencv2/features2d.hpp> 15 #include <opencv2/objdetect.hpp> 23 static void help(
const char* appname)
25 cout <<
"\nThis program demonstrates how to detect and compute ORB BRISK and AKAZE descriptors \n" 26 "\nUsage: "<<appname<<
" <image> \n" 27 "\nPress a key on active image window to proceed to the following descriptor.\n" 31 int main(
int argc,
char *argv[])
33 vector<String> typeDesc;
43 typeDesc.push_back(
"AKAZE-DESCRIPTOR_KAZE_UPRIGHT");
44 typeDesc.push_back(
"AKAZE");
45 typeDesc.push_back(
"ORB");
46 typeDesc.push_back(
"BRISK");
47 typeDesc.push_back(
"CORNER");
49 const String keys =
"{@image1 | | Reference image } {help h | | }";
50 CommandLineParser parser(argc, argv, keys);
51 if (parser.has(
"help"))
56 fileName = parser.get<
string>((int) 0);
60 Mat img1 = imread(fileName, IMREAD_GRAYSCALE);
61 if (img1.rows * img1.cols <= 0)
63 cout <<
"Image " << fileName <<
" is empty or cannot be found\n";
67 vector<double> desMethCmp;
71 vector<String>::iterator itDesc;
72 for (itDesc = typeDesc.begin(); itDesc != typeDesc.end(); ++itDesc)
75 vector<KeyPoint> keypoints;
78 if (*itDesc ==
"AKAZE-DESCRIPTOR_KAZE_UPRIGHT")
79 b = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);
80 else if (*itDesc ==
"AKAZE")
82 else if (*itDesc ==
"ORB")
84 else if (*itDesc ==
"BRISK")
86 else if (*itDesc ==
"CORNER")
90 cout <<
"\nUnknown descriptor type requested: <"<<*itDesc<<
">\n"<<endl;
98 b->detect(img1, keypoints);
99 b->compute(img1, keypoints, descImg1);
105 vector<Point2f> features;
106 int maxCorners = 1000;
107 double qualityLevel = 0.001;
108 double minDistance = 5.0;
109 goodFeaturesToTrack(img1, features, maxCorners, qualityLevel, minDistance);
110 KeyPoint::convert(features, keypoints, 10.0);
114 drawKeypoints(img1, keypoints, descImg1, Scalar::all(-1),
115 DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
116 namedWindow(*itDesc, WINDOW_AUTOSIZE);
117 imshow(*itDesc, descImg1);
123 cout <<
"\nHit exception: "<<e.msg << endl;
int main(int argc, char *argv[])