/********************************************************** ** This is C-code which will read in a raw Perceptron image, ** split it into range and reflectance images, and write ** them out in PGM format. WARNING: Note that the Perceptron ** data is 12-bit, so must be stored in the ASCII version ** of PGM. Many image readers (like xv) will load this data, ** but will often clip it to 8-bit. **********************************************************/ #include main(argc,argv) int argc; char *argv[]; { char text[300],header[6][800]; int *LoadingImage; short int *pgm; int i,j,value,r,c; FILE *fpt; if ((LoadingImage=(int *)calloc(4,512*512)) == NULL || (pgm=(short int *)calloc(2,512*512)) == NULL) { printf("Unable to acquire necessary memory\n"); exit(0); } if (argc != 2) { printf("Usage: perc-to-pgm [filename] \n"); exit(0); } if ((fpt=fopen(argv[1],"r")) == NULL) { printf("Unable to open %s\n",argv[1]); exit(0); } fscanf(fpt,"%s %s",header[0],header[1]); fscanf(fpt,"%s %s",header[0],header[1]); fscanf(fpt,"%s %s %s",header[0],header[1],header[2]); fscanf(fpt,"%s %s %s",header[0],header[1],header[2]); fscanf(fpt,"%s %s %s",header[0],header[1],header[2]); fscanf(fpt,"%s %s %s",header[0],header[1],header[2]); fscanf(fpt,"%s %s %s %s",header[0],header[1],header[2],header[3]); fscanf(fpt,"%s %s %s %s",header[0],header[1],header[2],header[3]); fscanf(fpt,"%s %s %s",header[0],header[1],header[2]); fscanf(fpt,"%s %s %s %s %s",header[0],header[1],header[2], header[3],header[4]); fscanf(fpt,"%c%c",&(header[0][0]),&(header[0][1])); /* extra new-line bytes */ if (fread(LoadingImage,4,512*512,fpt) != 512*512) { printf("Problem reading perceptron data\n"); exit(0); } fclose(fpt); for (i=0; i<2; i++) { for (j=0; j<512*512; j++) { if (i == 0) value=(LoadingImage[j] & 0x00000fff) ; /* range data for pixel */ else value=(LoadingImage[j] & 0x0fff0000) >> 16; /* reflectance */ pgm[j]=(short int)(value); } if (i == 0) sprintf(text,"%s.range.pgm",argv[1]); else sprintf(text,"%s.refl.pgm",argv[1]); if ((fpt=fopen(text,"w")) == NULL) { printf("Unable to open %s for writing\n",text); exit(0); } fprintf(fpt,"P2 512 512 4095\n"); for (r=0; r<512; r++) { for (c=0; c<511; c++) fprintf(fpt,"%d ",(int)pgm[r*512+c]); fprintf(fpt,"%d\n",(int)pgm[r*512+511]); } fclose(fpt); } free(LoadingImage); free(pgm); } /* ** Convert Perceptron image to 3D cartesian coordinates. ** ** ** beta > 0 ** ** ^ y ** alpha > 0 | alpha < 0 ** Seen from camera: x <----|---- (z-axis points ** out of camera) ** ** beta < 0 */ #include #include ConvertPerceptronRangeToCartesian(RangeImage,P,ROWS,COLS) short int *RangeImage; double *P[3]; int ROWS,COLS; { double ra, r_0, r_1, r_2, r_3, h_1, h_2, dx, dy, dz; double alpha, beta, alpha_0, beta_0; /* alpha = Horizontal, beta = Vertical angle */ double gamma, theta; double H,V,delta; int r,c; h_1=3.0; /* dist (y) between rotating mirror axis ** and the parallel laser beam. */ h_2=5.5; /* dist (y) between nodding mirror axis ** and rotating mirror laser intersection. */ gamma=45.0*(M_PI/180.0); /* slope of rotating mirror */ theta=45.0*(M_PI/180.0); /* slope of nodding mirror in mid position */ alpha_0=beta_0=0.0; H=51.65; V=36.73; r_0=830.3; delta=0.20236; for (r=0; r