Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <structureColoring/segcomp/rangetocoords.h>
00009 #include <stdio.h>
00010 #include <math.h>
00011
00012 #define UNDEFINED_PT -1.0
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 void ConvertPerceptronRangeToCartesian(short int* RangeImage, double *P[3], int ROWS, int COLS)
00034 {
00035 double ra, r_0, r_1, r_2, r_3, h_1, h_2, dx, dy, dz;
00036 double alpha, beta, alpha_0, beta_0;
00037
00038 double gamma, theta;
00039 double H,V,delta;
00040 int r,c;
00041
00042 h_1=3.0;
00043
00044 h_2=5.5;
00045
00046 gamma=45.0*(M_PI/180.0);
00047 theta=45.0*(M_PI/180.0);
00048 alpha_0=beta_0=0.0;
00049 H=51.65;
00050 V=36.73;
00051 r_0=830.3;
00052 delta=0.20236;
00053
00054 for (r=0; r<ROWS; r++)
00055 {
00056 for (c=0; c<COLS; c++)
00057 {
00058 alpha = alpha_0 + H*(255.5 - c)/512.0;
00059 alpha = alpha*M_PI/180.0;
00060 beta = beta_0 + V*(255.5 - r)/512.0;
00061 beta = beta*M_PI/180.0;
00062
00063
00064
00065 dz = -(h_1*(1.0-cos(alpha))/tan(gamma));
00066
00067
00068
00069 dy = dz*tan(theta + 0.5*beta);
00070
00071
00072 dx = (h_2 + dy)*tan(alpha);
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 ra = (double) RangeImage[r*COLS+c];
00090
00091 r_1 = (dz - h_2)/delta;
00092 r_2 = sqrt(dx*dx + (h_2+dy)*(h_2+dy))/delta;
00093 r_3 = (ra + r_0 - (r_1 +r_2))*delta;
00094
00095 P[0][r*COLS+c] = dx + r_3 * sin(alpha);
00096 P[1][r*COLS+c] = dy + r_3 * cos(alpha)*sin(beta);
00097 P[2][r*COLS+c] = dz + r_3 * cos(alpha)*cos(beta);
00098 }
00099 }
00100 }
00101
00102
00103
00104
00105 void ConvertABWRangeToCartesian(const unsigned char* RangeImage, const int width, const int height, double* P[3], const int cal)
00106 {
00107 int r, c;
00108 double OFFSET;
00109 double SCAL;
00110 double F;
00111 double C;
00112
00113 if (cal == 1) {
00114 OFFSET = 785.410786;
00115 SCAL = 0.773545;
00116 F = -1610.981722;
00117 C = 1.4508;
00118 } else {
00119 OFFSET = 771.016866;
00120 SCAL = 0.791686;
00121 F = -1586.072821;
00122 C = 1.4508;
00123 }
00124
00125 for (r = 0; r < height; r++) {
00126 for (c = 0; c < width; c++) {
00127 size_t idx = r * width + c;
00128 if (RangeImage[idx] == 0) {
00129 P[0][idx] = P[1][idx] = P[2][idx]
00130 =UNDEFINED_PT;
00131 continue;
00132 }
00133 P[0][idx] = (double) (c - 255) * ((double) RangeImage[idx] / SCAL + OFFSET) / fabs(F);
00134 P[1][idx] = (double) (-r + 255) / C * ((double) RangeImage[idx] / SCAL + OFFSET)
00135 / fabs(F);
00136 P[2][idx] = (double) (255 - RangeImage[idx]) / SCAL;
00137 }
00138 }
00139 }
00140
00141
00142
00143
00144
00145
00146 void ConvertIMakeRangeToCartesian(unsigned char* RangeImage, double* P[3])
00147 {
00148 int r,c;
00149 double HORIZONTAL_FOV=60.0;
00150 double VERTICAL_FOV=60.0;
00151 int IMAGE_ROWS=512;
00152 int IMAGE_COLS=512;
00153 double RayX,RayY;
00154
00155 for (r=0; r<512; r++)
00156 {
00157 for (c=0; c<512; c++)
00158 {
00159 if (RangeImage[r*512+c] == 0)
00160 {
00161 P[0][r*512+c]=P[1][r*512+c]=P[2][r*512+c]=UNDEFINED_PT;
00162 continue;
00163 }
00164
00165
00166 RayX=((-HORIZONTAL_FOV/2.0)+((double)r+0.5)*
00167 (HORIZONTAL_FOV/(double)IMAGE_ROWS))*M_PI/180.0;
00168 RayY=((-VERTICAL_FOV/2.0)+((double)c+0.5)*
00169 (VERTICAL_FOV/(double)IMAGE_COLS))*M_PI/180.0;
00170 P[2][r*512+c]=(double)RangeImage[r*512+c]/sqrt(1.0+
00171 (tan(RayY)*tan(RayY))+(tan(RayX)*tan(RayX)));
00172 P[1][r*512+c]=P[2][r*512+c]*tan(RayY);
00173 P[0][r*512+c]=P[2][r*512+c]*tan(RayX);
00174 }
00175 }
00176 }