1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
48 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
52 #else // SKIP_INCLUDES
54 #if defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64
55 #define CV_CDECL __cdecl
56 #define CV_STDCALL __stdcall
64 #define CV_EXTERN_C extern "C"
65 #define CV_DEFAULT(val) = val
68 #define CV_DEFAULT(val)
72 #ifndef CV_EXTERN_C_FUNCPTR
74 #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
76 #define CV_EXTERN_C_FUNCPTR(x) typedef x
81 #if defined __cplusplus
82 #define CV_INLINE inline
83 #elif (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && !defined __GNUC__
84 #define CV_INLINE __inline
86 #define CV_INLINE static
88 #endif /* CV_INLINE */
90 #if (defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && defined CVAPI_EXPORTS
91 #define CV_EXPORTS __declspec(dllexport)
97 #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
100 #endif // SKIP_INCLUDES
103 #pragma package <chopencv>
110 #endif /* __cplusplus */
112 /****************************************************************************************\
113 * Basic GUI functions *
114 \****************************************************************************************/
116 /* this function is used to set some external parameters in case of X Window */
117 CVAPI(int) cvInitSystem( int argc, char** argv );
119 CVAPI(int) cvStartWindowThread();
121 #define CV_WINDOW_AUTOSIZE 1
123 CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
125 /* display image within window (highgui windows remember their content) */
126 CVAPI(void) cvShowImage( const char* name, const CvArr* image );
128 /* resize/move window */
129 CVAPI(void) cvResizeWindow( const char* name, int width, int height );
130 CVAPI(void) cvMoveWindow( const char* name, int x, int y );
133 /* destroy window and all the trackers associated with it */
134 CVAPI(void) cvDestroyWindow( const char* name );
136 CVAPI(void) cvDestroyAllWindows(void);
138 /* get native window handle (HWND in case of Win32 and Widget in case of X Window) */
139 CVAPI(void*) cvGetWindowHandle( const char* name );
141 /* get name of highgui window given its native handle */
142 CVAPI(const char*) cvGetWindowName( void* window_handle );
145 typedef void (CV_CDECL *CvTrackbarCallback)(int pos);
147 /* create trackbar and display it on top of given window, set callback */
148 CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name,
149 int* value, int count, CvTrackbarCallback on_change);
151 typedef void (CV_CDECL *CvTrackbarCallback2)(int pos, void* userdata);
153 CVAPI(int) cvCreateTrackbar2( const char* trackbar_name, const char* window_name,
154 int* value, int count, CvTrackbarCallback2 on_change,
155 void* userdata CV_DEFAULT(0));
157 /* retrieve or set trackbar position */
158 CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
159 CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
161 #define CV_EVENT_MOUSEMOVE 0
162 #define CV_EVENT_LBUTTONDOWN 1
163 #define CV_EVENT_RBUTTONDOWN 2
164 #define CV_EVENT_MBUTTONDOWN 3
165 #define CV_EVENT_LBUTTONUP 4
166 #define CV_EVENT_RBUTTONUP 5
167 #define CV_EVENT_MBUTTONUP 6
168 #define CV_EVENT_LBUTTONDBLCLK 7
169 #define CV_EVENT_RBUTTONDBLCLK 8
170 #define CV_EVENT_MBUTTONDBLCLK 9
172 #define CV_EVENT_FLAG_LBUTTON 1
173 #define CV_EVENT_FLAG_RBUTTON 2
174 #define CV_EVENT_FLAG_MBUTTON 4
175 #define CV_EVENT_FLAG_CTRLKEY 8
176 #define CV_EVENT_FLAG_SHIFTKEY 16
177 #define CV_EVENT_FLAG_ALTKEY 32
179 typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
181 /* assign callback for mouse events */
182 CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
183 void* param CV_DEFAULT(NULL));
185 /* 8bit, color or not */
186 #define CV_LOAD_IMAGE_UNCHANGED -1
188 #define CV_LOAD_IMAGE_GRAYSCALE 0
190 #define CV_LOAD_IMAGE_COLOR 1
192 #define CV_LOAD_IMAGE_ANYDEPTH 2
194 #define CV_LOAD_IMAGE_ANYCOLOR 4
196 /* load image from file
197 iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
198 overrides the other flags
199 using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
200 unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
202 CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
203 CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
205 #define CV_IMWRITE_JPEG_QUALITY 1
206 #define CV_IMWRITE_PNG_COMPRESSION 16
207 #define CV_IMWRITE_PXM_BINARY 32
209 /* save image to file */
210 CVAPI(int) cvSaveImage( const char* filename, const CvArr* image,
211 const int* params CV_DEFAULT(0) );
213 /* decode image stored in the buffer */
214 CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
215 CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
217 /* encode image and store the result as a byte vector (single-row 8uC1 matrix) */
218 CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image,
219 const int* params CV_DEFAULT(0) );
221 #define CV_CVTIMG_FLIP 1
222 #define CV_CVTIMG_SWAP_RB 2
223 /* utility function: convert one image to another with optional vertical flip */
224 CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
226 /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
227 CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
230 /****************************************************************************************\
231 * Working with Video Files and Cameras *
232 \****************************************************************************************/
234 /* "black box" capture structure */
235 typedef struct CvCapture CvCapture;
237 /* start capturing frames from video file */
238 CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
240 #define CV_CAP_ANY 0 // autodetect
242 #define CV_CAP_MIL 100 // MIL proprietary drivers
244 #define CV_CAP_VFW 200 // platform native
245 #define CV_CAP_V4L 200
246 #define CV_CAP_V4L2 200
248 #define CV_CAP_FIREWARE 300 // IEEE 1394 drivers
249 #define CV_CAP_FIREWIRE 300
250 #define CV_CAP_IEEE1394 300
251 #define CV_CAP_DC1394 300
252 #define CV_CAP_CMU1394 300
254 #define CV_CAP_STEREO 400 // TYZX proprietary drivers
255 #define CV_CAP_TYZX 400
256 #define CV_TYZX_LEFT 400
257 #define CV_TYZX_RIGHT 401
258 #define CV_TYZX_COLOR 402
259 #define CV_TYZX_Z 403
261 #define CV_CAP_QT 500 // QuickTime
263 #define CV_CAP_UNICAP 600 // Unicap drivers
265 #define CV_CAP_DSHOW 700 // DirectShow (via videoInput)
267 /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
268 CVAPI(CvCapture*) cvCreateCameraCapture( int index );
270 /* grab a frame, return 1 on success, 0 on fail.
271 this function is thought to be fast */
272 CVAPI(int) cvGrabFrame( CvCapture* capture );
274 /* get the frame grabbed with cvGrabFrame(..)
275 This function may apply some frame processing like
276 frame decompression, flipping etc.
277 !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
278 CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture, int streamIdx CV_DEFAULT(0) );
280 /* Just a combination of cvGrabFrame and cvRetrieveFrame
281 !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
282 CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
284 /* stop capturing/reading and free resources */
285 CVAPI(void) cvReleaseCapture( CvCapture** capture );
287 #define CV_CAP_PROP_POS_MSEC 0
288 #define CV_CAP_PROP_POS_FRAMES 1
289 #define CV_CAP_PROP_POS_AVI_RATIO 2
290 #define CV_CAP_PROP_FRAME_WIDTH 3
291 #define CV_CAP_PROP_FRAME_HEIGHT 4
292 #define CV_CAP_PROP_FPS 5
293 #define CV_CAP_PROP_FOURCC 6
294 #define CV_CAP_PROP_FRAME_COUNT 7
295 #define CV_CAP_PROP_FORMAT 8
296 #define CV_CAP_PROP_MODE 9
297 #define CV_CAP_PROP_BRIGHTNESS 10
298 #define CV_CAP_PROP_CONTRAST 11
299 #define CV_CAP_PROP_SATURATION 12
300 #define CV_CAP_PROP_HUE 13
301 #define CV_CAP_PROP_GAIN 14
302 #define CV_CAP_PROP_EXPOSURE 15
303 #define CV_CAP_PROP_CONVERT_RGB 16
304 #define CV_CAP_PROP_WHITE_BALANCE 17
305 #define CV_CAP_PROP_RECTIFICATION 18
307 /* retrieve or set capture properties */
308 CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
309 CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
311 // Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY
312 CVAPI(int) cvGetCaptureDomain( CvCapture* capture);
314 /* "black box" video file writer structure */
315 typedef struct CvVideoWriter CvVideoWriter;
318 #define CV_FOURCC(c1,c2,c3,c4) \
319 (((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24))
321 // Prototype for CV_FOURCC so that swig can generate wrapper without mixing up the define
322 int CV_FOURCC(char c1, char c2, char c3, char c4);
325 #define CV_FOURCC_PROMPT -1 /* Open Codec Selection Dialog (Windows only) */
326 #define CV_FOURCC_DEFAULT CV_FOURCC('I', 'Y', 'U', 'V') /* Use default codec for specified filename (Linux only) */
328 /* initialize video file writer */
329 CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
330 double fps, CvSize frame_size,
331 int is_color CV_DEFAULT(1));
333 //CVAPI(CvVideoWriter*) cvCreateImageSequenceWriter( const char* filename,
334 // int is_color CV_DEFAULT(1));
336 /* write frame to video file */
337 CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
339 /* close video file writer */
340 CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
342 /****************************************************************************************\
343 * Obsolete functions/synonyms *
344 \****************************************************************************************/
346 #ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
347 #define HIGHGUI_BACKWARD_COMPATIBILITY
350 #ifdef HIGHGUI_BACKWARD_COMPATIBILITY
352 #define cvCaptureFromFile cvCreateFileCapture
353 #define cvCaptureFromCAM cvCreateCameraCapture
354 #define cvCaptureFromAVI cvCaptureFromFile
355 #define cvCreateAVIWriter cvCreateVideoWriter
356 #define cvWriteToAVI cvWriteFrame
357 #define cvAddSearchPath(path)
358 #define cvvInitSystem cvInitSystem
359 #define cvvNamedWindow cvNamedWindow
360 #define cvvShowImage cvShowImage
361 #define cvvResizeWindow cvResizeWindow
362 #define cvvDestroyWindow cvDestroyWindow
363 #define cvvCreateTrackbar cvCreateTrackbar
364 #define cvvLoadImage(name) cvLoadImage((name),1)
365 #define cvvSaveImage cvSaveImage
366 #define cvvAddSearchPath cvAddSearchPath
367 #define cvvWaitKey(name) cvWaitKey(0)
368 #define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
369 #define cvvConvertImage cvConvertImage
370 #define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
371 #define set_preprocess_func cvSetPreprocessFuncWin32
372 #define set_postprocess_func cvSetPostprocessFuncWin32
374 #if defined WIN32 || defined _WIN32
376 typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
377 CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
378 CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
380 CV_INLINE int iplWidth( const IplImage* img );
381 CV_INLINE int iplWidth( const IplImage* img )
383 return !img ? 0 : !img->roi ? img->width : img->roi->width;
386 CV_INLINE int iplHeight( const IplImage* img );
387 CV_INLINE int iplHeight( const IplImage* img )
389 return !img ? 0 : !img->roi ? img->height : img->roi->height;
394 #endif /* obsolete functions */
396 /* For use with Win32 */
397 #if defined WIN32 || defined _WIN32
399 CV_INLINE RECT NormalizeRect( RECT r );
400 CV_INLINE RECT NormalizeRect( RECT r )
404 if( r.left > r.right )
411 if( r.top > r.bottom )
421 CV_INLINE CvRect RectToCvRect( RECT sr );
422 CV_INLINE CvRect RectToCvRect( RECT sr )
424 sr = NormalizeRect( sr );
425 return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
428 CV_INLINE RECT CvRectToRect( CvRect sr );
429 CV_INLINE RECT CvRectToRect( CvRect sr )
434 dr.right = sr.x + sr.width;
435 dr.bottom = sr.y + sr.height;
440 CV_INLINE IplROI RectToROI( RECT r );
441 CV_INLINE IplROI RectToROI( RECT r )
444 r = NormalizeRect( r );
445 roi.xOffset = r.left;
447 roi.width = r.right - r.left;
448 roi.height = r.bottom - r.top;
457 } /* end of extern "C" */
458 #endif /* __cplusplus */
461 #if defined __cplusplus && !defined CV_NO_CVV_IMAGE
463 /* CvvImage class definition */
464 class CV_EXPORTS CvvImage
470 /* Create image (BGR or grayscale) */
471 virtual bool Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
473 /* Load image from specified file */
474 virtual bool Load( const char* filename, int desired_color = 1 );
476 /* Load rectangle from the file */
477 virtual bool LoadRect( const char* filename,
478 int desired_color, CvRect r );
480 #if defined WIN32 || defined _WIN32
481 virtual bool LoadRect( const char* filename,
482 int desired_color, RECT r )
484 return LoadRect( filename, desired_color,
485 cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
489 /* Save entire image to specified file. */
490 virtual bool Save( const char* filename );
492 /* Get copy of input image ROI */
493 virtual void CopyOf( CvvImage& image, int desired_color = -1 );
494 virtual void CopyOf( IplImage* img, int desired_color = -1 );
496 IplImage* GetImage() { return m_img; };
497 virtual void Destroy(void);
499 /* width and height of ROI */
500 int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
501 int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
502 int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
504 virtual void Fill( int color );
506 /* draw to highgui window */
507 virtual void Show( const char* window );
509 #if defined WIN32 || defined _WIN32
510 /* draw part of image to the specified DC */
511 virtual void Show( HDC dc, int x, int y, int width, int height,
512 int from_x = 0, int from_y = 0 );
513 /* draw the current image ROI to the specified rectangle of the destination DC */
514 virtual void DrawToHDC( HDC hDCDst, RECT* pDstRect );
522 typedef CvvImage CImage;
525 #endif /* __cplusplus */
528 /****************************************************************************************\
530 \****************************************************************************************/
532 #include "highgui.hpp"
534 #endif /* _HIGH_GUI_ */