/* David Marten */ /* CS455 */ /* program 1 night vision */ #include #include #include #include #include #include #define NO 0 #define YES 1 #define esc 27 struct sgttyb tab6; struct sgttyb *addr = &tab6; int result; int x,y; int values[1024]; int harray[1024]; int c; int fp; int result; char *name; short done = 0; main() { int cmd; int mode; char buffer[80]; int base, i, result, r; char req; int x1, y1, x2, y2; int dx, threshold; int length, xvals[1024], yvals[1024]; mode = 2; name = "/dev/tty"; system (buffer); fp = open(name, mode); if (fp != -1) do { initialize_vision_system(); fflush(stdin); menu(); set_raw_mode(); cmd = toupper(getchar()); fflush(stdin); set_normal_mode(); fflush(stdin); switch (cmd) { case 'C' : system("clear"); night_vision1(); break; case 'F' : system("clear"); night_vision2(); break; case 'E' : done = 1; break; } }while (done == 0); } menu() { int test; system("clear"); GotoXY(10,14); printf("F : night vision (freeze frame)."); GotoXY(14,14); printf("C : Run night vision simulator (continuous)."); GotoXY(18,14); printf("E : Exit."); GotoXY(22,14); printf("Please pick a function : "); } void Smooth_Function(y, smooth_factor) int *y, smooth_factor; { int i,j,t; int base = 455; /* must be same as CS455-histogram */ int original[256]; int temp[256]; int how_many = 5; /* default is 5 */ int sum = 0; int largest; float scale; how_many = smooth_factor; for (i=0;i<=255;i++) original[i] = y[i]; t = 0; for (i=0; i<=255;i++) /* was 246 RWW */ temp[i] = 0; for (i=how_many;i < (255 - how_many);i++) /* was 246 RWW */ { sum = 0; for (j=i-how_many;j <= i+how_many; j++) { sum += y[j]; } /* end for j */ temp[i] = sum / (how_many * 2 + 1); } /* end for i */ largest = 0; for (i=0;i <= 255;i++) if (original[i] > largest) largest = original[i]; scale = 1.0/((float)largest/((float)base-25.0)); for (i=0;i <= 254;i++) temp[i] = temp[i] * scale; for (i=0;i <= 254;i++) original[i] = original[i] * scale; for (i=0; i <= 255;i++) /* was 246 RWW */ { y[i] = temp[i]; } } /* end function */ night_vision1() { int done = 0,i; char ch; int harray[256]; ungetc(0,stdin); do { VIS$LINEARIZE_LUT(i,0); VIS$FREEZE(); HISTOGRAM(0,0,640,480,YES,harray,2); VIS$VIEW(); delay(); /* set_raw_mode(); scanf("%s",&ch); set_normal_mode(); if (ch==0) ungetc(done,stdin); else done = 1; */ }while (done == 0); } night_vision2() { int harray[256],i; int harray2[256]; HISTOGRAM2(0,0,640,480); getkey(); VIS$SET_MODE(1); VIS$FREEZE(); HISTOGRAM(0,0,640,480,YES,harray2,2); HISTOGRAM2(0,0,640,480); getkey(); } /************ Function sets keyboard input to unbuffered ****************/ set_raw_mode() { /* addr->sg_flags = 0300; /* MVAXII was 0310 in octal RWW fixed 8/9/90 */ result = ioctl(fp, TIOCGETP, addr); addr->sg_flags = O_RAW; /* RWW fixed 7/21/91for SUN */ addr->sg_ispeed = 13; /* 7 is 300 baud 13 is 9600 baud*/ addr->sg_ospeed = 13; /* 7 is 300 baud 13 is 9600 baud*/ result = ioctl(fp, TIOCSETP, addr); } /************ Function sets keyboard input back to buffered ************/ set_normal_mode() { /* addr->sg_flags = 0300; /* MVAXII was 0310 in octal RWW fixed 8/9/90 */ addr->sg_flags = O_ALLDELAY | ECHO | CRMOD; /* RWW fixed 7/21/91for SUN */ addr->sg_ispeed = 13; /* 7 is 300 baud 13 is 9600 baud*/ addr->sg_ospeed = 13; /* 7 is 300 baud 13 is 9600 baud*/ result = ioctl(fp, TIOCSETP, addr); } /************** Function to wait for key to be pressed ********/ getkey() { int cmd; printf("\n\nHit any key to continue"); set_raw_mode(); cmd = toupper(getchar()); fflush(stdin); set_normal_mode(); fflush(stdin); } /*********** Function moves the cursor to the screen coordinates X ( lines down from top), Y ( spaces in from right )***********/ GotoXY( x, y ) int x, y; { printf("\n"); printf( "%c%c%d%c%d%c", (char)esc, '[', x, ';', y, 'H' ); } initialize_vision_system() { VIS$OPEN(); VIS$INIT_FB(); VIS$INIT_LUTS(); VIS$VIEW(); setcamera(0); } /****************** functions from vks101.c ************************/ /*** histogram is the same as VIS$CS455HISTOGRAM but with out graphics */ HISTOGRAM(x1,y1,x2,y2,equalize,harray, color) int x1,y1,x2,y2, equalize, *harray, color; { int i,x; int offset,base,largest,grpfact,barwidth,area,X1,X2; int values[641]; float scale,eos; /* CONSTANTS */ grpfact=4; barwidth=8; base= 455 /* was 475 RWW */ ; area=(y2-y1)*(x2-x1); eos=256/grpfact-1; /* End Of Scale */ /* INITIALIZE ARRAYS */ for (i=0;i<=255;i++) { harray[i] = 0; } /* FILL HARRAY WITH READ_HORIZONTAL_LINE this is the histogram */ for (i=y1;i<=y2;i++) { rhline(x1,i,x2-x1,values); for (x=0;x largest) largest = darray[i]; scale = 1.0/((float)largest/((float)base-25.0)); /* DISPLAY HISTOGRAM FUNCTION OVER IMAGE */ X1=0; X2=barwidth; VIS$DRAW_BOX(0,25,barwidth*(256/grpfact+1),base,0,0); for (i=0;i<=eos;i++) { X1+=barwidth; X2+=barwidth; VIS$BLOCK(X1,(int)(base-(darray[i]*scale)), X2, base, 0); } } /* end function */ delay() { int i,j; for (i=0;i<10000000;i++) j = i + i + i; }