MRPT  2.0.2
CFeatureExtraction_LATCH.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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 
18 #include <mrpt/io/CMemoryStream.h>
19 #include <mrpt/system/os.h>
20 #include <mrpt/vision/CFeatureExtraction.h> // important import
21 // Universal include for all versions of OpenCV
22 #include <mrpt/3rdparty/do_opencv_includes.h>
23 
24 #ifdef HAVE_OPENCV_NONFREE // MRPT_HAS_OPENCV_NONFREE
25 #include <opencv2/nonfree/nonfree.hpp>
26 #endif
27 
28 #ifdef HAVE_OPENCV_XFEATURES2D
29 #include <opencv2/xfeatures2d.hpp>
30 #endif
31 #ifdef HAVE_OPENCV_LINE_DESCRIPTOR
32 #include <opencv2/line_descriptor.hpp>
33 using namespace cv::line_descriptor;
34 #endif
35 
36 using namespace mrpt::vision;
37 using namespace mrpt::img;
38 using namespace mrpt::math;
39 using namespace mrpt::img;
40 using namespace mrpt;
41 using namespace std;
42 
43 #if defined(HAVE_OPENCV_XFEATURES2D) && defined(HAVE_OPENCV_LINE_DESCRIPTOR)
44 #define HAVE_OPENCV_WITH_LATCH 1
45 #else
46 #define HAVE_OPENCV_WITH_LATCH 0
47 #endif
48 
49 void CFeatureExtraction::internal_computeLATCHDescriptors(
50  const mrpt::img::CImage& in_img, CFeatureList& in_features)
51 {
53 
55  profiler, "internal_computeLATCHDescriptors");
56 
57 #if (!HAVE_OPENCV_WITH_LATCH)
59  "This function requires OpenCV modules: xfeatures2d,line_descriptor");
60 #else
61  using namespace cv;
62 
63  if (in_features.empty()) return;
64 
65  const size_t n_feats = in_features.size();
66  // Make sure we operate on a gray-scale version of the image:
67  const CImage inImg_gray(in_img, FAST_REF_OR_CONVERT_TO_GRAY);
68 
69  // convert from CFeatureList to vector<KeyPoint>
70  vector<KeyPoint> cv_feats(n_feats);
71  for (size_t k = 0; k < n_feats; ++k)
72  {
73  KeyPoint& kp = cv_feats[k];
74  kp.pt.x = in_features[k].keypoint.pt.x;
75  kp.pt.y = in_features[k].keypoint.pt.y;
76  kp.angle = in_features[k].orientation;
77  kp.size = in_features[k].keypoint.octave; // ?
78  } // end-for
79 
80  const Mat& cvImg = inImg_gray.asCvMatRef();
81  Mat cv_descs; // OpenCV descriptor output
82 
83  Ptr<xfeatures2d::LATCH> latch = xfeatures2d::LATCH::create(
84  options.LATCHOptions.bytes, options.LATCHOptions.rotationInvariance,
85  options.LATCHOptions.half_ssd_size);
86  latch->compute(cvImg, cv_feats, cv_descs);
87 
88  // -----------------------------------------------------------------
89  // MRPT Wrapping
90  // -----------------------------------------------------------------
91  int i = 0;
92  for (auto& ft : in_features)
93  {
94  // Get the LATCH descriptor
95  ft.descriptors.LATCH.emplace();
96  ft.descriptors.LATCH->resize(cv_descs.cols);
97  for (int m = 0; m < cv_descs.cols; ++m)
98  (*ft.descriptors.LATCH)[m] = cv_descs.at<int>(i, m);
99 
100  i++;
101  }
102 
103 #endif
104  MRPT_END
105 } // end internal_computeLatchDescriptors
#define MRPT_START
Definition: exceptions.h:241
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
A safe way to call enter() and leave() of a mrpt::system::CTimeLogger upon construction and destructi...
size_t size() const
Definition: CFeature.h:352
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Definition: CImage.cpp:227
STL namespace.
Definition: img/CImage.h:23
This base provides a set of functions for maths stuff.
Classes for computer vision, detectors, features, etc.
Definition: CDifodo.h:17
A list of visual features, to be used as output by detectors, as input/output by trackers, etc.
Definition: CFeature.h:275
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define MRPT_END
Definition: exceptions.h:245
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020