Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Devices/svs.h

00001 /*#########################################
00002  * svs.h
00003  *
00004  * Header file for the SVM library
00005  *
00006  *#########################################
00007  */
00008 
00009 #ifndef _svs_h_
00010 #define _svs_h_
00011 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #include <stdio.h>
00047 
00048 #ifdef UNIX
00049 #include <sys/ipc.h>
00050 #include <sys/shm.h>
00051 #define ALIGN8 __attribute__ ((aligned (8)))
00052 #define ALIGN16 __attribute__ ((aligned (16)))
00053 #define FALSE 0
00054 #define TRUE 1
00055 #endif
00056 
00057 #ifdef WIN32
00058 #include <windows.h>
00059 #define ALIGN8
00060 #define REALLYIMPORT __declspec(dllimport)
00061 #ifndef LIBCODE
00062 #define IMPORT __declspec(dllimport)
00063 #else
00064 #define IMPORT __declspec(dllexport)
00065 #endif
00066 #else
00067 #define IMPORT
00068 #endif
00069 
00070 /* This structure stores the intrinsic parameters of a camera.  The 
00071  *   first half of this structure deals with parameters recovered
00072  *   from camera calibration.  The second half allows for the 
00073  *   parameters to be adjusted for subsampled images and subwindows.
00074  *   Camera calibration should be done for the largest image size 
00075  *   possible, and the image subwindow parameters used if smaller 
00076  *   images are to be used.
00077  */
00078 typedef struct {
00079   /* Intrinsic parameters */
00080   int       pwidth;      /* [pix]    Width of frame grabber's image */
00081   int       pheight;     /* [pix]    Height of frame grabber's image */
00082   double    dpx;    /* [mm/pix] X dimension of pixel in frame grabber */
00083   double    dpy;    /* [mm/pix] Y dimension of pixel in frame grabber */
00084   double    sx;          /* []       Scale factor to compensate for any error in dpx   */
00085   double    Cx;          /* [pix]    Z axis intercept of image plane */
00086   double    Cy;     /* [pix]    Z axis intercept of image plane */
00087   double    f;      /* [mm]     Focal length */
00088   double    kappa1;      /* [1/mm^2] First coefficient of radial distortion */
00089   double    kappa2;      /* [1/mm^4] Second coefficient of radial distortion */
00090   float     proj[3][4]; /* projection matrix of rectified image */
00091   float     rect[3][3]; /* rectification transform after correction for lens distortion */
00092 } svsIP;
00093 
00094 //
00095 // The svsSP structure stores all info about a stereo image pair and the stereo
00096 //   calculation.  Used as an argument to most functions.
00097 //
00098 
00099 typedef struct {
00100   int id;
00101 
00102   /* Stereo algorithm parameters */
00103   int convx, convy;      /* Edge convolution kernel size, pixels */
00104   int corrxsize, corrysize;   /* Correlation window size, pixels */
00105   int thresh;            /* Confidence threshold, 0-20 */
00106   int lr;           /* Left/right check, 1=on, 0=off */
00107   int ndisp;             /* Number of pixel disparities to search */
00108   int dpp;                      /* Disparities per pixel */
00109   int offx, offy;               /* Non-calibrated systems offset */
00110 
00111   /* framegrabber/image parameters absolute parameters */
00112   int max_linelen;       /* for NTSC fields, 640 */
00113   int max_lines;         /* for NTSC fields, 240 */
00114   int max_decimation;         /* 1, 2 or 4 */
00115   int max_binning;       /* 1 or 2 */
00116   double gamma;               /* gamma correction needed for display, 1.0 is none */
00117   int color;             /* 0 for monochrome, 1 for color imager */
00118 
00119   /* digitization parameters */
00120   int autogain;               /* 1 if available */
00121   int manualgain;        /* 1 if available */
00122   int autowhite;         /* 1 if available */
00123   int manualwhite;       /* 1 if available */
00124 
00125   int gain;              /* Image gain, from 0 to 100; -1 is auto */
00126   int exposure;               /* Image exposure from 0 to 100, -1 is auto */
00127   int contrast;               /* Image contrast, from 0 to 100, if auto mode */
00128   int brightness;        /* Image brightness, from 0 to 100, if auto mode */
00129   int saturation;        /* Image color saturation, from 0 to 100 */
00130   int red;               /* Image red gain, from 0 to 100, -1 is auto */
00131   int blue;              /* Image green gain, from 0 to 100, -1 is auto */
00132   int green;             /* Image blue gain, from 0 to 100, -1 is auto */
00133 
00134   /* Image subwindow */
00135   int ix;           /* Subimage start column */
00136   int iy;           /* Subimage start row */
00137   int width;             /* Subimage width, in pixels */
00138   int height;            /* Subimage height, in pixels */
00139   int vergence;               /* Subimage vergence between images */
00140 
00141   /* warping source subwindow parameters, only used in subwindow warping */
00142   int subwarp;           /* 1 if we're warping subimage, 0 if not */
00143   int left_ix, left_iy;       /* source start column and row */
00144   int left_width, left_height;     /* source width and height */
00145   int right_ix, right_iy;     /* source start column and row */
00146   int right_width, right_height; /* source width and height */
00147 
00148   /* Current full-frame image size */
00149   int decimation;        /* current decimation */
00150   int binning;           /* current binning */
00151   int subwindow;         /* 1 = subwindow capability, 0 = none */
00152   /* Parameters below here are important for redoing warping addresses */
00153   int linelen;           /* Image line length, in pixels */
00154   int lines;                    /* Number of image lines */
00155 
00156   /* Internal camera optical parameters */
00157   svsIP  left;           /* Left camera parameters */
00158   svsIP  right;               /* Right camera parameters */
00159 
00160   /* Transformation between left and right cameras */
00161   /* Coordinate system is attached to the center of projection of the
00162      left camera, with the X and Y axis aligned with the u and v axis,
00163      and Z along the line of sight */
00164   double Tx;             /* [mm] */
00165   double Ty;             /* [mm] */
00166   double Tz;             /* [mm] */
00167   double Rx;             /* [rad] Yaw */
00168   double Ry;             /* [rad] Pitch */
00169   double Rz;             /* [rad] Roll */
00170 
00171   unsigned long reserved;
00172 } svsSP;
00173 
00174 IMPORT extern svsSP svsParams;
00175 
00176 #define VIDEO_ERROR_FRAME_SIZE   -6
00177 #define VIDEO_ERROR_FRAME_SAMPLE -2
00178 #define VIDEO_ERROR_DEC_MODE     -3
00179 #define VIDEO_ERROR_BIN_MODE     -4
00180 #define VIDEO_ERROR_SUBWINDOW    -5
00181 
00182 
00183 //#define LINE_SIZE 160
00184 //#define FRAME_SIZE 120
00185 
00186 /*
00187  * Maximum sizes for caches
00188  */
00189 #define MAXX 1280        /* maximum number of columns in image */
00190 #define MAXY 1032        /* maximum number of rows in image */
00191 #define MAXD 16               /* stereo search range */
00192 #define MAXDS 128        /* abs max search range */
00193 #define MAXW 13               /* max window size */
00194 #define MAXRVAL 2048          /* maximum range value returned */
00195 #define SUBPIXELS 16          /* subpixel interpolation size */
00196 
00197 /* size of video, filter kernels */
00198 IMPORT extern int svsConvX, svsConvY, svsCorrX, svsCorrY, svsNumDisp;
00199 
00200 #define VID_ROWS 240
00201 #define VID_COLS 320
00202 #define XKERNEL 9
00203 #define YKERNEL 5
00204 #define XCORR  11
00205 #define YCORR  1
00206 #define NUM_DISP 16
00207 
00208 /* These macros give offsets and size of the disparity image, relative
00209  *   to the left intensity image.  Takes svsSP pointer as the argument. 
00210  *   Offsets are in terms of the left image.
00211  */
00212 #define RESWIDTH(p) ((p)->width - (p)->convx - (p)->corrxsize - 2*(p)->ndisp - \
00213                      abs((p)->offx) + 4)
00214 #define RESLEN(p)   ((p)->height - (p)->convy - (p)->corrysize - abs((p)->offy) + 2)
00215 #define RESLEFT(p)  (((p)->convx +(p)->corrxsize + (p)->ndisp + (p)->ndisp - 4) /2 \
00216                      + ((p)->offx < 0 ? -(p)->offx : 0))
00217 #define RESTOP(p)   (((p)->convy + (p)->corrysize - 2) / 2 + \
00218                ((p)->offy < 0 ? -(p)->offy : 0))
00219 
00220 /* These macros give offsets and size of the edge image, relative
00221  *   to the left intensity image.  Takes svsSP pointer as the argument. 
00222  */
00223 #define EDGEWIDTH(p) (((p)->linelen) - (p)->convx + 1)
00224 #define EDGELEN(p)   (((p)->height) - (p)->convy + 1)
00225 #define EDGELEFT(p)  ((p)->convx/2)
00226 #define EDGETOP(p)   ((p)->convy/2)
00227 
00228 /* video input */
00229 #define IN_STORAGE  4
00230 #define IN_LIVE          5
00231 
00232 /* display mode */
00233 #define DISP_NONE   0
00234 #define DISP_LEFT   1
00235 #define DISP_RIGHT  2
00236 #define DISP_BOTH   3
00237 #define DISP_MOSAIC 4
00238 #define DISP_HIST   5
00239 #define DISP_IMAGE  6
00240 #define DISP_X1     7
00241 #define DISP_X2     8
00242 
00243 /* acquisition mode */
00244 #define AQ_SINGLE  1
00245 #define AQ_CONTIN  2
00246 #define AQ_FREEZE  11
00247 #define AQ_CALIBRATE 10
00248 
00249 /* GM:acquisition type */
00250 #define AQT_SVM   3
00251 #define AQT_BUFFER 4
00252 #define AQT_FRAMEGRAB 5
00253 #define AQT_NONE 6
00254 
00255 /* storage modes */
00256 #define STO_ON  1
00257 #define STO_OFF 2
00258 #define STO_CLEAR 3
00259 
00260 /* capture formats */
00261 #define CAP_INTERLACE   0
00262 #define CAP_RGCOMPONENT 1
00263 #define CAP_DUAL        2
00264 #define CAP_TRIPLE      3
00265 #define CAP_CHANNELS    4
00266 
00267 #define BI_YVU9  0x39555659        // YVU9, planar
00268 #define BI_YV12  0x32315659        // YVU12 (4:1:1), planar
00269 #define BI_I420  0x30323449        // YUV12 (4:2:0), planar 
00270 #define BI_I422  0x32323449        // YUV12 (4:1:1), planar
00271 #define BI_MRG2  0x3247524d        // YUV16 (4:2:2) ??
00272 
00273 /*
00274  * SVS video capture main functions
00275  */
00276 
00277 IMPORT extern char *svsVideoIdent;  // identifier string for this capture interface
00278 
00279 IMPORT extern int svsDevice1; // first video capture device
00280 IMPORT extern int svsDevice2; // second video capture device
00281 
00282 IMPORT extern int svsDevice1;  /* first video capture device */
00283 IMPORT extern int svsDevice2;  /* second video capture device */
00284 IMPORT extern char *svsDevName;  /* name of first device */
00285 IMPORT extern char *svsDevName2; /* name of second device */
00286 IMPORT extern int  svsIsPXC_PC104; /* set to 1 for PXC PC104+ board under LINUX */
00287 
00288 IMPORT extern int svsMeteorMotion; /* set if capturing motion images */
00289 IMPORT extern int svsDualCaptureFormat; /* set if line interlace stereo */
00290 IMPORT extern int svsSwapInterlace; /* 1 to swap L/R interlaced images */
00291 IMPORT extern int svsVideoFormat;  /* fourcc code for video stream type */
00292 IMPORT extern int svsVideoBPP;     /* number of bits per pixel, only for RGB */
00293 /* opens capture for business: */
00294 IMPORT int  svsVideoOpen(svsSP *sp);/* returns -1 if error, 0 if ok */
00295 IMPORT void svsVideoClose(void); /* closes capture */
00296 /* waits for next continuous image from meteors: */
00297 IMPORT int  svsVideoWaitImage(int ms); 
00298 IMPORT int  svsVideoCheckImage(void); /* Returns 1 if an image is ready */
00299 IMPORT void svsVideoGetImage(unsigned char **buf, unsigned char **buf2, 
00300                     unsigned char **color);
00301 IMPORT void svsVideoGetRectImage(unsigned char **left, unsigned char **right, 
00302                      unsigned char **color, svsSP *sp);
00303 IMPORT int  svsVideoCheckParameters(svsSP *sp);   /* returns -1 on error, 0 if ok */
00304 IMPORT int  svsVideoStartContinuous(svsSP *sp);   /* ditto */
00305 IMPORT void svsVideoHaltContinuous(void);
00306 IMPORT int  svsVideoGrabSingle(svsSP *sp, int ms); /* returns -1 on error, 0 if ok ??? */
00307 
00308 // Calls to set parameters while streaming video
00309 IMPORT int svsVideoSetDigParams(svsSP *sp);/* -1  on error, 0 if ok */
00310 IMPORT int svsVideoSetOffsets(svsSP *sp); /* ditto */
00311 
00312 // Imager name (not implemented on analog stereo heads)
00313 IMPORT int svsVideoGetName(char *name);
00314 IMPORT int svsVideoSetName(char *name);
00315 
00316 // Debugging callbacks
00317 IMPORT extern void (*capDebug)(char *str);
00318 IMPORT extern void (*svsDebug)(char *str);
00319 IMPORT void svsDebugMessage(char *str, ...);
00320 
00321 
00322 /* 
00323  * Sometimes we need to say which image we want
00324  */
00325 
00326 #define svsLEFT  1
00327 #define svsRIGHT 2
00328 #define svsBOTH  3
00329 #define svsLEFTCOLOR 100
00330 #define svsLEFTBAYER 102
00331 #define svsRIGHTBAYER 103
00332 
00333 // added for CAP_TRIPLE
00334 //
00335 #define svsLEFT1  4
00336 #define svsLEFT2  5
00337 #define svsLEFT3  6
00338 #define svsRIGHT1 7
00339 #define svsRIGHT2 8
00340 #define svsRIGHT3 9
00341 
00342 /*
00343  * display output
00344  */
00345 #define svsNONE       0
00346 #define svsSTEREO     1
00347 #define svsCONFIDENCE 2
00348 #define svsEDGES      3
00349 #define svsMOTION     4
00350 #define svsCOLOR      5
00351 
00352 /*
00353  * Calculations
00354  */
00355 
00356 /* MMX definition */
00357 #ifdef IMPORT_HASMMX
00358 REALLYIMPORT
00359 #else
00360 IMPORT 
00361 #endif
00362 extern int svsHasMMX;    /* 1 for MMX, 0 for none, -1 for not checked. 
00363                        Can be set or read */
00364 IMPORT int svsCheckMMX(void); /* Checks for MMX and sets svsHasMMX */
00365 
00366 /* 
00367  * Puts stereo results in dest, using il and ir images.
00368  * Uses stereo params structure; if null, defaults to svsParams.
00369  */
00370 IMPORT void svsWarpImage(unsigned char *dest, unsigned char *src, int which, svsSP *sp);
00371 IMPORT void svsWarpImageBayer(unsigned char *dest, unsigned char *dest2, unsigned char *src, 
00372                      int which, svsSP *sp);
00373 IMPORT void svsWarpImageMono (unsigned char *dest, unsigned char *src, 
00374                      int which, svsSP *sp);
00375 IMPORT void svsCalcStereo(short *dest, unsigned char *il, 
00376                  unsigned char *ir, svsSP *sp);
00377 IMPORT void svsCalcEdges(signed char *ld, signed char *rd, unsigned char *il, 
00378                 unsigned char *ir, svsSP *sp);
00379 IMPORT void svsCalcConfidence(char *dest, unsigned char *il, svsSP *sp);
00380 IMPORT void svsCalcMotion(unsigned char *dest, unsigned char *il, 
00381                  unsigned char *ir, int xs, int ys, svsSP *sp);
00382 
00383 
00384 // 3D reconstruction functions
00385 //
00386 IMPORT void     svsReconstruct3D (float *X, float *Y, float *Z, float x, float y, float disp, svsSP *sp);
00387 IMPORT void svsReconstruct3DFast (float *X, float *Y, float *Z, float x, float y, float disp, svsSP *sp);
00388 
00389 #define LRVAL     0xfe        /* failed LR check */
00390 #define THRESHVAL 0xff        /* failed texture threshold */
00391 
00392 /*
00393  * Display functions
00394  */
00395 
00396 IMPORT extern int svsStereoOffsetX, svsStereoOffsetY; /* right image offsets */
00397 IMPORT extern float svsRangeImageValue(short *im, svsSP *sp);
00398 IMPORT extern void svsSleep(int ms); /* wait this long in milliseconds */
00399 IMPORT extern int svsSharedMemory; /* if we can use shared memory, really only Unix */
00400 
00401 #ifdef UNIX
00402 #endif
00403 
00404 #ifdef WIN32
00405 IMPORT extern HWND svsMainWin;          /* main window handle */
00406 #endif
00407 
00408 /*
00409  * image file I/O
00410  */
00411 
00412 #define HEADER_STRING "srisunim"
00413 
00414 #define HEADER_TYPE 0
00415 #define DATA_INT 0
00416 #define DATA_FLOAT 1
00417 #define HEADER_SIZE 256
00418 
00419 /* whole structure should take 256 bytes */
00420 struct  srisunim_header
00421 { 
00422     char srisunim[8];
00423     char header_type;
00424     char data_type;
00425     char bits_per_pixel;
00426     char n_dimensions;
00427     unsigned char x_dimension_h;
00428     unsigned char x_dimension_l;
00429     unsigned char y_dimension_h;
00430     unsigned char y_dimension_l;
00431     unsigned char z_dimension_h;
00432     unsigned char z_dimension_l;
00433     unsigned char n_images;   /* number of images */
00434     char padding[237];
00435   };
00436     
00437 /* Reads an .ssi file and put contents into buffer.  Creates
00438    buffer if null. */
00439 IMPORT unsigned char *svsReadFile(char *name, unsigned char *buffer, 
00440                   int *height, int *width, int *num);
00441 IMPORT int svsWriteImage(char *name, unsigned char *buf, int width, 
00442                 int height, char *type, int numframes);
00443 IMPORT int svsReadFileBMP(char *name, unsigned char *buffer, 
00444                   int *width, int *height, int interlace);
00445 IMPORT unsigned char *svsReadFile2BMP(char *name, unsigned char *buffer, 
00446                   int *width, int *height);
00447 IMPORT int svsWriteImageBMP(char *name, unsigned char *im, int width, int height, 
00448                     int isDisparity);
00449 IMPORT int svsWriteImageColorBMP(char *name, unsigned char *im, int width, int height, 
00450                      int isDisparity);
00451 IMPORT extern char *svsError;
00452 IMPORT int svsWriteParamFile(char *fname, svsSP *sp);  /* writes out stereo setting */
00453 IMPORT int svsReadParamFile(char *fname, svsSP *sp);   /* reads in stereo setting */
00454 
00455 
00456 
00457 /* version of the software */
00458 #define engine_version 21
00459 IMPORT extern int svsEngineVersion;
00460 
00461 IMPORT extern int svsPreFilterTime, svsPostFilterTime, svsCorrTime, svsMaxTime;
00462 
00463 //
00464 // new FLTK-based drawing fns
00465 //
00466 
00467 IMPORT void svsDrawImage(void *w, unsigned char *im, svsSP *p, int type);
00468 IMPORT void *svsGetWindow(int w, int h);
00469 IMPORT int  fltk_check(void); /* process fltk events */
00470 
00471 #ifdef __cplusplus
00472 }
00473 #endif
00474 
00475 #endif    /* ifdef _svs_h_ */

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000