Cinder

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/OpenCV/highgui.h

Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                        Intel License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000, Intel Corporation, all rights reserved.
00014 // Third party copyrights are property of their respective owners.
00015 //
00016 // Redistribution and use in source and binary forms, with or without modification,
00017 // are permitted provided that the following conditions are met:
00018 //
00019 //   * Redistribution's of source code must retain the above copyright notice,
00020 //     this list of conditions and the following disclaimer.
00021 //
00022 //   * Redistribution's in binary form must reproduce the above copyright notice,
00023 //     this list of conditions and the following disclaimer in the documentation
00024 //     and/or other materials provided with the distribution.
00025 //
00026 //   * The name of Intel Corporation may not be used to endorse or promote products
00027 //     derived from this software without specific prior written permission.
00028 //
00029 // This software is provided by the copyright holders and contributors "as is" and
00030 // any express or implied warranties, including, but not limited to, the implied
00031 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00032 // In no event shall the Intel Corporation or contributors be liable for any direct,
00033 // indirect, incidental, special, exemplary, or consequential damages
00034 // (including, but not limited to, procurement of substitute goods or services;
00035 // loss of use, data, or profits; or business interruption) however caused
00036 // and on any theory of liability, whether in contract, strict liability,
00037 // or tort (including negligence or otherwise) arising in any way out of
00038 // the use of this software, even if advised of the possibility of such damage.
00039 //
00040 //M*/
00041 
00042 #ifndef __OPENCV_HIGHGUI_H__
00043 #define __OPENCV_HIGHGUI_H__
00044 
00045 #ifndef SKIP_INCLUDES
00046 
00047   #include "cxcore.h"
00048   #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
00049     #include <windows.h>
00050     #undef min
00051     #undef max
00052   #endif
00053 
00054 #else // SKIP_INCLUDES
00055 
00056   #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
00057     #define CV_CDECL __cdecl
00058     #define CV_STDCALL __stdcall
00059   #else
00060     #define CV_CDECL
00061     #define CV_STDCALL
00062   #endif
00063 
00064   #ifndef CV_EXTERN_C
00065     #ifdef __cplusplus
00066       #define CV_EXTERN_C extern "C"
00067       #define CV_DEFAULT(val) = val
00068     #else
00069       #define CV_EXTERN_C
00070       #define CV_DEFAULT(val)
00071     #endif
00072   #endif
00073 
00074   #ifndef CV_EXTERN_C_FUNCPTR
00075     #ifdef __cplusplus
00076       #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
00077     #else
00078       #define CV_EXTERN_C_FUNCPTR(x) typedef x
00079     #endif
00080   #endif
00081 
00082   #ifndef CV_INLINE
00083     #if defined __cplusplus
00084       #define CV_INLINE inline
00085     #elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __GNUC__
00086       #define CV_INLINE __inline
00087     #else
00088       #define CV_INLINE static
00089     #endif
00090   #endif /* CV_INLINE */
00091 
00092   #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && defined CVAPI_EXPORTS
00093     #define CV_EXPORTS __declspec(dllexport)
00094   #else
00095     #define CV_EXPORTS
00096   #endif
00097 
00098   #ifndef CVAPI
00099     #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
00100   #endif
00101 
00102 #endif // SKIP_INCLUDES
00103 
00104 #if defined(_CH_)
00105   #pragma package <chopencv>
00106   #include <chdl.h>
00107   LOAD_CHDL(highgui)
00108 #endif
00109 
00110 #ifdef __cplusplus
00111   extern "C" {
00112 #endif /* __cplusplus */
00113 
00114 /****************************************************************************************\
00115 *                                  Basic GUI functions                                   *
00116 \****************************************************************************************/
00117 
00118 /* this function is used to set some external parameters in case of X Window */
00119 CVAPI(int) cvInitSystem( int argc, char** argv );
00120 
00121 CVAPI(int) cvStartWindowThread();
00122 
00123 #define CV_WINDOW_AUTOSIZE  1
00124 /* create window */
00125 CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
00126 
00127 // ---------  YV ---------
00128 #define CV_WND_PROP_FULLSCREEN   0
00129 #define CV_WND_PROP_AUTOSIZE     1
00130 #define CV_WINDOW_NORMAL         0
00131 #define CV_WINDOW_FULLSCREEN     1
00132 /* Set and Get Property of the window */
00133 CVAPI(void) cvSetWindowProperty(const char* name, int prop_id, double prop_value);
00134 CVAPI(double) cvGetWindowProperty(const char* name, int prop_id);
00135 
00136 /* display image within window (highgui windows remember their content) */
00137 CVAPI(void) cvShowImage( const char* name, const CvArr* image );
00138 
00139 /* resize/move window */
00140 CVAPI(void) cvResizeWindow( const char* name, int width, int height );
00141 CVAPI(void) cvMoveWindow( const char* name, int x, int y );
00142 
00143 
00144 /* destroy window and all the trackers associated with it */
00145 CVAPI(void) cvDestroyWindow( const char* name );
00146 
00147 CVAPI(void) cvDestroyAllWindows(void);
00148 
00149 /* get native window handle (HWND in case of Win32 and Widget in case of X Window) */
00150 CVAPI(void*) cvGetWindowHandle( const char* name );
00151 
00152 /* get name of highgui window given its native handle */
00153 CVAPI(const char*) cvGetWindowName( void* window_handle );
00154 
00155 
00156 typedef void (CV_CDECL *CvTrackbarCallback)(int pos);
00157 
00158 /* create trackbar and display it on top of given window, set callback */
00159 CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name,
00160                              int* value, int count, CvTrackbarCallback on_change);
00161 
00162 typedef void (CV_CDECL *CvTrackbarCallback2)(int pos, void* userdata);
00163 
00164 CVAPI(int) cvCreateTrackbar2( const char* trackbar_name, const char* window_name,
00165                               int* value, int count, CvTrackbarCallback2 on_change,
00166                               void* userdata CV_DEFAULT(0));
00167 
00168 /* retrieve or set trackbar position */
00169 CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
00170 CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
00171 
00172 #define CV_EVENT_MOUSEMOVE      0
00173 #define CV_EVENT_LBUTTONDOWN    1
00174 #define CV_EVENT_RBUTTONDOWN    2
00175 #define CV_EVENT_MBUTTONDOWN    3
00176 #define CV_EVENT_LBUTTONUP      4
00177 #define CV_EVENT_RBUTTONUP      5
00178 #define CV_EVENT_MBUTTONUP      6
00179 #define CV_EVENT_LBUTTONDBLCLK  7
00180 #define CV_EVENT_RBUTTONDBLCLK  8
00181 #define CV_EVENT_MBUTTONDBLCLK  9
00182 
00183 #define CV_EVENT_FLAG_LBUTTON   1
00184 #define CV_EVENT_FLAG_RBUTTON   2
00185 #define CV_EVENT_FLAG_MBUTTON   4
00186 #define CV_EVENT_FLAG_CTRLKEY   8
00187 #define CV_EVENT_FLAG_SHIFTKEY  16
00188 #define CV_EVENT_FLAG_ALTKEY    32
00189 
00190 typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
00191 
00192 /* assign callback for mouse events */
00193 CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
00194                                 void* param CV_DEFAULT(NULL));
00195 
00196 /* 8bit, color or not */
00197 #define CV_LOAD_IMAGE_UNCHANGED  -1
00198 /* 8bit, gray */
00199 #define CV_LOAD_IMAGE_GRAYSCALE   0
00200 /* ?, color */
00201 #define CV_LOAD_IMAGE_COLOR       1
00202 /* any depth, ? */
00203 #define CV_LOAD_IMAGE_ANYDEPTH    2
00204 /* ?, any color */
00205 #define CV_LOAD_IMAGE_ANYCOLOR    4
00206 
00207 /* load image from file
00208   iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
00209   overrides the other flags
00210   using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
00211   unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
00212 */
00213 CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
00214 CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
00215 
00216 #define CV_IMWRITE_JPEG_QUALITY 1
00217 #define CV_IMWRITE_PNG_COMPRESSION 16
00218 #define CV_IMWRITE_PXM_BINARY 32
00219 
00220 /* save image to file */
00221 CVAPI(int) cvSaveImage( const char* filename, const CvArr* image,
00222                         const int* params CV_DEFAULT(0) );
00223 
00224 /* decode image stored in the buffer */
00225 CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
00226 CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
00227 
00228 /* encode image and store the result as a byte vector (single-row 8uC1 matrix) */
00229 CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image,
00230                              const int* params CV_DEFAULT(0) );
00231 
00232 #define CV_CVTIMG_FLIP      1
00233 #define CV_CVTIMG_SWAP_RB   2
00234 /* utility function: convert one image to another with optional vertical flip */
00235 CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
00236 
00237 /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
00238 CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
00239 
00240 
00241 /****************************************************************************************\
00242 *                         Working with Video Files and Cameras                           *
00243 \****************************************************************************************/
00244 
00245 /* "black box" capture structure */
00246 typedef struct CvCapture CvCapture;
00247 
00248 /* start capturing frames from video file */
00249 CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
00250 
00251 #define CV_CAP_ANY      0     // autodetect
00252 
00253 #define CV_CAP_MIL      100   // MIL proprietary drivers
00254 
00255 #define CV_CAP_VFW      200   // platform native
00256 #define CV_CAP_V4L      200
00257 #define CV_CAP_V4L2     200
00258 
00259 #define CV_CAP_FIREWARE 300   // IEEE 1394 drivers
00260 #define CV_CAP_FIREWIRE 300
00261 #define CV_CAP_IEEE1394 300
00262 #define CV_CAP_DC1394   300
00263 #define CV_CAP_CMU1394  300
00264 
00265 #define CV_CAP_STEREO   400   // TYZX proprietary drivers
00266 #define CV_CAP_TYZX     400
00267 #define CV_TYZX_LEFT    400
00268 #define CV_TYZX_RIGHT   401
00269 #define CV_TYZX_COLOR   402
00270 #define CV_TYZX_Z       403
00271 
00272 #define CV_CAP_QT       500   // QuickTime
00273 
00274 #define CV_CAP_UNICAP   600   // Unicap drivers
00275 
00276 #define CV_CAP_DSHOW    700   // DirectShow (via videoInput)
00277 
00278 #define CV_CAP_PVAPI    800   // PvAPI, Prosilica GigE SDK
00279 
00280 /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
00281 CVAPI(CvCapture*) cvCreateCameraCapture( int index );
00282 
00283 /* grab a frame, return 1 on success, 0 on fail.
00284   this function is thought to be fast               */
00285 CVAPI(int) cvGrabFrame( CvCapture* capture );
00286 
00287 /* get the frame grabbed with cvGrabFrame(..)
00288   This function may apply some frame processing like
00289   frame decompression, flipping etc.
00290   !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
00291 CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture, int streamIdx CV_DEFAULT(0) );
00292 
00293 /* Just a combination of cvGrabFrame and cvRetrieveFrame
00294    !!!DO NOT RELEASE or MODIFY the retrieved frame!!!      */
00295 CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
00296 
00297 /* stop capturing/reading and free resources */
00298 CVAPI(void) cvReleaseCapture( CvCapture** capture );
00299 
00300 #define CV_CAP_PROP_POS_MSEC       0
00301 #define CV_CAP_PROP_POS_FRAMES     1
00302 #define CV_CAP_PROP_POS_AVI_RATIO  2
00303 #define CV_CAP_PROP_FRAME_WIDTH    3
00304 #define CV_CAP_PROP_FRAME_HEIGHT   4
00305 #define CV_CAP_PROP_FPS            5
00306 #define CV_CAP_PROP_FOURCC         6
00307 #define CV_CAP_PROP_FRAME_COUNT    7
00308 #define CV_CAP_PROP_FORMAT         8
00309 #define CV_CAP_PROP_MODE           9
00310 #define CV_CAP_PROP_BRIGHTNESS    10
00311 #define CV_CAP_PROP_CONTRAST      11
00312 #define CV_CAP_PROP_SATURATION    12
00313 #define CV_CAP_PROP_HUE           13
00314 #define CV_CAP_PROP_GAIN          14
00315 #define CV_CAP_PROP_EXPOSURE      15
00316 #define CV_CAP_PROP_CONVERT_RGB   16
00317 #define CV_CAP_PROP_WHITE_BALANCE 17
00318 #define CV_CAP_PROP_RECTIFICATION 18
00319 
00320 /* retrieve or set capture properties */
00321 CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
00322 CVAPI(int)    cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
00323 
00324 // Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY
00325 CVAPI(int)    cvGetCaptureDomain( CvCapture* capture);  
00326 
00327 /* "black box" video file writer structure */
00328 typedef struct CvVideoWriter CvVideoWriter;
00329 
00330 #ifndef SWIG
00331 #define CV_FOURCC(c1,c2,c3,c4)  \
00332     (((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24))
00333 #else
00334   // Prototype for CV_FOURCC so that swig can generate wrapper without mixing up the define
00335   int CV_FOURCC(char c1, char c2, char c3, char c4);
00336 #endif
00337 
00338 #define CV_FOURCC_PROMPT -1  /* Open Codec Selection Dialog (Windows only) */
00339 #define CV_FOURCC_DEFAULT CV_FOURCC('I', 'Y', 'U', 'V') /* Use default codec for specified filename (Linux only) */
00340 
00341 /* initialize video file writer */
00342 CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
00343                                            double fps, CvSize frame_size,
00344                                            int is_color CV_DEFAULT(1));
00345 
00346 //CVAPI(CvVideoWriter*) cvCreateImageSequenceWriter( const char* filename,
00347 //                                                   int is_color CV_DEFAULT(1));
00348 
00349 /* write frame to video file */
00350 CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
00351 
00352 /* close video file writer */
00353 CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
00354 
00355 /****************************************************************************************\
00356 *                              Obsolete functions/synonyms                               *
00357 \****************************************************************************************/
00358 
00359 #ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
00360     #define HIGHGUI_BACKWARD_COMPATIBILITY
00361 #endif
00362 
00363 #ifdef HIGHGUI_BACKWARD_COMPATIBILITY
00364 
00365 #define cvCaptureFromFile cvCreateFileCapture
00366 #define cvCaptureFromCAM cvCreateCameraCapture
00367 #define cvCaptureFromAVI cvCaptureFromFile
00368 #define cvCreateAVIWriter cvCreateVideoWriter
00369 #define cvWriteToAVI cvWriteFrame
00370 #define cvAddSearchPath(path)
00371 #define cvvInitSystem cvInitSystem
00372 #define cvvNamedWindow cvNamedWindow
00373 #define cvvShowImage cvShowImage
00374 #define cvvResizeWindow cvResizeWindow
00375 #define cvvDestroyWindow cvDestroyWindow
00376 #define cvvCreateTrackbar cvCreateTrackbar
00377 #define cvvLoadImage(name) cvLoadImage((name),1)
00378 #define cvvSaveImage cvSaveImage
00379 #define cvvAddSearchPath cvAddSearchPath
00380 #define cvvWaitKey(name) cvWaitKey(0)
00381 #define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
00382 #define cvvConvertImage cvConvertImage
00383 #define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
00384 #define set_preprocess_func cvSetPreprocessFuncWin32
00385 #define set_postprocess_func cvSetPostprocessFuncWin32
00386 
00387 #if defined WIN32 || defined _WIN32
00388 
00389 typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
00390 CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
00391 CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
00392 
00393 CV_INLINE int iplWidth( const IplImage* img );
00394 CV_INLINE int iplWidth( const IplImage* img )
00395 {
00396     return !img ? 0 : !img->roi ? img->width : img->roi->width;
00397 }
00398 
00399 CV_INLINE int iplHeight( const IplImage* img );
00400 CV_INLINE int iplHeight( const IplImage* img )
00401 {
00402     return !img ? 0 : !img->roi ? img->height : img->roi->height;
00403 }
00404 
00405 #endif
00406 
00407 #endif /* obsolete functions */
00408 
00409 /* For use with Win32 */
00410 #if defined WIN32 || defined _WIN32
00411 
00412 CV_INLINE RECT NormalizeRect( RECT r );
00413 CV_INLINE RECT NormalizeRect( RECT r )
00414 {
00415     int t;
00416 
00417     if( r.left > r.right )
00418     {
00419         t = r.left;
00420         r.left = r.right;
00421         r.right = t;
00422     }
00423 
00424     if( r.top > r.bottom )
00425     {
00426         t = r.top;
00427         r.top = r.bottom;
00428         r.bottom = t;
00429     }
00430 
00431     return r;
00432 }
00433 
00434 CV_INLINE CvRect RectToCvRect( RECT sr );
00435 CV_INLINE CvRect RectToCvRect( RECT sr )
00436 {
00437     sr = NormalizeRect( sr );
00438     return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
00439 }
00440 
00441 CV_INLINE RECT CvRectToRect( CvRect sr );
00442 CV_INLINE RECT CvRectToRect( CvRect sr )
00443 {
00444     RECT dr;
00445     dr.left = sr.x;
00446     dr.top = sr.y;
00447     dr.right = sr.x + sr.width;
00448     dr.bottom = sr.y + sr.height;
00449 
00450     return dr;
00451 }
00452 
00453 CV_INLINE IplROI RectToROI( RECT r );
00454 CV_INLINE IplROI RectToROI( RECT r )
00455 {
00456     IplROI roi;
00457     r = NormalizeRect( r );
00458     roi.xOffset = r.left;
00459     roi.yOffset = r.top;
00460     roi.width = r.right - r.left;
00461     roi.height = r.bottom - r.top;
00462     roi.coi = 0;
00463 
00464     return roi;
00465 }
00466 
00467 #endif /* WIN32 */
00468 
00469 #ifdef __cplusplus
00470 }  /* end of extern "C" */
00471 #endif /* __cplusplus */
00472 
00473 
00474 #if defined __cplusplus && !defined CV_NO_CVV_IMAGE
00475 
00476 /* CvvImage class definition */
00477 class CV_EXPORTS CvvImage
00478 {
00479 public:
00480     CvvImage();
00481     virtual ~CvvImage();
00482 
00483     /* Create image (BGR or grayscale) */
00484     virtual bool  Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
00485 
00486     /* Load image from specified file */
00487     virtual bool  Load( const char* filename, int desired_color = 1 );
00488 
00489     /* Load rectangle from the file */
00490     virtual bool  LoadRect( const char* filename,
00491                             int desired_color, CvRect r );
00492 
00493 #if defined WIN32 || defined _WIN32
00494     virtual bool  LoadRect( const char* filename,
00495                             int desired_color, RECT r )
00496     {
00497         return LoadRect( filename, desired_color,
00498                          cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
00499     }
00500 #endif
00501 
00502     /* Save entire image to specified file. */
00503     virtual bool  Save( const char* filename );
00504 
00505     /* Get copy of input image ROI */
00506     virtual void  CopyOf( CvvImage& image, int desired_color = -1 );
00507     virtual void  CopyOf( IplImage* img, int desired_color = -1 );
00508 
00509     IplImage* GetImage() { return m_img; };
00510     virtual void  Destroy(void);
00511 
00512     /* width and height of ROI */
00513     int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
00514     int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
00515     int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
00516 
00517     virtual void  Fill( int color );
00518 
00519     /* draw to highgui window */
00520     virtual void  Show( const char* window );
00521 
00522 #if defined WIN32 || defined _WIN32
00523     /* draw part of image to the specified DC */
00524     virtual void  Show( HDC dc, int x, int y, int width, int height,
00525                         int from_x = 0, int from_y = 0 );
00526     /* draw the current image ROI to the specified rectangle of the destination DC */
00527     virtual void  DrawToHDC( HDC hDCDst, RECT* pDstRect );
00528 #endif
00529 
00530 protected:
00531 
00532     IplImage*  m_img;
00533 };
00534 
00535 typedef CvvImage CImage;
00536 
00537 
00538 #endif /* __cplusplus */
00539 
00540 
00541 /****************************************************************************************\
00542 *                                    New interface                                       *
00543 \****************************************************************************************/
00544 
00545 #include "highgui.hpp"
00546 
00547 #endif