highgui.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  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.
  8. //
  9. //
  10. // Intel License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000, Intel Corporation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  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.
  25. //
  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.
  28. //
  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.
  39. //
  40. //M*/
  41. #ifndef _HIGH_GUI_
  42. #define _HIGH_GUI_
  43. #ifndef SKIP_INCLUDES
  44. #include "cxcore.h"
  45. #if defined WIN32 || defined WIN64
  46. #include <windows.h>
  47. #endif
  48. #else // SKIP_INCLUDES
  49. #if defined WIN32 || defined WIN64
  50. #define CV_CDECL __cdecl
  51. #define CV_STDCALL __stdcall
  52. #else
  53. #define CV_CDECL
  54. #define CV_STDCALL
  55. #endif
  56. #ifndef CV_EXTERN_C
  57. #ifdef __cplusplus
  58. #define CV_EXTERN_C extern "C"
  59. #define CV_DEFAULT(val) = val
  60. #else
  61. #define CV_EXTERN_C
  62. #define CV_DEFAULT(val)
  63. #endif
  64. #endif
  65. #ifndef CV_EXTERN_C_FUNCPTR
  66. #ifdef __cplusplus
  67. #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
  68. #else
  69. #define CV_EXTERN_C_FUNCPTR(x) typedef x
  70. #endif
  71. #endif
  72. #ifndef CV_INLINE
  73. #if defined __cplusplus
  74. #define CV_INLINE inline
  75. #elif (defined WIN32 || defined WIN64) && !defined __GNUC__
  76. #define CV_INLINE __inline
  77. #else
  78. #define CV_INLINE static
  79. #endif
  80. #endif /* CV_INLINE */
  81. #if (defined WIN32 || defined WIN64) && defined CVAPI_EXPORTS
  82. #define CV_EXPORTS __declspec(dllexport)
  83. #else
  84. #define CV_EXPORTS
  85. #endif
  86. #ifndef CVAPI
  87. #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
  88. #endif
  89. #endif // SKIP_INCLUDES
  90. #if defined(_CH_)
  91. #pragma package <chopencv>
  92. #include <chdl.h>
  93. LOAD_CHDL(highgui)
  94. #endif
  95. #ifdef __cplusplus
  96. extern "C" {
  97. #endif /* __cplusplus */
  98. /****************************************************************************************\
  99. * Basic GUI functions *
  100. \****************************************************************************************/
  101. /* this function is used to set some external parameters in case of X Window */
  102. CVAPI(int) cvInitSystem( int argc, char** argv );
  103. CVAPI(int) cvStartWindowThread();
  104. #define CV_WINDOW_AUTOSIZE 1
  105. /* create window */
  106. CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
  107. /* display image within window (highgui windows remember their content) */
  108. CVAPI(void) cvShowImage( const char* name, const CvArr* image );
  109. /* resize/move window */
  110. CVAPI(void) cvResizeWindow( const char* name, int width, int height );
  111. CVAPI(void) cvMoveWindow( const char* name, int x, int y );
  112. /* destroy window and all the trackers associated with it */
  113. CVAPI(void) cvDestroyWindow( const char* name );
  114. CVAPI(void) cvDestroyAllWindows(void);
  115. /* get native window handle (HWND in case of Win32 and Widget in case of X Window) */
  116. CVAPI(void*) cvGetWindowHandle( const char* name );
  117. /* get name of highgui window given its native handle */
  118. CVAPI(const char*) cvGetWindowName( void* window_handle );
  119. typedef void (CV_CDECL *CvTrackbarCallback)(int pos);
  120. /* create trackbar and display it on top of given window, set callback */
  121. CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name,
  122. int* value, int count, CvTrackbarCallback on_change );
  123. /* retrieve or set trackbar position */
  124. CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
  125. CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
  126. #define CV_EVENT_MOUSEMOVE 0
  127. #define CV_EVENT_LBUTTONDOWN 1
  128. #define CV_EVENT_RBUTTONDOWN 2
  129. #define CV_EVENT_MBUTTONDOWN 3
  130. #define CV_EVENT_LBUTTONUP 4
  131. #define CV_EVENT_RBUTTONUP 5
  132. #define CV_EVENT_MBUTTONUP 6
  133. #define CV_EVENT_LBUTTONDBLCLK 7
  134. #define CV_EVENT_RBUTTONDBLCLK 8
  135. #define CV_EVENT_MBUTTONDBLCLK 9
  136. #define CV_EVENT_FLAG_LBUTTON 1
  137. #define CV_EVENT_FLAG_RBUTTON 2
  138. #define CV_EVENT_FLAG_MBUTTON 4
  139. #define CV_EVENT_FLAG_CTRLKEY 8
  140. #define CV_EVENT_FLAG_SHIFTKEY 16
  141. #define CV_EVENT_FLAG_ALTKEY 32
  142. typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
  143. /* assign callback for mouse events */
  144. CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
  145. void* param CV_DEFAULT(NULL));
  146. /* 8bit, color or not */
  147. #define CV_LOAD_IMAGE_UNCHANGED -1
  148. /* 8bit, gray */
  149. #define CV_LOAD_IMAGE_GRAYSCALE 0
  150. /* ?, color */
  151. #define CV_LOAD_IMAGE_COLOR 1
  152. /* any depth, ? */
  153. #define CV_LOAD_IMAGE_ANYDEPTH 2
  154. /* ?, any color */
  155. #define CV_LOAD_IMAGE_ANYCOLOR 4
  156. /* load image from file
  157. iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
  158. overrides the other flags
  159. using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
  160. unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
  161. */
  162. CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
  163. CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
  164. /* save image to file */
  165. CVAPI(int) cvSaveImage( const char* filename, const CvArr* image );
  166. #define CV_CVTIMG_FLIP 1
  167. #define CV_CVTIMG_SWAP_RB 2
  168. /* utility function: convert one image to another with optional vertical flip */
  169. CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
  170. /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
  171. CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
  172. /****************************************************************************************\
  173. * Working with Video Files and Cameras *
  174. \****************************************************************************************/
  175. /* "black box" capture structure */
  176. typedef struct CvCapture CvCapture;
  177. /* start capturing frames from video file */
  178. CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
  179. #define CV_CAP_ANY 0 // autodetect
  180. #define CV_CAP_MIL 100 // MIL proprietary drivers
  181. #define CV_CAP_VFW 200 // platform native
  182. #define CV_CAP_V4L 200
  183. #define CV_CAP_V4L2 200
  184. #define CV_CAP_FIREWARE 300 // IEEE 1394 drivers
  185. #define CV_CAP_IEEE1394 300
  186. #define CV_CAP_DC1394 300
  187. #define CV_CAP_CMU1394 300
  188. #define CV_CAP_STEREO 400 // TYZX proprietary drivers
  189. #define CV_CAP_TYZX 400
  190. #define CV_TYZX_LEFT 400
  191. #define CV_TYZX_RIGHT 401
  192. #define CV_TYZX_COLOR 402
  193. #define CV_TYZX_Z 403
  194. #define CV_CAP_QT 500 // QuickTime
  195. /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
  196. CVAPI(CvCapture*) cvCreateCameraCapture( int index );
  197. /* grab a frame, return 1 on success, 0 on fail.
  198. this function is thought to be fast */
  199. CVAPI(int) cvGrabFrame( CvCapture* capture );
  200. /* get the frame grabbed with cvGrabFrame(..)
  201. This function may apply some frame processing like
  202. frame decompression, flipping etc.
  203. !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
  204. CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture );
  205. /* Just a combination of cvGrabFrame and cvRetrieveFrame
  206. !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
  207. CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
  208. /* stop capturing/reading and free resources */
  209. CVAPI(void) cvReleaseCapture( CvCapture** capture );
  210. #define CV_CAP_PROP_POS_MSEC 0
  211. #define CV_CAP_PROP_POS_FRAMES 1
  212. #define CV_CAP_PROP_POS_AVI_RATIO 2
  213. #define CV_CAP_PROP_FRAME_WIDTH 3
  214. #define CV_CAP_PROP_FRAME_HEIGHT 4
  215. #define CV_CAP_PROP_FPS 5
  216. #define CV_CAP_PROP_FOURCC 6
  217. #define CV_CAP_PROP_FRAME_COUNT 7
  218. #define CV_CAP_PROP_FORMAT 8
  219. #define CV_CAP_PROP_MODE 9
  220. #define CV_CAP_PROP_BRIGHTNESS 10
  221. #define CV_CAP_PROP_CONTRAST 11
  222. #define CV_CAP_PROP_SATURATION 12
  223. #define CV_CAP_PROP_HUE 13
  224. #define CV_CAP_PROP_GAIN 14
  225. #define CV_CAP_PROP_CONVERT_RGB 15
  226. /* retrieve or set capture properties */
  227. CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
  228. CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
  229. /* "black box" video file writer structure */
  230. typedef struct CvVideoWriter CvVideoWriter;
  231. #define CV_FOURCC(c1,c2,c3,c4) \
  232. (((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24))
  233. /* initialize video file writer */
  234. CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
  235. double fps, CvSize frame_size,
  236. int is_color CV_DEFAULT(1));
  237. /* write frame to video file */
  238. CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
  239. /* close video file writer */
  240. CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
  241. /****************************************************************************************\
  242. * Obsolete functions/synonyms *
  243. \****************************************************************************************/
  244. #ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
  245. #define HIGHGUI_BACKWARD_COMPATIBILITY
  246. #endif
  247. #ifdef HIGHGUI_BACKWARD_COMPATIBILITY
  248. #define cvCaptureFromFile cvCreateFileCapture
  249. #define cvCaptureFromCAM cvCreateCameraCapture
  250. #define cvCaptureFromAVI cvCaptureFromFile
  251. #define cvCreateAVIWriter cvCreateVideoWriter
  252. #define cvWriteToAVI cvWriteFrame
  253. #define cvAddSearchPath(path)
  254. #define cvvInitSystem cvInitSystem
  255. #define cvvNamedWindow cvNamedWindow
  256. #define cvvShowImage cvShowImage
  257. #define cvvResizeWindow cvResizeWindow
  258. #define cvvDestroyWindow cvDestroyWindow
  259. #define cvvCreateTrackbar cvCreateTrackbar
  260. #define cvvLoadImage(name) cvLoadImage((name),1)
  261. #define cvvSaveImage cvSaveImage
  262. #define cvvAddSearchPath cvAddSearchPath
  263. #define cvvWaitKey(name) cvWaitKey(0)
  264. #define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
  265. #define cvvConvertImage cvConvertImage
  266. #define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
  267. #define set_preprocess_func cvSetPreprocessFuncWin32
  268. #define set_postprocess_func cvSetPostprocessFuncWin32
  269. #ifdef WIN32
  270. typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
  271. CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
  272. CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
  273. CV_INLINE int iplWidth( const IplImage* img );
  274. CV_INLINE int iplWidth( const IplImage* img )
  275. {
  276. return !img ? 0 : !img->roi ? img->width : img->roi->width;
  277. }
  278. CV_INLINE int iplHeight( const IplImage* img );
  279. CV_INLINE int iplHeight( const IplImage* img )
  280. {
  281. return !img ? 0 : !img->roi ? img->height : img->roi->height;
  282. }
  283. #endif
  284. #endif /* obsolete functions */
  285. /* For use with Win32 */
  286. #ifdef WIN32
  287. CV_INLINE RECT NormalizeRect( RECT r );
  288. CV_INLINE RECT NormalizeRect( RECT r )
  289. {
  290. int t;
  291. if( r.left > r.right )
  292. {
  293. t = r.left;
  294. r.left = r.right;
  295. r.right = t;
  296. }
  297. if( r.top > r.bottom )
  298. {
  299. t = r.top;
  300. r.top = r.bottom;
  301. r.bottom = t;
  302. }
  303. return r;
  304. }
  305. CV_INLINE CvRect RectToCvRect( RECT sr );
  306. CV_INLINE CvRect RectToCvRect( RECT sr )
  307. {
  308. sr = NormalizeRect( sr );
  309. return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
  310. }
  311. CV_INLINE RECT CvRectToRect( CvRect sr );
  312. CV_INLINE RECT CvRectToRect( CvRect sr )
  313. {
  314. RECT dr;
  315. dr.left = sr.x;
  316. dr.top = sr.y;
  317. dr.right = sr.x + sr.width;
  318. dr.bottom = sr.y + sr.height;
  319. return dr;
  320. }
  321. CV_INLINE IplROI RectToROI( RECT r );
  322. CV_INLINE IplROI RectToROI( RECT r )
  323. {
  324. IplROI roi;
  325. r = NormalizeRect( r );
  326. roi.xOffset = r.left;
  327. roi.yOffset = r.top;
  328. roi.width = r.right - r.left;
  329. roi.height = r.bottom - r.top;
  330. roi.coi = 0;
  331. return roi;
  332. }
  333. #endif /* WIN32 */
  334. #ifdef __cplusplus
  335. } /* end of extern "C" */
  336. #endif /* __cplusplus */
  337. #if defined __cplusplus && (!defined WIN32 || !defined (__GNUC__))
  338. #define CImage CvvImage
  339. /* CvvImage class definition */
  340. class CV_EXPORTS CvvImage
  341. {
  342. public:
  343. CvvImage();
  344. virtual ~CvvImage();
  345. /* Create image (BGR or grayscale) */
  346. virtual bool Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
  347. /* Load image from specified file */
  348. virtual bool Load( const char* filename, int desired_color = 1 );
  349. /* Load rectangle from the file */
  350. virtual bool LoadRect( const char* filename,
  351. int desired_color, CvRect r );
  352. #ifdef WIN32
  353. virtual bool LoadRect( const char* filename,
  354. int desired_color, RECT r )
  355. {
  356. return LoadRect( filename, desired_color,
  357. cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
  358. }
  359. #endif
  360. /* Save entire image to specified file. */
  361. virtual bool Save( const char* filename );
  362. /* Get copy of input image ROI */
  363. virtual void CopyOf( CvvImage& image, int desired_color = -1 );
  364. virtual void CopyOf( IplImage* img, int desired_color = -1 );
  365. IplImage* GetImage() { return m_img; };
  366. virtual void Destroy(void);
  367. /* width and height of ROI */
  368. int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
  369. int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
  370. int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
  371. virtual void Fill( int color );
  372. /* draw to highgui window */
  373. virtual void Show( const char* window );
  374. #ifdef WIN32
  375. /* draw part of image to the specified DC */
  376. virtual void Show( HDC dc, int x, int y, int width, int height,
  377. int from_x = 0, int from_y = 0 );
  378. /* draw the current image ROI to the specified rectangle of the destination DC */
  379. virtual void DrawToHDC( HDC hDCDst, RECT* pDstRect );
  380. #endif
  381. protected:
  382. IplImage* m_img;
  383. };
  384. #endif /* __cplusplus */
  385. #endif /* _HIGH_GUI_ */