SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
CVFeatureManager.cpp
Go to the documentation of this file.
1 /**
2  * \file CVFeatureManager.cpp
3  * \brief OpenCV Detector Describer Wrapper
4  * \date Spring 2017
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 /*
12 The OpenCV library version 3.4 or above with extra module must be present.
13 If the application captures the live video stream with OpenCV you have
14 to define in addition the constant APP_USES_CVCAPTURE.
15 All classes that use OpenCV begin with CV.
16 See also the class docs for CVCapture, CVCalibration and CVTracked
17 for a good top down information.
18 */
19 
20 #include <CVFeatureManager.h>
21 #include <CVRaulMurOrb.h>
22 #include <Utils.h>
23 #include <algorithm> // std::max
24 
25 //-----------------------------------------------------------------------------
27 {
29 }
30 //-----------------------------------------------------------------------------
32 {
33 }
34 //-----------------------------------------------------------------------------
35 //! Creates a detector and decriptor to the passed type
37 {
38  switch (type)
39  {
40 #ifndef __EMSCRIPTEN__
41  case DDT_FAST_BRIEF:
42  _detector = cv::FastFeatureDetector::create(30,
43  true,
44  cv::FastFeatureDetector::TYPE_9_16);
45  _descriptor = cv::xfeatures2d::BriefDescriptorExtractor::create(32, true);
46  break;
47 #endif
48  case DDT_ORB_ORB:
49  _detector = cv::ORB::create(200,
50  1.44f,
51  3,
52  31,
53  0,
54  2,
55  cv::ORB::HARRIS_SCORE,
56  31,
57  30);
59  break;
60  case DDT_RAUL_RAUL:
61  _detector = new CVRaulMurOrb(1500,
62  1.44f,
63  4,
64  30,
65  20);
67  break;
68 #ifndef __EMSCRIPTEN__
69  case DDT_SURF_SURF:
70  _detector = cv::xfeatures2d::SURF::create(100,
71  2,
72  2,
73  false,
74  false);
76  break;
77  case DDT_SIFT_SIFT:
78 # if CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 5
79  _detector = cv::SIFT::create(300,
80  2,
81  0.04,
82  10,
83  1.6);
84 # else
85  _detector = cv::xfeatures2d::SIFT::create(300,
86  2,
87  0.04,
88  10,
89  1.6);
90 # endif
92  break;
93 #endif
94  default:
95  Utils::exitMsg("SLProject",
96  "Unknown detector-descriptor type.",
97  __LINE__,
98  __FILE__);
99  }
100 
101  _type = type;
102 }
103 //-----------------------------------------------------------------------------
104 //! Sets the detector and decriptor to the passed ones
106  cv::Ptr<CVFeature2D> detector,
107  cv::Ptr<CVFeature2D> descriptor)
108 {
109  _type = type;
110  _detector = detector;
111  _descriptor = descriptor;
112 }
113 //-----------------------------------------------------------------------------
115  CVVKeyPoint& keypoints,
116  CVOutputArray descriptors,
117  CVInputArray mask)
118 {
119  assert(_detector && "CVFeatureManager::detectAndDescribe: No detector!");
120  assert(_descriptor && "CVFeatureManager::detectAndDescribe: No descriptor!");
121 
122  if (_detector == _descriptor)
123  _detector->detectAndCompute(image, mask, keypoints, descriptors);
124  else
125  {
126  _detector->detect(image, keypoints, mask);
127  _descriptor->compute(image, keypoints, descriptors);
128  }
129 }
130 //-----------------------------------------------------------------------------
CVDetectDescribeType
Feature detector-decriptor types.
@ DDT_ORB_ORB
@ DDT_SURF_SURF
@ DDT_FAST_BRIEF
@ DDT_SIFT_SIFT
@ DDT_RAUL_RAUL
Declares the Raul Mur ORB feature detector and descriptor.
cv::InputArray CVInputArray
Definition: CVTypedefs.h:63
cv::OutputArray CVOutputArray
Definition: CVTypedefs.h:64
vector< cv::KeyPoint > CVVKeyPoint
Definition: CVTypedefs.h:88
CVDetectDescribeType _type
Type of detector-descriptor pair.
CVDetectDescribeType type()
void setDetectorDescriptor(CVDetectDescribeType detectDescribeType, cv::Ptr< CVFeature2D > detector, cv::Ptr< CVFeature2D > descriptor)
Sets the detector and decriptor to the passed ones.
void createDetectorDescriptor(CVDetectDescribeType detectDescribeType)
Creates a detector and decriptor to the passed type.
cv::Ptr< CVFeature2D > _descriptor
CV smart pointer to the OpenCV descriptor extractor.
void detectAndDescribe(CVInputArray image, CVVKeyPoint &keypoints, CVOutputArray descriptors, CVInputArray mask=cv::noArray())
cv::Ptr< CVFeature2D > _detector
CV smart pointer to the OpenCV feature detector.
Orb detector and descriptor with distribution.
Definition: CVRaulMurOrb.h:21
void exitMsg(const char *tag, const char *msg, const int line, const char *file)
Terminates the application with a message. No leak checking.
Definition: Utils.cpp:1135