#!/usr/sww/bin/perl ######################################################################## ## ## NAME: center ## ## USAGE: center ## ## DESCRIPTION: This is a perl script to search through an ASCII PPM (portable ## pixel map) file describing the binary picture from an ## Eyesys videokeratograph and return the center. ## ## AUTHOR: Dan Garcia - University of California at Berkeley ## ddgarcia@cs.berkeley.edu ## ## DATE: 94-10-31 ## ## REVISION: 1.0 ## ########################################################################## unless ($#ARGV >= 0) { # are there any command line arguments? print "Usage: $0 PPM_FILE\n"; print " Read in a PPM (Portable Pixel Map) file describing\n"; print " the binary picture from an Eyesys videokeratograph\n"; print " and prints out the center\n"; exit 1; } $headerfile = $ARGV[0]; open(HEADER, $headerfile) || die "$0 couldn't open PPM file $headerfile: $!\n"; @ppmFile =
; @firstRow = split(/ */,$ppmFile[4]); ## Due to the regular expression above, the first element in the row ## is NOT firstRow[0] but firstRow[1], thus the index difference $xcent = (($firstRow[6] << 8) + $firstRow[5])/10.0; $ycent = (($firstRow[8] << 8) + $firstRow[7])/10.0; printf "%.1f %.1f\n", $xcent, $ycent; ## // c++ code from Eyesys people to recover center information ## ## // ---- input image ---- ## ## if (fh = open(infile, O_RDONLY)) == -1) { ## close(fh); ## return(FAILURE); ## } ## ## n = 48; ## nbytes = 512 * n; ## for (j = 0 ; j < 480 ; j+= n) { ## if ((bytesread = read(fh, big_buf[j], nbytes)) = -1) { ## close(fh); ## return(FAILURE); ## } ## } ## ## close (fh); ## ## // ---- get center information ---- ## ## c_x = (float) big_buf[0][4]; ## c_x = c_x + (float) (big_buf[0][5] << 8); ## c_x = c_x / 10; ## ## c_y = (float) big_buf[0][6]; ## c_y = c_y + (float) (big_buf[0][7] << 8); ## c_y = c_y / 10; ##