Re: Speeding up undistort

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Speeding up undistort

johnarg15
Dear Mr. Olivier,
I am using cvInitUndistortMap and cvRemap for distortion correction. However, I need more fast algorithm. I used Olivier's LUT method. It is working but it has errors in resulting image.
Did you implemented the interpolation portion ? I need your help or some sample code regarding required interpolation.

Thanking you.

--- In [hidden email], "rwctrllgc" <rwctrllgc@...> wrote:

>
> OK, I have implemented the code, done a few quick improvements
> regarding speed, and this is what I've got (1280*1024 B&W, PentiumM
> 1.6GHz) :
>
>  - undistort2 = 220ms
>  - cvInitUndistortMap and cvRemap = 170ms
>  - Olivier's LUT = 60ms (but errors in resulting image)
>  - Olivier's LUT optimized (no test needed, pointers optimization) =
> 35ms (but errors in resulting image)
>
> I have modified the LUT calculation to avoid obvious errors, it is
> good enough for me because speed is more important than precision,
> but not good if the undistorted image has to be as close as possible
> from source image (in that case interpolation is needed, but slows
> down the process)
>
> To add interpolation, we would need another table, and add a test to
> the optimized algo. My guess is that implementing interpolation
> would cost an other 10ms to 50ms, depending of the correction, that
> would mean up to 85ms.
>
> I'm going to keep what I have right now, because I don't need
> interpolation, I will certainly post Olivier's modified code in the
> next couple of days
>
> Regards,
>
> Regis
> --- In [hidden email], Olivier Demuynck <odemuynck@>
> wrote:
> >
> > I was treating ROI's of 2208*3000 sized images... don't remember
> how faster it was for the all image (maybe not faster)...
> >    
> >   Here is the sample code to generate the LUT:
> >    
> >   int Disto_correct_U1[2208*3000], Disto_correct_V1[2208*3000];  
> > float u0, v0, fx, fy, _fx, _fy, k1, k2, p1, p2;
> > int u, v, iu, iv;
> >    
> >   /* distortion coeficients */
> >   double a1[] = { 0.4, 0,
> >                   -0.0, -0.000 };
> >      
> >   /* camara intrinsec coeficients */
> >   double b1[] = {2377.02, 0, 904,
> >                   0, 2379.9, 1500,
> >                   0, 0, 1 };
> >  
> > u0 = b1[2];
> > v0 = b1[5];
> > fx = b1[0];
> > fy = b1[4];
> > _fx = 1.f/fx;
> > _fy = 1.f/fy;
> >    
> >   /* The coeficients where obtain with Matlab calibration tool,
> and in this case you have to take the oposite value...*/
> > k1 = -a1[0];
> > k2 = -a1[1];
> > p1 = -a1[2];
> >   p2 = -a1[3];
> >      
> >   for( v = 0; v < src_image1->height; v++ )
> >     {
> >         float y = (v - v0)*_fy;
> >         float y2 = y*y;
> >         float ky = 1 + (k1 + k2*y2)*y2;
> >         float k2y = 2*k2*y2;
> >         float _2p1y = 2*p1*y;
> >         float _3p1y2 = 3*p1*y2;
> >         float p2y2 = p2*y2;
> >           for( u = 0; u < src_image1->width; u++)
> >         {
> >             float x = (u - u0)*_fx;
> >             float x2 = x*x;
> >             float kx = (k1 + k2*x2)*x2;
> >             float d = kx + ky + k2y*x2;
> >             float _u = fx*(x*(d + _2p1y) + p2y2 + (3*p2)*x2) + u0;
> >             float _v = fy*(y*(d + (2*p2)*x) + _3p1y2 + p1*x2) + v0;
> >             int iu = cvRound(_u);
> >             int iv = cvRound(_v);
> >    
> >    Disto_correct_U1[v*src_image1->width+u]=iu;
> >    Disto_correct_V1[v*src_image1->width+u]=iv;  
> >   }
> >  }
> >    
> >   And here is the way to use the LUT for color images:
> >    
> >   for( v = 0; v < src_image1->height; v++ )
> >   {
> >   for( u = 0; u < src_image1->width; u++ )
> >   {    
> >    iu=Disto_correct_U1[v*(src_image1->width)+u];
> >    iv=Disto_correct_V1[v*(src_image1->width)+u];
> >    if(iu >= 0 && iv >= 0 && iu < src_image1->width && iv <
> src_image1->height)
> >    {
> >     *(dst_image1->imageData+((iv*dst_image1->widthStep)
> +iu*dst_image1->nChannels))=*(src_image1->imageData+((v*src_image1-
> >widthStep)+u*src_image1->nChannels));  
> >     *(dst_image1->imageData+((iv*dst_image1->widthStep)
> +iu*dst_image1->nChannels)+1)=*(src_image1->imageData+((v*src_image1-
> >widthStep)+u*src_image1->nChannels)+1);
> >     *(dst_image1->imageData+((iv*dst_image1->widthStep)
> +iu*dst_image1->nChannels)+2)=*(src_image1->imageData+((v*src_image1-
> >widthStep)+u*src_image1->nChannels)+2);
> >    }
> >   }
> >  }
> >
> >   Let me know if it speed up your treatment when you've got it
> implemented.
> >   Regards,
> >   Olivier.
> >
> >  
> > ---------------------------------
> > Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and
> 30+ countries) for 2ยข/min or less.
> >
> > [Non-text portions of this message have been removed]
> >
>