IM: im_capture.h Source File

IM - An Imaging Tool

im_capture.h

Go to the documentation of this file.
00001 /** \file
00002  * \brief Video Capture
00003  *
00004  * See Copyright Notice in im.h
00005  * $Id: im_capture.h,v 1.8 2006/11/20 13:18:51 scuri Exp $
00006  */
00007 
00008 #ifndef __IM_CAPTURE_H
00009 #define __IM_CAPTURE_H
00010 
00011 #if     defined(__cplusplus)
00012 extern "C" {
00013 #endif
00014 
00015 /* declarations to create an export library for Watcom. */
00016 #if ! defined (IM_DECL)   
00017   #if defined (__WATCOMC__)
00018     #define IM_DECL   __cdecl
00019   #elif defined(__WATCOM_CPLUSPLUS__)
00020     #define IM_DECL   __cdecl
00021   #else
00022     #define IM_DECL
00023   #endif
00024 #endif
00025 
00026 /** \defgroup capture Image Capture 
00027  * \par
00028  * Functions to capture images from live video devices.
00029  * \par
00030  * See \ref im_capture.h
00031  */
00032 
00033 typedef struct _imVideoCapture imVideoCapture;
00034 
00035 /** Returns the number of available devices.
00036  *
00037  * \verbatim im.VideoCaptureDeviceCount() -> count: number [in Lua 5] \endverbatim
00038  * \ingroup capture */
00039 int IM_DECL imVideoCaptureDeviceCount(void);
00040 
00041 /** Returns the device description. Returns NULL only if it is an invalid device.
00042  *
00043  * \verbatim im.VideoCaptureDeviceDesc(device: number) -> desc: string [in Lua 5] \endverbatim
00044  * \ingroup capture */
00045 const char* IM_DECL imVideoCaptureDeviceDesc(int device);
00046 
00047 /** Returns the extendend device description. May return NULL.
00048  *
00049  * \verbatim im.VideoCaptureDeviceExDesc(device: number) -> desc: string [in Lua 5] \endverbatim
00050  * \ingroup capture */
00051 const char* imVideoCaptureDeviceExDesc(int device);
00052 
00053 /** Returns the device path configuration. This is a unique string. 
00054  *
00055  * \verbatim im.VideoCaptureDevicePath(device: number) -> desc: string [in Lua 5] \endverbatim
00056  * \ingroup capture */
00057 const char* imVideoCaptureDevicePath(int device);
00058 
00059 /** Returns the vendor information. May return NULL.
00060  *
00061  * \verbatim im.VideoCaptureDeviceVendorInfo(device: number) -> desc: string [in Lua 5] \endverbatim
00062  * \ingroup capture */
00063 const char* imVideoCaptureDeviceVendorInfo(int device);
00064 
00065 /** Reload the device list. The devices can be dynamically removed or added to the system.
00066  * Returns the number of available devices.
00067  *
00068  * \verbatim im.imVideoCaptureReloadDevices() -> count: number [in Lua 5] \endverbatim
00069  * \ingroup capture */
00070 int IM_DECL imVideoCaptureReloadDevices(void);
00071 
00072 /** Creates a new imVideoCapture object. \n
00073  * Returns NULL if there is no capture device available. \n
00074  * In Windows returns NULL if DirectX version is older than 8.
00075  *
00076  * \verbatim im.VideoCaptureCreate() -> vc: imVideoCapture [in Lua 5] \endverbatim
00077  * \ingroup capture */
00078 imVideoCapture* IM_DECL imVideoCaptureCreate(void);
00079 
00080 /** Destroys a imVideoCapture object.
00081  *
00082  * \verbatim im.VideoCaptureDestroy(vc: imVideoCapture) [in Lua 5] \endverbatim
00083  * \verbatim vc:Destroy() [in Lua 5] \endverbatim
00084  * \ingroup capture */
00085 void IM_DECL imVideoCaptureDestroy(imVideoCapture* vc);
00086 
00087 /** Connects to a capture device. 
00088  * More than one imVideoCapture object can be created
00089  * but they must be connected to different devices.  \n
00090  * If the object is conected it will disconnect first. \n
00091  * Use -1 to return the current connected device, 
00092  * in this case returns -1 if not connected. \n
00093  * Returns zero if failed.
00094  *
00095  * \verbatim vc:Connect([device: number]) -> ret: number [in Lua 5] \endverbatim
00096  * \ingroup capture */
00097 int IM_DECL imVideoCaptureConnect(imVideoCapture* vc, int device);
00098 
00099 /** Disconnect from a capture device.
00100  *
00101  * \verbatim vc:Disconnect() [in Lua 5] \endverbatim
00102  * \ingroup capture */
00103 void IM_DECL imVideoCaptureDisconnect(imVideoCapture* vc);
00104 
00105 /** Returns the number of available configuration dialogs.
00106  *
00107  * \verbatim vc:DialogCount() -> count: number [in Lua 5] \endverbatim
00108  * \ingroup capture */
00109 int IM_DECL imVideoCaptureDialogCount(imVideoCapture* vc);
00110 
00111 /** Displays a configuration modal dialog of the connected device. \n
00112  * In Windows, the capturing will be stopped in some cases. \n
00113  * In Windows parent is a HWND of a parent window, it can be NULL. \n
00114  * dialog can be from 0 to \ref imVideoCaptureDialogCount. \n
00115  * Returns zero if failed.
00116  *
00117  * \verbatim vc:ShowDialog(dialog: number, parent: userdata) -> error: number [in Lua 5] \endverbatim
00118  * \ingroup capture */
00119 int IM_DECL imVideoCaptureShowDialog(imVideoCapture* vc, int dialog, void* parent);
00120 
00121 /** Allows to control the input and output of devices that have multiple input and outputs.
00122  * cross controls in which stage the input/output will be set. Usually use 1, but some capture boards
00123  * has a second stage. In Direct X it controls the crossbars.
00124  *
00125  * \verbatim vc:SetInOut(input, output, cross: number) -> error: number [in Lua 5] \endverbatim
00126  * \ingroup capture */
00127 int imVideoCaptureSetInOut(imVideoCapture* vc, int input, int output, int cross);
00128 
00129 /** Returns the description of a configuration dialog.
00130  * dialog can be from 0 to \ref imVideoCaptureDialogCount. \n
00131  *
00132  * \verbatim vc:DialogDesc(dialog: number) -> desc: string [in Lua 5] \endverbatim
00133  * \ingroup capture */
00134 const char* IM_DECL imVideoCaptureDialogDesc(imVideoCapture* vc, int dialog);
00135 
00136 /** Returns the number of available video formats. \n
00137  * Returns zero if failed.
00138  *
00139  * \verbatim vc:FormatCount() -> error: number [in Lua 5] \endverbatim
00140  * \ingroup capture */
00141 int IM_DECL imVideoCaptureFormatCount(imVideoCapture* vc);
00142 
00143 /** Returns information about the video format. \n
00144  * format can be from 0 to \ref imVideoCaptureFormatCount. \n
00145  * desc should be of size 10. \n
00146  * The image size is usually the maximum size for that format. 
00147  * Other sizes can be available using \ref imVideoCaptureSetImageSize. \n
00148  * Returns zero if failed.
00149  *
00150  * \verbatim vc:GetFormat(format: number) -> error: number, width: number, height: number, desc: string [in Lua 5] \endverbatim
00151  * \ingroup capture */
00152 int IM_DECL imVideoCaptureGetFormat(imVideoCapture* vc, int format, int *width, int *height, char* desc);
00153 
00154 /** Changes the video format of the connected device. \n 
00155  * Should NOT work for DV devices. Use \ref imVideoCaptureSetImageSize only. \n
00156  * Use -1 to return the current format, in this case returns -1 if failed. \n
00157  * When the format is changed in the dialog, for some formats 
00158  * the returned format is the preferred format, not the current format. \n
00159  * This will not affect color_mode of the capture image. \n
00160  * Returns zero if failed.
00161  *
00162  * \verbatim vc:SetFormat(format: number) -> error: number [in Lua 5] \endverbatim
00163  * \ingroup capture */
00164 int IM_DECL imVideoCaptureSetFormat(imVideoCapture* vc, int format);
00165 
00166 /** Returns the current image size of the connected device. \n
00167  *  width and height returns 0 if not connected.
00168  *
00169  * \verbatim vc:GetImageSize() -> width: number, height: number [in Lua 5] \endverbatim
00170  * \ingroup capture */
00171 void IM_DECL imVideoCaptureGetImageSize(imVideoCapture* vc, int *width, int *height);
00172 
00173 /** Changes the image size of the connected device. \n 
00174  * Similar to \ref imVideoCaptureSetFormat, but changes only the size. \n
00175  * Valid sizes can be obtained with  \ref imVideoCaptureGetFormat. \n
00176  * Returns zero if failed.
00177  *
00178  * \verbatim vc:SetImageSize(width: number, height: number) -> error: number [in Lua 5] \endverbatim
00179  * \ingroup capture */
00180 int IM_DECL imVideoCaptureSetImageSize(imVideoCapture* vc, int width, int height);
00181 
00182 /** Returns a new captured frame. Use -1 for infinite timeout. \n
00183  * Color space can be IM_RGB or IM_GRAY, and mode can be packed (IM_PACKED) or not. \n
00184  * It can not have an alpha channel and orientation is always bottom up. \n
00185  * Returns zero if failed or timeout expired, the buffer is not changed.
00186  *
00187  * \verbatim vc:Frame(image: imImage, timeout: number) -> error: number [in Lua 5] \endverbatim
00188  * \ingroup capture */
00189 int IM_DECL imVideoCaptureFrame(imVideoCapture* vc, unsigned char* data, int color_mode, int timeout);
00190 
00191 /** Start capturing, returns the new captured frame and stop capturing.  \n
00192  * This is more usefull if you are switching between devices. \n
00193  * Data format is the same as imVideoCaptureFrame. \n
00194  * Returns zero if failed.
00195  *
00196  * \verbatim vc:OneFrame(image: imImage) -> error: number [in Lua 5] \endverbatim
00197  * \ingroup capture */
00198 int IM_DECL imVideoCaptureOneFrame(imVideoCapture* vc, unsigned char* data, int color_mode);
00199 
00200 /** Start capturing. \n
00201  * Use -1 to return the current state. \n
00202  * Returns zero if failed.
00203  *
00204  * \verbatim vc:Live(live: number) -> error: number [in Lua 5] \endverbatim
00205  * \ingroup capture */
00206 int IM_DECL imVideoCaptureLive(imVideoCapture* vc, int live); 
00207 
00208 /** Resets a camera or video attribute to the default value or 
00209  * to the automatic setting. \n
00210  * Not all attributes support automatic modes. \n
00211  * Returns zero if failed.
00212  *
00213  * \verbatim vc:ResetAttribute(attrib: string, fauto: number) -> error: number [in Lua 5] \endverbatim
00214  * \ingroup capture */
00215 int IM_DECL imVideoCaptureResetAttribute(imVideoCapture* vc, const char* attrib, int fauto);
00216 
00217 /** Returns a camera or video attribute in percentage of the valid range value. \n
00218  * Returns zero if failed or attribute not supported.
00219  *
00220  * \verbatim vc:GetAttribute(attrib: string) -> error: number, percent: number [in Lua 5] \endverbatim
00221  * \ingroup capture */
00222 int IM_DECL imVideoCaptureGetAttribute(imVideoCapture* vc, const char* attrib, float *percent);
00223 
00224 /** Changes a camera or video attribute in percentage of the valid range value. \n
00225  * Returns zero if failed or attribute not supported.
00226  *
00227  * \verbatim vc:SetAttribute(attrib: string, percent: number) -> error: number [in Lua 5] \endverbatim
00228  * \ingroup capture */
00229 int IM_DECL imVideoCaptureSetAttribute(imVideoCapture* vc, const char* attrib, float percent);
00230 
00231 /** Returns a list of the description of the valid attributes for the device class. \n
00232  * But each device may still not support some of the returned attributes. \n
00233  * Use the return value of \ref imVideoCaptureGetAttribute to check if the attribute is supported.
00234  *
00235  * \verbatim vc:GetAttributeList() -> attrib_list: table of strings [in Lua 5] \endverbatim
00236  * \ingroup capture */
00237 const char** IM_DECL imVideoCaptureGetAttributeList(imVideoCapture* vc, int *num_attrib);
00238 
00239 
00240 /** \defgroup winattrib Windows Attributes Names
00241  * Not all attributes are supported by each device.
00242  * Use the return value of \ref imVideoCaptureGetAttribute to check if the attribute is supported.
00243 \verbatim
00244   VideoBrightness - Specifies the brightness, also called the black level. 
00245   VideoContrast - Specifies the contrast, expressed as gain factor. 
00246   VideoHue - Specifies the hue angle. 
00247   VideoSaturation - Specifies the saturation.
00248   VideoSharpness - Specifies the sharpness. 
00249   VideoGamma - Specifies the gamma. 
00250   VideoColorEnable - Specifies the color enable setting. (0/100)
00251   VideoWhiteBalance - Specifies the white balance, as a color temperature in degrees Kelvin. 
00252   VideoBacklightCompensation - Specifies the backlight compensation setting. (0/100)
00253   VideoGain - Specifies the gain adjustment.
00254   CameraPanAngle - Specifies the camera's pan angle. To 100 rotate right, To 0 rotate left (view from above).
00255   CameraTiltAngle - Specifies the camera's tilt angle.  To 100 rotate up, To 0 rotate down.
00256   CameraRollAngle - Specifies the camera's roll angle. To 100 rotate right, To 0 rotate left.
00257   CameraLensZoom - Specifies the camera's zoom setting. 
00258   CameraExposure - Specifies the exposure setting. 
00259   CameraIris - Specifies the camera's iris setting. 
00260   CameraFocus - Specifies the camera's focus setting, as the distance to the optimally focused target. 
00261   FlipHorizontal - Specifies the video will be flipped in the horizontal direction.
00262   FlipVertical - Specifies the video will be flipped in the vertical direction.
00263   AnalogFormat - Specifies the video format standard NTSC, PAL, etc. Valid values:
00264       NTSC_M     = 0 
00265       NTSC_M_J   = 1  
00266       NTSC_433   = 2
00267       PAL_B      = 3
00268       PAL_D      = 4
00269       PAL_H      = 5
00270       PAL_I      = 6
00271       PAL_M      = 7
00272       PAL_N      = 8
00273       PAL_60     = 9
00274       SECAM_B    = 10
00275       SECAM_D    = 11
00276       SECAM_G    = 12
00277       SECAM_H    = 13
00278       SECAM_K    = 14
00279       SECAM_K1   = 15
00280       SECAM_L    = 16
00281       SECAM_L1   = 17
00282       PAL_N_COMBO = 18
00283 \endverbatim
00284  * \ingroup capture */
00285 
00286 
00287 #if defined(__cplusplus)
00288 }
00289 
00290 /** A C++ Wrapper for the imVideoCapture structure functions.
00291  * \ingroup capture */
00292 class imCapture
00293 {
00294 public:
00295   imCapture() 
00296     { vc = imVideoCaptureCreate(); }
00297   
00298   ~imCapture() 
00299     { if (vc) imVideoCaptureDestroy(vc); }
00300   
00301   int Failed() 
00302     { if (!vc) return 0; else return 1; }
00303   
00304   int Connect(int device) 
00305     { return imVideoCaptureConnect(vc, device); }
00306   
00307   void Disconnect() 
00308     { imVideoCaptureDisconnect(vc); }
00309   
00310   int DialogCount() 
00311     { return imVideoCaptureDialogCount(vc); }
00312   
00313   int ShowDialog(int dialog, void* parent) 
00314     { return imVideoCaptureShowDialog(vc, dialog, parent); }
00315   
00316   const char* DialogDescription(int dialog) 
00317     { return imVideoCaptureDialogDesc(vc, dialog); }
00318 
00319   int FormatCount()
00320     { return imVideoCaptureFormatCount(vc); }
00321 
00322   int GetFormat(int format, int *width, int *height, char* desc)
00323     { return imVideoCaptureGetFormat(vc, format, width, height, desc); }
00324 
00325   int SetFormat(int format)
00326     { return imVideoCaptureSetFormat(vc, format); }
00327   
00328   void GetImageSize(int *width, int *height) 
00329     { imVideoCaptureGetImageSize(vc, width, height); }
00330   
00331   int SetImageSize(int width, int height) 
00332     { return imVideoCaptureSetImageSize(vc, width, height); }
00333   
00334   int GetFrame(unsigned char* data, int color_mode, int timeout) 
00335     { return imVideoCaptureFrame(vc, data, color_mode, timeout); }
00336   
00337   int GetOneFrame(unsigned char* data, int color_mode) 
00338     { return imVideoCaptureOneFrame(vc, data, color_mode); }
00339   
00340   int Live(int live) 
00341     { return imVideoCaptureLive(vc, live); }
00342   
00343   int ResetAttribute(const char* attrib, int fauto) 
00344     { return imVideoCaptureResetAttribute(vc, attrib, fauto); }
00345   
00346   int GetAttribute(const char* attrib, float *percent) 
00347     { return imVideoCaptureGetAttribute(vc, attrib, percent); }
00348   
00349   int SetAttribute(const char* attrib, float percent) 
00350     { return imVideoCaptureSetAttribute(vc, attrib, percent); }
00351   
00352   const char** GetAttributeList(int *num_attrib) 
00353     { return imVideoCaptureGetAttributeList(vc, num_attrib); }
00354   
00355 protected:
00356   imVideoCapture* vc;
00357 };
00358 
00359 #endif
00360 
00361 #endif