MRPT
2.0.3
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
{
52
MRPT_START
53
54
mrpt::system::CTimeLoggerEntry
tle(
55
profiler,
"internal_computeLATCHDescriptors"
);
56
57
#if (!HAVE_OPENCV_WITH_LATCH)
58
THROW_EXCEPTION
(
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
mrpt::vision::CFeatureList::size
size_t size() const
Definition:
CFeature.h:352
os.h
mrpt::img::FAST_REF_OR_CONVERT_TO_GRAY
@ FAST_REF_OR_CONVERT_TO_GRAY
Definition:
img/CImage.h:68
mrpt::vision
Copyright (C) 2010 Hauke Strasdat Imperial College London Copyright (c) 2005-2020,...
Definition:
bundle_adjustment.h:35
CMemoryStream.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition:
BaseAppDataSource.h:15
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition:
exceptions.h:67
vision-precomp.h
mrpt::vision::CFeatureList
A list of visual features, to be used as output by detectors, as input/output by trackers,...
Definition:
CFeature.h:275
mrpt::img::CImage::asCvMatRef
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Definition:
CImage.cpp:227
mrpt::img
Definition:
CCanvas.h:16
mrpt::vision::CFeatureList::empty
bool empty() const
Definition:
CFeature.h:351
MRPT_START
#define MRPT_START
Definition:
exceptions.h:241
CFeatureExtraction.h
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition:
img/CImage.h:148
mrpt::system::CTimeLoggerEntry
A safe way to call enter() and leave() of a mrpt::system::CTimeLogger upon construction and destructi...
Definition:
system/CTimeLogger.h:189
MRPT_END
#define MRPT_END
Definition:
exceptions.h:245
mrpt::math
This base provides a set of functions for maths stuff.
Definition:
math/include/mrpt/math/bits_math.h:11
cv
Definition:
img/CImage.h:23
Page generated by
Doxygen 1.8.17
for MRPT 2.0.3 at Fri May 29 13:06:46 UTC 2020