cv::remap does not seem to work

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cv::remap does not seem to work

Matthias Schmieder
Hi,
I just found out, that the new c++ cv::remap() function does not seem to
work properly. Can someone acknowledge this?
I filled out a bug ticket, https://code.ros.org/trac/opencv/ticket/67
Here is what i tested:



cv::Mat mapx_ = cv::Mat_<float>(fSize.height,fSize.width);
cv::Mat mapy_ = cv::Mat_<float>(fSize.height,fSize.width);
cv::Point2f center(80,60);

for (int row = 0; row <120; row++)
{
   for ( int col = 0; col < 160; col++)
   {
     cv::Point2f pn ( (col-center.x)* 0.025f,(row-center.y)* 0.025f );

     /* compute polar coordinates of pn */
     cv::Point2f pn_pol;
     /* length r */
     pn_pol.x = std::sqrt( std::pow(pn.x,2) + std::pow(pn.y,2) );
     /* agnle theta */
     pn_pol.y = std::atan2(pn.y,pn.x);
     /* apply radial distortion correction with pre-computed polynome */
     float nR =
0.0012*(std::pow(pn_pol.x,4))+(-0.0165*(std::pow(pn_pol.x,3)))+
0.0016*(std::pow(pn_pol.x,2))+0.9999*(pn_pol.x)-0.0001;

     /* back to cartesian coordinates */
     pn.x = nR * std::cos(pn_pol.y);
     pn.y = nR * std::sin(pn_pol.y);

     float xn = pn.x/elementSize_um_.width + center.x;
     float yn = pn.y/elementSize_um_.height + center.y;

     mapx_.at<float>(row,col) = xn;
     mapy_.at<float>(row,col) = yn;
   }
}

/* this does not result in a nice picture */
cv::Mat img = imread("some160x120image");
cv::Mat uimg;

cv::remap(img,uimg,mapx_,mapy_,cv::INTER_CUBIC);
cv::imshow("win",uimg);


/* converting everything to the old structures and using cvRemap() works
just fine */

/* workaround since cv::remap() does not seem to work */
IplImage* src = cvCreateImageHeader(cvSize(160,120),IPL_DEPTH_32F,1);
IplImage* dst = cvCreateImage(cvSize(160,120),IPL_DEPTH_32F,1);
IplImage* mapx = cvCreateImageHeader(cvSize(160,120),IPL_DEPTH_32F,1);
IplImage* mapy = cvCreateImageHeader(cvSize(160,120),IPL_DEPTH_32F,1);

src->imageData  = (char*)img.data;
mapx->imageData = (char*)mapx_.data;
mapy->imageData = (char*)mapy_.data;

cvRemap(src,dst,mapx,mapy,CV_INTER_CUBIC);
cv::Mat iplimg(dst);
cv::showimage("win2",iplimg);
cv::waitKey(0);



Reply | Threaded
Open this post in threaded view
|

Re: cv::remap does not seem to work

Matthias Schmieder
Jeees, found it out myself. I tried to do the remap inplace, which seems not to work properly...

--- In [hidden email], "Hype" <schmieder.matthias@...> wrote:

>
> Hi,
> I just found out, that the new c++ cv::remap() function does not seem to
> work properly. Can someone acknowledge this?
> I filled out a bug ticket, https://code.ros.org/trac/opencv/ticket/67
> Here is what i tested:
>
>
>
> cv::Mat mapx_ = cv::Mat_<float>(fSize.height,fSize.width);
> cv::Mat mapy_ = cv::Mat_<float>(fSize.height,fSize.width);
> cv::Point2f center(80,60);
>
> for (int row = 0; row <120; row++)
> {
>    for ( int col = 0; col < 160; col++)
>    {
>      cv::Point2f pn ( (col-center.x)* 0.025f,(row-center.y)* 0.025f );
>
>      /* compute polar coordinates of pn */
>      cv::Point2f pn_pol;
>      /* length r */
>      pn_pol.x = std::sqrt( std::pow(pn.x,2) + std::pow(pn.y,2) );
>      /* agnle theta */
>      pn_pol.y = std::atan2(pn.y,pn.x);
>      /* apply radial distortion correction with pre-computed polynome */
>      float nR =
> 0.0012*(std::pow(pn_pol.x,4))+(-0.0165*(std::pow(pn_pol.x,3)))+
> 0.0016*(std::pow(pn_pol.x,2))+0.9999*(pn_pol.x)-0.0001;
>
>      /* back to cartesian coordinates */
>      pn.x = nR * std::cos(pn_pol.y);
>      pn.y = nR * std::sin(pn_pol.y);
>
>      float xn = pn.x/elementSize_um_.width + center.x;
>      float yn = pn.y/elementSize_um_.height + center.y;
>
>      mapx_.at<float>(row,col) = xn;
>      mapy_.at<float>(row,col) = yn;
>    }
> }
>
> /* this does not result in a nice picture */
> cv::Mat img = imread("some160x120image");
> cv::Mat uimg;
>
> cv::remap(img,uimg,mapx_,mapy_,cv::INTER_CUBIC);
> cv::imshow("win",uimg);
>
>
> /* converting everything to the old structures and using cvRemap() works
> just fine */
>
> /* workaround since cv::remap() does not seem to work */
> IplImage* src = cvCreateImageHeader(cvSize(160,120),IPL_DEPTH_32F,1);
> IplImage* dst = cvCreateImage(cvSize(160,120),IPL_DEPTH_32F,1);
> IplImage* mapx = cvCreateImageHeader(cvSize(160,120),IPL_DEPTH_32F,1);
> IplImage* mapy = cvCreateImageHeader(cvSize(160,120),IPL_DEPTH_32F,1);
>
> src->imageData  = (char*)img.data;
> mapx->imageData = (char*)mapx_.data;
> mapy->imageData = (char*)mapy_.data;
>
> cvRemap(src,dst,mapx,mapy,CV_INTER_CUBIC);
> cv::Mat iplimg(dst);
> cv::showimage("win2",iplimg);
> cv::waitKey(0);
>