Main MRPT website > C++ reference for MRPT 1.9.9
CFeatureExtraction_LATCH.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 /*---------------------------------------------------------------
11  CLASS: CFeatureExtraction
12  FILE: CFeatureExtraction_LATCH.cpp
13  AUTHOR: Raghavender Sahdev <raghavendersahdev@gmail.com>
14  ---------------------------------------------------------------*/
15 
16 #include "vision-precomp.h" // Precompiled headers
17 #include <mrpt/system/os.h>
18 #include <mrpt/vision/CFeatureExtraction.h> // important import
19 #include <mrpt/io/CMemoryStream.h>
20 // Universal include for all versions of OpenCV
21 #include <mrpt/otherlibs/do_opencv_includes.h>
22 
23 #ifdef HAVE_OPENCV_NONFREE // MRPT_HAS_OPENCV_NONFREE
24 #include <opencv2/nonfree/nonfree.hpp>
25 #endif
26 
27 #ifdef HAVE_OPENCV_XFEATURES2D
28 #include <opencv2/xfeatures2d.hpp>
29 #endif
30 #ifdef HAVE_OPENCV_LINE_DESCRIPTOR
31 #include <opencv2/line_descriptor.hpp>
32 using namespace cv::line_descriptor;
33 #endif
34 
35 using namespace mrpt::vision;
36 using namespace mrpt::img;
37 using namespace mrpt::math;
38 using namespace mrpt::img;
39 using namespace mrpt;
40 using namespace std;
41 
42 #if defined(HAVE_OPENCV_XFEATURES2D) && defined(HAVE_OPENCV_LINE_DESCRIPTOR)
43 #define HAVE_OPENCV_WITH_LATCH 1
44 #else
45 #define HAVE_OPENCV_WITH_LATCH 0
46 #endif
47 
48 /************************************************************************************************
49 * internal_computeLATCHDescriptors
50 ************************************************************************************************/
51 void CFeatureExtraction::internal_computeLATCHDescriptors(
52  const mrpt::img::CImage& in_img, CFeatureList& in_features) const
53 {
55 #if (!HAVE_OPENCV_WITH_LATCH)
57  "This function requires OpenCV modules: xfeatures2d,line_descriptor");
58 #else
59  using namespace cv;
60 
61  if (in_features.empty()) return;
62 
63  const size_t n_feats = in_features.size();
64  // Make sure we operate on a gray-scale version of the image:
65  const CImage inImg_gray(in_img, FAST_REF_OR_CONVERT_TO_GRAY);
66 
67  // convert from CFeatureList to vector<KeyPoint>
68  vector<KeyPoint> cv_feats(n_feats);
69  for (size_t k = 0; k < n_feats; ++k)
70  {
71  KeyPoint& kp = cv_feats[k];
72  kp.pt.x = in_features[k]->x;
73  kp.pt.y = in_features[k]->y;
74  kp.angle = in_features[k]->orientation;
75  kp.size = in_features[k]->scale;
76  } // end-for
77 
78  Mat cvImg(cv::cvarrToMat(inImg_gray.getAs<IplImage>()));
79  Mat cv_descs; // OpenCV descriptor output
80 
81  Ptr<xfeatures2d::LATCH> latch = xfeatures2d::LATCH::create(
82  options.LATCHOptions.bytes, options.LATCHOptions.rotationInvariance,
83  options.LATCHOptions.half_ssd_size);
84  latch->compute(cvImg, cv_feats, cv_descs);
85 
86  // -----------------------------------------------------------------
87  // MRPT Wrapping
88  // -----------------------------------------------------------------
90  int i;
91  for (i = 0, itList = in_features.begin(); itList != in_features.end();
92  itList++, i++)
93  {
94  CFeature::Ptr ft = *itList;
95 
96  // Get the LATCH descriptor
97  ft->descriptors.LATCH.resize(cv_descs.cols);
98  for (int m = 0; m < cv_descs.cols; ++m)
99  ft->descriptors.LATCH[m] =
100  cv_descs.at<int>(i, m); // Get the LATCH descriptor
101  } // end for-
102 
103 #endif
104  MRPT_END
105 } // end internal_computeLatchDescriptors
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV&#39;s headers.
Definition: img/CImage.h:599
#define MRPT_START
Definition: exceptions.h:262
TInternalFeatList::iterator iterator
Definition: CFeature.h:365
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
size_t size() const
Definition: CFeature.h:386
STL namespace.
This base provides a set of functions for maths stuff.
Classes for computer vision, detectors, features, etc.
Definition: CCamModel.h:20
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:304
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MRPT_END
Definition: exceptions.h:266
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019