/*######################################### * svm.h * * Header file for the SVM library * *######################################### */ /** ** svm.h ** ** Copyright 1997 by Kurt Konolige ** ** The author hereby grants to SRI permission to use this software. ** The author also grants to SRI permission to distribute this software ** to educational institutes for non-commercial educational use only. ** ** The author hereby grants to other individuals or organizations ** permission to use this software for non-commercial ** educational use only. This software may not be distributed to others ** except by SRI, under the conditions above. ** ** Other than these cases, no part of this software may be used or ** distributed without written permission of the author. ** ** Neither the author nor SRI make any representations about the ** suitability of this software for any purpose. It is provided ** "as is" without express or implied warranty. ** ** Kurt Konolige ** Senior Computer Scientist ** SRI International ** 333 Ravenswood Avenue ** Menlo Park, CA 94025 ** E-mail: konolige@ai.sri.com ** **/ #ifdef __cplusplus extern "C" { #endif #include #ifdef UNIX #include "X11/Xlib.h" #include "X11/Xutil.h" #include "X11/Xos.h" #include "X11/Intrinsic.h" #include "X11/IntrinsicP.h" #include "X11/CoreP.h" #include "X11/Shell.h" #include "X11/keysym.h" #include #include #include #endif #ifdef WIN32 #include #ifndef LIBCODE #define IMPORT __declspec(dllimport) #else #define IMPORT __declspec(dllexport) #endif #else #define IMPORT #endif #define LINE_SIZE 160 #define FRAME_SIZE 120 /* * image frame definitions */ /* size of video */ #define VID_ROWS 240 #define VID_COLS 320 #define XKERNEL 9 #define YKERNEL 3 #define XCORR 11 #define YCORR 11 #define NUM_DISP 64 #define NUM_SEARCH 16 #define RESWIDTH(x) ((x) - XKERNEL - XCORR - NUM_SEARCH - NUM_SEARCH + 4) #define RESLEN(x) ((x) - YKERNEL - YCORR + 2) #define RESLEFT ((XKERNEL + XCORR + NUM_SEARCH + NUM_SEARCH -4) / 2) #define RESTOP ((YKERNEL + YCORR -2)/2) #define EDGEWIDTH(x) ((x) - XKERNEL + 1) #define EDGELEN(x) ((x) - YKERNEL + 1) #define EDGELEFT (XKERNEL/2) #define EDGETOP (YKERNEL/2) /* video input */ #define IN_STORAGE 4 #define IN_LIVE 5 /* display mode */ #define DISP_NONE 0 #define DISP_LEFT 1 #define DISP_RIGHT 2 #define DISP_BOTH 3 #define DISP_MOSAIC 4 #define DISP_HIST 5 #define DISP_IMAGE 6 #define DISP_X1 7 #define DISP_X2 8 /* acquisition mode */ #define AQ_SINGLE 1 #define AQ_CONTIN 2 /* GM:acquisition type */ #define AQT_LIVE 3 #define AQT_BUFFER 4 /* storage modes */ #define STO_ON 1 #define STO_OFF 2 #define STO_CLEAR 3 /* * SVM main functions */ IMPORT extern int svmPort; /* parallel port address */ IMPORT int svmOpen(int *params);/* opens the SVM for business */ IMPORT int svmClose(void); /* shuts the SVM down */ IMPORT int svmAlive(void); /* 0 if alive, -1 or -2 if no SVM */ IMPORT int svmWaitImage(int ms); /* waits for SVM frame; 1 if yes, 0 if no */ IMPORT int svmGetImage(int *params, char *buf, char *buf2); /* gets next image into buffers; returns 0 if ok, -1 if not */ IMPORT void svmGetParams(int *params); /* reads svm params */ IMPORT void svmHostReadOn(void); /* sets host read control bit */ IMPORT void svmHostReadOff(void); /* clears host read control bit */ IMPORT void svmGetFrame(char *buf, char *buf2);/* reads next frame into buffers */ /* * SVM commands * Return 0 on success, -1 on failure * Always check SVM status, wait for frame ready state */ IMPORT int svmSetMode(int mode); /* set output mode */ #define svmLEFT 1 #define svmRIGHT 2 #define svmBOTH 3 IMPORT int svmSaveParams(void); /* saves current settings to EEPROM */ IMPORT int svmRestoreParams(void); /* restores current settings from EEPROM */ IMPORT int svmSetThreshold(int val); /* sets confidence threshold value */ IMPORT int svmSetLR(int val); /* sets LR check on (1) or off (0) */ IMPORT int svmSetFunction(int func); /* sets SVM processing function */ IMPORT int svmSetLength(int length); IMPORT int svmSetWidth(int width); IMPORT int svmSetOffset(int offset); IMPORT int set_monitor(); /*XXX */ #define svmNONE 0 #define svmSTEREO 1 #define svmCONFIDENCE 2 #define svmEDGES 3 IMPORT int svmSetStereoOffset(int vdiff, int hdiff); /* sets stereo verical and horizontal offset */ /* * SVM parameter table entries */ #define svmTHRESH 0 /* confidence threshold */ #define svmFRAMENUM 1 /* frame number */ #define svmMODE 2 /* display mode */ #define svmWIDTH 3 /* frame width */ #define svmLENGTH 4 /* frame length */ #define svmFIRST 5 /* first line of video frame (offset from top) */ #define svmVDIFF 6 /* vertical offset between left and right */ #define svmHDIFF 7 /* horizontal offset between left and right */ #define svmFUNCTION 8 /* processing function */ #define svmCOMMAND 9 /* last SVM command */ #define svmLR 10 /* L/R check flag */ #define svmVERSION 11 /* version number (11 = 1.1) */ /* * Calculations */ /* * puts stereo results in dest, using il and ir images. * offsets must have already been calculated * xd and yd are width and height of image to be processed * linelen is length of image line * xs and ys are width and height of summation window * thresh is confidence threshold * lr is left/right check flag */ IMPORT void svmCalcStereo(unsigned char *dest, unsigned char *il, unsigned char *ir, int xd, int yd, int linelen, int xs, int ys, int thresh, int lr); IMPORT void svmCalcEdges(signed char *dest, unsigned char *src, int xd, int yd, int linelen); IMPORT void svmCalcConfidence(char *dest, unsigned char *il, int xd, int yd, int linelen, int xs, int ys, int thresh); #define LRVAL 0xfe /* failed LR check */ #define THRESHVAL 0xff /* failed texture threshold */ /* * Display functions */ IMPORT void svmConvertImage(unsigned char *buf, unsigned char *im, int ctype, int width, int length, int linelen, int outwidth, int bpp, int mag, int xoff, int yoff); /* transfers raw image to display buffer */ IMPORT extern int svmDepth; /* visual depth in bits */ #ifdef UNIX IMPORT void svmOpenDisplay(Display *dpy); /* gets a connection to the display */ IMPORT Colormap svmInitColormap(int depth); /* gets an appropriate colormap */ IMPORT extern Colormap svmColormap; IMPORT extern Display *svmDisplay; IMPORT extern int svmScreen; IMPORT extern int svmSharedMemory; /* if we can use shared memory */ IMPORT extern XShmSegmentInfo *svmShmInfo; /* for passing back shm info */ IMPORT XImage *svmGetImageBuffer(Window win, int width, int height); IMPORT void svmDisplayImage(XImage *xim, Window win, GC igc, int x, int y); #endif #ifdef WIN32 IMPORT void svmOpenDisplay(void); /* just sets svmDepth */ IMPORT HPALETTE svmInitColormap(int depth); /* always 8-bit depth, maybe later... */ IMPORT extern HPALETTE svmColormap; IMPORT extern HBITMAP svmBitmap; /* for passing back bitmap info */ IMPORT HDC svmGetImageBuffer(HDC windc, int width, int height, unsigned char **buf); /* returns image HDC, and raw buffer in *buf */ IMPORT void svmDisplayImage(HDC idc, HDC windc, int x, int y, int width, int height); #endif /* * image file I/O */ #define HEADER_STRING "srisunim" #define HEADER_TYPE 0 #define DATA_INT 0 #define DATA_FLOAT 1 #define HEADER_SIZE 256 /* whole structure should take 256 bytes */ struct srisunim_header { char srisunim[8]; char header_type; char data_type; char bits_per_pixel; char n_dimensions; unsigned char x_dimension_h; unsigned char x_dimension_l; unsigned char y_dimension_h; unsigned char y_dimension_l; unsigned char z_dimension_h; unsigned char z_dimension_l; unsigned char n_images; /* number of images */ char padding[237]; }; /* Reads an .ssi file and put contents into buffer. Creates buffer if null. */ IMPORT unsigned char *svmReadFile(char *name, unsigned char *buffer, int *height, int *width, int *num); IMPORT int svmWriteImage(FILE *, char *, int, int, char *, int); #ifdef UNIX /* * colormap definitions */ #define GRAY_SCALE_OFFSET 0x70 /* start grayscale here */ #define GRAY_SHIFT 1 /* shift pixels right this much */ #define NUM_GRAYS 128 /* how many grays we show */ #define DISPARITY_SCALE_OFFSET 0x30 #define DISPARITY_SHIFT 2 /* assumes max 64 levels */ #define NUM_DISPARITIES 64 #define NUM_OTHERS 6 #define BEGIN_OVERLAYS 0x20 #define MY_RED 0 #define MY_HALF_RED 1 #define MY_GREEN 2 #define MY_HALF_GREEN 3 #define MY_YELLOW 4 #define MY_HALF_YELLOW 5 extern long gray_ct[]; extern long disp_ct[]; extern long other_ct[]; #endif #ifdef __cplusplus } #endif