15 #include <mrpt/otherlibs/do_opencv_includes.h> 27 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM < 0x111 29 const CvArr* srcarr, CvArr* dstarr, CvPoint2D32f center,
double maxRadius,
36 CV_FUNCNAME(
"cvLinPolar");
40 CvMat srcstub, *
src = (CvMat *)srcarr;
41 CvMat dststub, *
dst = (CvMat *)dstarr;
44 CV_CALL(
src = cvGetMat(srcarr, &srcstub, 0, 0));
45 CV_CALL(
dst = cvGetMat(dstarr, &dststub, 0, 0));
47 if (!CV_ARE_TYPES_EQ(
src,
dst)) CV_ERROR(CV_StsUnmatchedFormats,
"");
49 ssize.width =
src->cols;
50 ssize.height =
src->rows;
51 dsize.width =
dst->cols;
52 dsize.height =
dst->rows;
54 CV_CALL(mapx = cvCreateMat(dsize.height, dsize.width, CV_32F));
55 CV_CALL(mapy = cvCreateMat(dsize.height, dsize.width, CV_32F));
57 if (!(flags & CV_WARP_INVERSE_MAP))
61 for (phi = 0; phi < dsize.height; phi++)
63 double cp = cos(phi * 2 *
CV_PI / (dsize.height - 1));
64 double sp = sin(phi * 2 *
CV_PI / (dsize.height - 1));
65 float* mx = (
float*)(mapx->data.ptr + phi * mapx->step);
66 float* my = (
float*)(mapy->data.ptr + phi * mapy->step);
68 for (rho = 0; rho < dsize.width; rho++)
70 double r = maxRadius * (rho + 1) /
double(dsize.width - 1);
71 double x =
r * cp + center.x;
72 double y =
r * sp + center.y;
82 CvMat bufx, bufy, bufp, bufa;
83 const double ascale = (ssize.height - 1) / (2 *
CV_PI);
84 const double pscale = (ssize.width - 1) / maxRadius;
86 CV_CALL(buf = (
float*)cvAlloc(4 * dsize.width *
sizeof(buf[0])));
88 bufx = cvMat(1, dsize.width, CV_32F, buf);
89 bufy = cvMat(1, dsize.width, CV_32F, buf + dsize.width);
90 bufp = cvMat(1, dsize.width, CV_32F, buf + dsize.width * 2);
91 bufa = cvMat(1, dsize.width, CV_32F, buf + dsize.width * 3);
93 for (
x = 0;
x < dsize.width;
x++) bufx.data.fl[
x] = (
float)
x - center.x;
95 for (
y = 0;
y < dsize.height;
y++)
97 float* mx = (
float*)(mapx->data.ptr +
y * mapx->step);
98 float* my = (
float*)(mapy->data.ptr +
y * mapy->step);
100 for (
x = 0;
x < dsize.width;
x++)
101 bufy.data.fl[
x] = (
float)
y - center.y;
103 cvCartToPolar(&bufx, &bufy, &bufp, &bufa, 0);
105 for (
x = 0;
x < dsize.width;
x++) bufp.data.fl[
x] += 1.f;
107 for (
x = 0;
x < dsize.width;
x++)
109 double rho = bufp.data.fl[
x] * pscale;
110 double phi = bufa.data.fl[
x] * ascale;
117 cvRemap(
src,
dst, mapx, mapy, flags, cvScalarAll(0));
133 ASSERT_(options.PolarImagesOptions.radius > 1);
134 ASSERT_(options.PolarImagesOptions.bins_angle > 1);
135 ASSERT_(options.PolarImagesOptions.bins_distance > 1);
137 const unsigned int radius = options.PolarImagesOptions.radius;
138 const unsigned int patch_w = options.PolarImagesOptions.bins_distance;
139 const unsigned int patch_h = options.PolarImagesOptions.bins_angle;
145 it != in_features.
end(); ++it)
148 (*it)->scale = radius;
151 #if MRPT_OPENCV_VERSION_NUM < 0x111 156 in_img.
getAs<IplImage>(),
157 linpolar_frame.getAs<IplImage>(),
158 cvPoint2D32f( (*it)->x,(*it)->y ),
160 CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
163 linpolar_frame.getAsMatrix((*it)->descriptors.PolarImg);
168 THROW_EXCEPTION(
"This method needs MRPT compiled with OpenCV support");
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's headers.
TInternalFeatList::iterator iterator
#define THROW_EXCEPTION(msg)
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
#define ASSERT_(f)
Defines an assertion mechanism.
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
A class for storing images as grayscale or RGB bitmaps.