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-2017, 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
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::utils;
37 using namespace mrpt::math;
38 using namespace mrpt;
39 using namespace std;
40 
41 #if defined(HAVE_OPENCV_XFEATURES2D) && defined(HAVE_OPENCV_LINE_DESCRIPTOR)
42 #define HAVE_OPENCV_WITH_LATCH 1
43 #else
44 #define HAVE_OPENCV_WITH_LATCH 0
45 #endif
46 
47 /************************************************************************************************
48 * internal_computeLATCHDescriptors
49 ************************************************************************************************/
50 void CFeatureExtraction::internal_computeLATCHDescriptors(
51  const mrpt::utils::CImage& in_img, CFeatureList& in_features) const
52 {
54 #if (!HAVE_OPENCV_WITH_LATCH)
56  "This function requires OpenCV modules: xfeatures2d,line_descriptor");
57 #else
58  using namespace cv;
59 
60  if (in_features.empty()) return;
61 
62  const size_t n_feats = in_features.size();
63  // Make sure we operate on a gray-scale version of the image:
64  const CImage inImg_gray(in_img, FAST_REF_OR_CONVERT_TO_GRAY);
65 
66  // convert from CFeatureList to vector<KeyPoint>
67  vector<KeyPoint> cv_feats(n_feats);
68  for (size_t k = 0; k < n_feats; ++k)
69  {
70  KeyPoint& kp = cv_feats[k];
71  kp.pt.x = in_features[k]->x;
72  kp.pt.y = in_features[k]->y;
73  kp.angle = in_features[k]->orientation;
74  kp.size = in_features[k]->scale;
75  } // end-for
76 
77  Mat cvImg(cv::cvarrToMat(inImg_gray.getAs<IplImage>()));
78  Mat cv_descs; // OpenCV descriptor output
79 
80  Ptr<xfeatures2d::LATCH> latch = xfeatures2d::LATCH::create(
81  options.LATCHOptions.bytes, options.LATCHOptions.rotationInvariance,
82  options.LATCHOptions.half_ssd_size);
83  latch->compute(cvImg, cv_feats, cv_descs);
84 
85  // -----------------------------------------------------------------
86  // MRPT Wrapping
87  // -----------------------------------------------------------------
89  int i;
90  for (i = 0, itList = in_features.begin(); itList != in_features.end();
91  itList++, i++)
92  {
93  CFeature::Ptr ft = *itList;
94 
95  // Get the LATCH descriptor
96  ft->descriptors.LATCH.resize(cv_descs.cols);
97  for (int m = 0; m < cv_descs.cols; ++m)
98  ft->descriptors.LATCH[m] =
99  cv_descs.at<int>(i, m); // Get the LATCH descriptor
100  } // end for-
101 
102 #endif
103  MRPT_END
104 } // end internal_computeLatchDescriptors
std::shared_ptr< CFeature > Ptr
Definition: CFeature.h:58
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
size_t size() const
Definition: CFeature.h:387
#define THROW_EXCEPTION(msg)
STL namespace.
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: CImage.h:587
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
#define MRPT_END
Classes for computer vision, detectors, features, etc.
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:305
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TInternalFeatList::iterator iterator
Definition: CFeature.h:366



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019