19#include <iCub/spherical_projection.h>
27 int output_lines,
int output_cols,
32 double *fa,
double *fe,
33 double *ca,
double *ce)
35 double max_azimuth = atan((input_cols-1-cx)/fx);
36 double min_azimuth = atan(-cx/fx);
37 double max_elevation = atan((input_lines-1-cy)/fy);
38 double min_elevation = atan(-cy/fy);
39 *fa = output_cols/(max_azimuth-min_azimuth);
40 *fe = output_lines/(max_elevation-min_elevation);
41 *ca = -min_azimuth*(*fa);
42 *ce = -min_elevation*(*fe);
49 int output_lines,
int output_cols,
54 float *mapx,
float *mapy)
56 if(input_lines <= 1)
return false;
57 if(input_cols <= 1)
return false;
58 if(output_lines <= 1)
return false;
59 if(output_cols <= 1)
return false;
60 if(fx <= 0)
return false;
61 if(fy <= 0)
return false;
62 if(mapx == 0)
return false;
63 if(mapy == 0)
return false;
72 int output_lines,
int output_cols,
77 float *mapx,
float *mapy)
79 double fa, fe, ca, ce, a,
e,
x,
y, r2, xd, yd;
82 fx, fy, cx, cy, k1, k2, p1, p2, mapx, mapy))
86 fx, fy, cx, cy, k1, k2, p1, p2,
89 for(i=0;i<output_lines;i++)
91 for(j=0;j<output_cols;j++)
98 xd =
x*(1+k1*r2+k2*r2*r2)+2*p1*
x*
y+p2*(r2+2*
x*
x);
99 yd =
y*(1+k1*r2+k2*r2*r2)+p1*(r2+2*
y*
y)+2*p2*
x*
y;
100 *mapx++ = (float)(fx*xd+cx);
101 *mapy++ = (float)(fy*yd+cy);
122 int output_lines,
int output_cols,
123 double fx,
double fy,
124 double cx,
double cy,
126 float *mapx,
float *mapy)
150 compute_egosp_map(input_lines, input_cols, output_lines, output_cols, fx, fy, cx, cy, Rt, mapx, mapy);
171 int output_lines,
int output_cols,
172 double fx,
double fy,
173 double cx,
double cy,
175 float *mapx,
float *mapy)
177 double flongitude, flatitude, clongitude, clatitude, longitude, latitude,
x,
y;
178 double Xworld,Yworld,Zworld,Xcamera,Ycamera,Zcamera;
180 clongitude = output_cols/2;
181 clatitude = output_lines/2;
182 flongitude = output_cols/2/3.141529;
183 flatitude = output_lines/3.141529;
185 for(i=0;i<output_lines;i++)
187 for(j=0;j<output_cols;j++)
189 latitude=-(i-clatitude)/flatitude;
190 longitude=-(j-clongitude)/flongitude;
192 Xworld = cos(longitude)*cos(latitude);
193 Yworld = sin(longitude)*cos(latitude);
194 Zworld = sin(latitude);
196 Xcamera= R[0]*Xworld+R[1]*Yworld+R[2]*Zworld;
197 Ycamera= R[3]*Xworld+R[4]*Yworld+R[5]*Zworld;
198 Zcamera= R[6]*Xworld+R[7]*Yworld+R[8]*Zworld;
204 *mapx++ = (float)(
x*fx+cx);
205 *mapy++ = (float)(
y*fy+cy);
bool compute_sp_map(int input_lines, int input_cols, int output_lines, int output_cols, double fx, double fy, double cx, double cy, double k1, double k2, double p1, double p2, float *mapx, float *mapy)
bool compute_icub_egosp_map(int input_lines, int input_cols, int output_lines, int output_cols, double fx, double fy, double cx, double cy, double *R, float *mapx, float *mapy)
void compute_sp_params(int input_lines, int input_cols, int output_lines, int output_cols, double fx, double fy, double cx, double cy, double k1, double k2, double p1, double p2, double *fa, double *fe, double *ca, double *ce)
bool compute_egosp_map(int input_lines, int input_cols, int output_lines, int output_cols, double fx, double fy, double cx, double cy, double *R, float *mapx, float *mapy)
bool check_sp_params(int input_lines, int input_cols, int output_lines, int output_cols, double fx, double fy, double cx, double cy, double k1, double k2, double p1, double p2, float *mapx, float *mapy)