OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
detect-test.cpp File Reference
#include <opencv/cv.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/objdetect.hpp>
#include <vector>
#include <iostream>
#include <string>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 31 of file detect-test.cpp.

32 {
33  vector<String> typeDesc;
34  String fileName;
35 
36  if (argc < 2)
37  {
38  help(argv[0]);
39  return 0;
40  }
41 
42  // This descriptor are going to be detect and compute
43  typeDesc.push_back("AKAZE-DESCRIPTOR_KAZE_UPRIGHT"); // see http://docs.opencv.org/trunk/d8/d30/classcv_1_1AKAZE.html
44  typeDesc.push_back("AKAZE"); // see http://docs.opencv.org/trunk/d8/d30/classcv_1_1AKAZE.html
45  typeDesc.push_back("ORB"); // see http://docs.opencv.org/trunk/de/dbf/classcv_1_1BRISK.html
46  typeDesc.push_back("BRISK"); // see http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html
47  typeDesc.push_back("CORNER"); // see http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html
48 
49  const String keys = "{@image1 | | Reference image } {help h | | }";
50  CommandLineParser parser(argc, argv, keys);
51  if (parser.has("help"))
52  {
53  help(argv[0]);
54  return 0;
55  }
56  fileName = parser.get<string>((int) 0);
57 
58  try
59  {
60  Mat img1 = imread(fileName, IMREAD_GRAYSCALE);
61  if (img1.rows * img1.cols <= 0)
62  {
63  cout << "Image " << fileName << " is empty or cannot be found\n";
64  return (0);
65  }
66 
67  vector<double> desMethCmp;
68  Ptr<Feature2D> b;
69 
70  // Descriptor loop
71  vector<String>::iterator itDesc;
72  for (itDesc = typeDesc.begin(); itDesc != typeDesc.end(); ++itDesc)
73  {
74  // keypoint for img1
75  vector<KeyPoint> keypoints;
76 
77  // Descriptor for img1
78  if (*itDesc == "AKAZE-DESCRIPTOR_KAZE_UPRIGHT")
79  b = AKAZE::create(AKAZE::DESCRIPTOR_KAZE_UPRIGHT);
80  else if (*itDesc == "AKAZE")
81  b = AKAZE::create();
82  else if (*itDesc == "ORB")
83  b = ORB::create();
84  else if (*itDesc == "BRISK")
85  b = BRISK::create();
86  else if (*itDesc == "CORNER")
87  b.release();
88  else
89  {
90  cout << "\nUnknown descriptor type requested: <"<<*itDesc<<">\n"<<endl;
91  return 0;
92  }
93 
94  Mat descImg1;
95  if (b)
96  {
97  // We can detect keypoint with detect method and then compute their descriptors:
98  b->detect(img1, keypoints);
99  b->compute(img1, keypoints, descImg1);
100 
101  }
102  else
103  {
104  // Next demo goodFaturesToTrack:
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);
111  }
112 
113  // Draw:
114  drawKeypoints(img1, keypoints, descImg1, Scalar::all(-1),
115  DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
116  namedWindow(*itDesc, WINDOW_AUTOSIZE);
117  imshow(*itDesc, descImg1);
118  }
119  waitKey();
120  }
121  catch (Exception& e)
122  {
123  cout << "\nHit exception: "<<e.msg << endl;
124  return 0;
125  }
126  return 0;
127 }