Main MRPT website > C++ reference for MRPT 1.9.9
CFeatureExtraction_polarImg.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 #include "vision-precomp.h" // Precompiled headers
11 
13 
14 // Universal include for all versions of OpenCV
15 #include <mrpt/otherlibs/do_opencv_includes.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::vision;
19 using namespace mrpt::system;
20 using namespace std;
21 
22 /****************************************************************************************
23  Linear-Polar Transform
24  J.L. Blanco, Apr 2009
25 ****************************************************************************************/
26 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM < 0x111
28  const CvArr* srcarr, CvArr* dstarr, CvPoint2D32f center, double maxRadius,
29  int flags)
30 {
31  CvMat* mapx = 0;
32  CvMat* mapy = 0;
33  float* buf = 0;
34 
35  CV_FUNCNAME("cvLinPolar");
36 
37  __BEGIN__;
38 
39  CvMat srcstub, *src = (CvMat *)srcarr;
40  CvMat dststub, *dst = (CvMat *)dstarr;
41  CvSize ssize, dsize;
42 
43  CV_CALL(src = cvGetMat(srcarr, &srcstub, 0, 0));
44  CV_CALL(dst = cvGetMat(dstarr, &dststub, 0, 0));
45 
46  if (!CV_ARE_TYPES_EQ(src, dst)) CV_ERROR(CV_StsUnmatchedFormats, "");
47 
48  ssize.width = src->cols;
49  ssize.height = src->rows;
50  dsize.width = dst->cols;
51  dsize.height = dst->rows;
52 
53  CV_CALL(mapx = cvCreateMat(dsize.height, dsize.width, CV_32F));
54  CV_CALL(mapy = cvCreateMat(dsize.height, dsize.width, CV_32F));
55 
56  if (!(flags & CV_WARP_INVERSE_MAP))
57  {
58  int phi, rho;
59 
60  for (phi = 0; phi < dsize.height; phi++)
61  {
62  double cp = cos(phi * 2 * CV_PI / (dsize.height - 1));
63  double sp = sin(phi * 2 * CV_PI / (dsize.height - 1));
64  float* mx = (float*)(mapx->data.ptr + phi * mapx->step);
65  float* my = (float*)(mapy->data.ptr + phi * mapy->step);
66 
67  for (rho = 0; rho < dsize.width; rho++)
68  {
69  double r = maxRadius * (rho + 1) / double(dsize.width - 1);
70  double x = r * cp + center.x;
71  double y = r * sp + center.y;
72 
73  mx[rho] = (float)x;
74  my[rho] = (float)y;
75  }
76  }
77  }
78  else
79  {
80  int x, y;
81  CvMat bufx, bufy, bufp, bufa;
82  const double ascale = (ssize.height - 1) / (2 * CV_PI);
83  const double pscale = (ssize.width - 1) / maxRadius;
84 
85  CV_CALL(buf = (float*)cvAlloc(4 * dsize.width * sizeof(buf[0])));
86 
87  bufx = cvMat(1, dsize.width, CV_32F, buf);
88  bufy = cvMat(1, dsize.width, CV_32F, buf + dsize.width);
89  bufp = cvMat(1, dsize.width, CV_32F, buf + dsize.width * 2);
90  bufa = cvMat(1, dsize.width, CV_32F, buf + dsize.width * 3);
91 
92  for (x = 0; x < dsize.width; x++) bufx.data.fl[x] = (float)x - center.x;
93 
94  for (y = 0; y < dsize.height; y++)
95  {
96  float* mx = (float*)(mapx->data.ptr + y * mapx->step);
97  float* my = (float*)(mapy->data.ptr + y * mapy->step);
98 
99  for (x = 0; x < dsize.width; x++)
100  bufy.data.fl[x] = (float)y - center.y;
101 
102  cvCartToPolar(&bufx, &bufy, &bufp, &bufa, 0);
103 
104  for (x = 0; x < dsize.width; x++) bufp.data.fl[x] += 1.f;
105 
106  for (x = 0; x < dsize.width; x++)
107  {
108  double rho = bufp.data.fl[x] * pscale;
109  double phi = bufa.data.fl[x] * ascale;
110  mx[x] = (float)rho;
111  my[x] = (float)phi;
112  }
113  }
114  }
115 
116  cvRemap(src, dst, mapx, mapy, flags, cvScalarAll(0));
117 
118  __END__;
119 
120  cvFree(&buf);
121  cvReleaseMat(&mapx);
122  cvReleaseMat(&mapy);
123 }
124 #endif
125 
126 /************************************************************************************************
127  computePolarImageDescriptors
128 ************************************************************************************************/
130  const mrpt::utils::CImage& in_img, CFeatureList& in_features) const
131 {
132  MRPT_START
133 #if MRPT_HAS_OPENCV
134 
135  ASSERT_(options.PolarImagesOptions.radius > 1)
136  ASSERT_(options.PolarImagesOptions.bins_angle > 1)
137  ASSERT_(options.PolarImagesOptions.bins_distance > 1)
138 
139  const unsigned int radius = options.PolarImagesOptions.radius;
140  const unsigned int patch_w = options.PolarImagesOptions.bins_distance;
141  const unsigned int patch_h = options.PolarImagesOptions.bins_angle;
142 
143  CImage linpolar_frame(patch_w, patch_h, in_img.getChannelCount());
144 
145  // Compute intensity-domain spin images
146  for (CFeatureList::iterator it = in_features.begin();
147  it != in_features.end(); ++it)
148  {
149  // Overwrite scale with the descriptor scale:
150  (*it)->scale = radius;
151 
152 // Use OpenCV to convert:
153 #if MRPT_OPENCV_VERSION_NUM < 0x111
154  my_cvLinearPolar( // Use version embedded above in this file
155 #else
156  cvLinearPolar( // Use version sent to OpenCV
157 #endif
158  in_img.getAs<IplImage>(),
159  linpolar_frame.getAs<IplImage>(),
160  cvPoint2D32f( (*it)->x,(*it)->y ),
161  radius,
162  CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
163 
164  // Get the image as a matrix and save as patch:
165  linpolar_frame.getAsMatrix((*it)->descriptors.PolarImg);
166 
167  } // end for it
168 
169 #else
170  THROW_EXCEPTION("This method needs MRPT compiled with OpenCV support")
171 #endif
172  MRPT_END
173 }
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
Definition: CImage.cpp:925
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:30
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
#define CV_PI
#define THROW_EXCEPTION(msg)
for(ctr=DCTSIZE;ctr > 0;ctr--)
Definition: jidctflt.cpp:56
STL namespace.
GLuint src
Definition: glext.h:7278
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
GLuint dst
Definition: glext.h:7135
#define MRPT_END
void my_cvLinearPolar(const CvArr *srcarr, CvArr *dstarr, CvPoint2D32f center, double maxRadius, int flags)
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.
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
#define ASSERT_(f)
TInternalFeatList::iterator iterator
Definition: CFeature.h:366
GLenum GLint GLint y
Definition: glext.h:3538
void internal_computePolarImageDescriptors(const mrpt::utils::CImage &in_img, CFeatureList &in_features) const
Compute a polar-image descriptor of the provided features into the input image.
GLenum GLint x
Definition: glext.h:3538



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