MRPT  2.0.1
CFeatureExtraction_logPolarImg.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 #include "vision-precomp.h" // Precompiled headers
11 
13 
14 // Universal include for all versions of OpenCV
15 #include <mrpt/3rdparty/do_opencv_includes.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::vision;
19 using namespace mrpt::img;
20 using namespace mrpt::system;
21 using namespace std;
22 
24  const mrpt::img::CImage& in_img, CFeatureList& in_features)
25 {
27 #if MRPT_HAS_OPENCV
28 
30  profiler, "internal_computeLogPolarImageDescriptors");
31 
32  ASSERT_(options.LogPolarImagesOptions.radius > 1);
33  ASSERT_(options.LogPolarImagesOptions.num_angles > 1);
34  ASSERT_(options.LogPolarImagesOptions.rho_scale > 0);
35 
36  const unsigned int radius = options.LogPolarImagesOptions.radius;
37  const unsigned int patch_h = options.LogPolarImagesOptions.num_angles;
38  const double rho_scale = options.LogPolarImagesOptions.rho_scale;
39  const unsigned int patch_w =
40  mrpt::round(rho_scale * std::log(static_cast<double>(radius)));
41 
42  mrpt::img::CImage logpolar_frame(
43  patch_w, patch_h, in_img.getChannelCount());
44 
45  // Compute intensity-domain spin images
46  for (auto& f : in_features)
47  {
48  // Overwrite scale with the descriptor scale:
49  f.keypoint.octave = radius;
50 
51  const auto pt = cv::Point2f(f.keypoint.pt.x, f.keypoint.pt.y);
52 
53  const cv::Mat& in = in_img.asCvMatRef();
54  cv::Mat& out = logpolar_frame.asCvMatRef();
55 
56 #if MRPT_OPENCV_VERSION_NUM < 0x300
57  IplImage cvin, cvout;
58  in_img.getAsIplImage(&cvin);
59  logpolar_frame.getAsIplImage(&cvout);
60 
61  cvLogPolar(
62  &cvin, &cvout, pt, radius, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS);
63 #elif MRPT_OPENCV_VERSION_NUM < 0x342
64  cv::logPolar(
65  in(cv::Rect(
66  round(pt.x - radius), round(pt.y - radius),
67  round(1 + 2 * radius), round(1 + 2 * radius))),
68  out, pt, radius, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS);
69 #else
70  // Latest opencv versions:
71  cv::warpPolar(
72  in, out, cv::Size(patch_w, patch_h), pt, radius,
73  cv::INTER_LINEAR + cv::WARP_FILL_OUTLIERS + cv::WARP_POLAR_LOG);
74 #endif
75 
76  // Get the image as a matrix and save as patch:
77  f.descriptors.LogPolarImg.emplace();
78  logpolar_frame.getAsMatrix(*f.descriptors.LogPolarImg);
79 
80  } // end for it
81 
82 #else
83  THROW_EXCEPTION("This method needs MRPT compiled with OpenCV support");
84 #endif
85  MRPT_END
86 }
#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...
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
Definition: CImage.cpp:227
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
Definition: CImage.cpp:878
STL namespace.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
Classes for computer vision, detectors, features, etc.
Definition: CDifodo.h:17
void getAsIplImage(IplImage *dest) const
(DEPRECATED, DO NOT USE - Kept here only to interface opencv 2.4)
Definition: CImage.cpp:2180
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.
void internal_computeLogPolarImageDescriptors(const mrpt::img::CImage &in_img, CFeatureList &in_features)
Compute a log-polar image descriptor of the provided features into the input image.
mrpt::vision::TStereoCalibResults out
struct _IplImage IplImage
Definition: img/CImage.h:22
#define MRPT_END
Definition: exceptions.h:245
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
int round(const T value)
Returns the closer integer (int) to x.
Definition: round.h:24



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020