PageRenderTime 625ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/opencv/highgui.h

https://github.com/ra--/BrainBay
C Header | 447 lines | 260 code | 93 blank | 94 comment | 10 complexity | d444e7c12ec41e524122462cd27ce011 MD5 | raw file
  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. #define CV_WINDOW_AUTOSIZE 1
  104. /* create window */
  105. CVAPI(int) cvNamedWindow( const char* name, int flags );
  106. /* display image within window (highgui windows remember their content) */
  107. CVAPI(void) cvShowImage( const char* name, const CvArr* image );
  108. /* resize/move window */
  109. CVAPI(void) cvResizeWindow( const char* name, int width, int height );
  110. CVAPI(void) cvMoveWindow( const char* name, int x, int y );
  111. /* destroy window and all the trackers associated with it */
  112. CVAPI(void) cvDestroyWindow( const char* name );
  113. CVAPI(void) cvDestroyAllWindows(void);
  114. /* get native window handle (HWND in case of Win32 and Widget in case of X Window) */
  115. CVAPI(void*) cvGetWindowHandle( const char* name );
  116. /* get name of highgui window given its native handle */
  117. CVAPI(const char*) cvGetWindowName( void* window_handle );
  118. typedef void (CV_CDECL *CvTrackbarCallback)(int pos);
  119. /* create trackbar and display it on top of given window, set callback */
  120. CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name,
  121. int* value, int count, CvTrackbarCallback on_change );
  122. /* retrieve or set trackbar position */
  123. CVAPI(int) cvGetTrackbarPos( const char* trackbar_name, const char* window_name );
  124. CVAPI(void) cvSetTrackbarPos( const char* trackbar_name, const char* window_name, int pos );
  125. #define CV_EVENT_MOUSEMOVE 0
  126. #define CV_EVENT_LBUTTONDOWN 1
  127. #define CV_EVENT_RBUTTONDOWN 2
  128. #define CV_EVENT_MBUTTONDOWN 3
  129. #define CV_EVENT_LBUTTONUP 4
  130. #define CV_EVENT_RBUTTONUP 5
  131. #define CV_EVENT_MBUTTONUP 6
  132. #define CV_EVENT_LBUTTONDBLCLK 7
  133. #define CV_EVENT_RBUTTONDBLCLK 8
  134. #define CV_EVENT_MBUTTONDBLCLK 9
  135. #define CV_EVENT_FLAG_LBUTTON 1
  136. #define CV_EVENT_FLAG_RBUTTON 2
  137. #define CV_EVENT_FLAG_MBUTTON 4
  138. #define CV_EVENT_FLAG_CTRLKEY 8
  139. #define CV_EVENT_FLAG_SHIFTKEY 16
  140. #define CV_EVENT_FLAG_ALTKEY 32
  141. typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
  142. /* assign callback for mouse events */
  143. CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
  144. void* param CV_DEFAULT(NULL));
  145. /*load image from file
  146. iscolor: >0 - output image is always color,
  147. 0 - output image is always grayscale,
  148. <0 - output image is color or grayscale dependending on the file */
  149. CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(1));
  150. /* save image to file */
  151. CVAPI(int) cvSaveImage( const char* filename, const CvArr* image );
  152. #define CV_CVTIMG_FLIP 1
  153. #define CV_CVTIMG_SWAP_RB 2
  154. /* utility function: convert one image to another with optional vertical flip */
  155. CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
  156. /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
  157. CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
  158. /****************************************************************************************\
  159. * Working with Video Files and Cameras *
  160. \****************************************************************************************/
  161. /* "black box" capture structure */
  162. typedef struct CvCapture CvCapture;
  163. /* start capturing frames from video file */
  164. CVAPI(CvCapture*) cvCaptureFromFile( const char* filename );
  165. #define CV_CAP_ANY 0
  166. #define CV_CAP_MIL 100
  167. #define CV_CAP_VFW 200
  168. #define CV_CAP_V4L 200
  169. #define CV_CAP_V4L2 200
  170. #define CV_CAP_FIREWARE 300
  171. #define CV_CAP_IEEE1394 300
  172. #define CV_CAP_DC1394 300
  173. #define CV_CAP_CMU1394 300
  174. /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
  175. CVAPI(CvCapture*) cvCaptureFromCAM( int index );
  176. /* grab a frame, return 1 on success, 0 on fail.
  177. this function is thought to be fast */
  178. CVAPI(int) cvGrabFrame( CvCapture* capture );
  179. /* get the frame grabbed with cvGrabFrame(..)
  180. This function may apply some frame processing like
  181. frame decompression, flipping etc.
  182. !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
  183. CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture );
  184. /* Just a combination of cvGrabFrame and cvRetrieveFrame
  185. !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
  186. CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
  187. /* stop capturing/reading and free resources */
  188. CVAPI(void) cvReleaseCapture( CvCapture** capture );
  189. #define CV_CAP_PROP_POS_MSEC 0
  190. #define CV_CAP_PROP_POS_FRAMES 1
  191. #define CV_CAP_PROP_POS_AVI_RATIO 2
  192. #define CV_CAP_PROP_FRAME_WIDTH 3
  193. #define CV_CAP_PROP_FRAME_HEIGHT 4
  194. #define CV_CAP_PROP_FPS 5
  195. #define CV_CAP_PROP_FOURCC 6
  196. #define CV_CAP_PROP_FRAME_COUNT 7
  197. /* retrieve or set capture properties */
  198. CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
  199. CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
  200. /* "black box" video file writer structure */
  201. typedef struct CvVideoWriter CvVideoWriter;
  202. #define CV_FOURCC(c1,c2,c3,c4) \
  203. (((c1)&255) + (((c2)&255)<<8) + (((c3)&255)<<16) + (((c4)&255)<<24))
  204. /* initialize video file writer */
  205. CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
  206. double fps, CvSize frame_size,
  207. int is_color CV_DEFAULT(1));
  208. /* write frame to video file */
  209. CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
  210. /* close video file writer */
  211. CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
  212. /****************************************************************************************\
  213. * Obsolete functions/synonyms *
  214. \****************************************************************************************/
  215. #ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
  216. #define HIGHGUI_BACKWARD_COMPATIBILITY
  217. #endif
  218. #ifdef HIGHGUI_BACKWARD_COMPATIBILITY
  219. #define cvCaptureFromAVI cvCaptureFromFile
  220. #define cvCreateAVIWriter cvCreateVideoWriter
  221. #define cvWriteToAVI cvWriteFrame
  222. #define cvAddSearchPath(path)
  223. #define cvvInitSystem cvInitSystem
  224. #define cvvNamedWindow cvNamedWindow
  225. #define cvvShowImage cvShowImage
  226. #define cvvResizeWindow cvResizeWindow
  227. #define cvvDestroyWindow cvDestroyWindow
  228. #define cvvCreateTrackbar cvCreateTrackbar
  229. #define cvvLoadImage(name) cvLoadImage((name),1)
  230. #define cvvSaveImage cvSaveImage
  231. #define cvvAddSearchPath cvAddSearchPath
  232. #define cvvWaitKey(name) cvWaitKey(0)
  233. #define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
  234. #define cvvConvertImage cvConvertImage
  235. #define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
  236. #define set_preprocess_func cvSetPreprocessFuncWin32
  237. #define set_postprocess_func cvSetPostprocessFuncWin32
  238. #ifdef WIN32
  239. typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
  240. CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
  241. CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
  242. CV_INLINE int iplWidth( const IplImage* img );
  243. CV_INLINE int iplWidth( const IplImage* img )
  244. {
  245. return !img ? 0 : !img->roi ? img->width : img->roi->width;
  246. }
  247. CV_INLINE int iplHeight( const IplImage* img );
  248. CV_INLINE int iplHeight( const IplImage* img )
  249. {
  250. return !img ? 0 : !img->roi ? img->height : img->roi->height;
  251. }
  252. #endif
  253. #endif /* obsolete functions */
  254. /* For use with Win32 */
  255. #ifdef WIN32
  256. CV_INLINE RECT NormalizeRect( RECT r );
  257. CV_INLINE RECT NormalizeRect( RECT r )
  258. {
  259. int t;
  260. if( r.left > r.right )
  261. {
  262. t = r.left;
  263. r.left = r.right;
  264. r.right = t;
  265. }
  266. if( r.top > r.bottom )
  267. {
  268. t = r.top;
  269. r.top = r.bottom;
  270. r.bottom = t;
  271. }
  272. return r;
  273. }
  274. CV_INLINE CvRect RectToCvRect( RECT sr );
  275. CV_INLINE CvRect RectToCvRect( RECT sr )
  276. {
  277. sr = NormalizeRect( sr );
  278. return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
  279. }
  280. CV_INLINE RECT CvRectToRect( CvRect sr );
  281. CV_INLINE RECT CvRectToRect( CvRect sr )
  282. {
  283. RECT dr;
  284. dr.left = sr.x;
  285. dr.top = sr.y;
  286. dr.right = sr.x + sr.width;
  287. dr.bottom = sr.y + sr.height;
  288. return dr;
  289. }
  290. CV_INLINE IplROI RectToROI( RECT r );
  291. CV_INLINE IplROI RectToROI( RECT r )
  292. {
  293. IplROI roi;
  294. r = NormalizeRect( r );
  295. roi.xOffset = r.left;
  296. roi.yOffset = r.top;
  297. roi.width = r.right - r.left;
  298. roi.height = r.bottom - r.top;
  299. roi.coi = 0;
  300. return roi;
  301. }
  302. #endif /* WIN32 */
  303. #ifdef __cplusplus
  304. } /* end of extern "C" */
  305. #endif /* __cplusplus */
  306. #if defined __cplusplus && (!defined WIN32 || !defined (__GNUC__))
  307. #define CImage CvvImage
  308. /* CvvImage class definition */
  309. class CV_EXPORTS CvvImage
  310. {
  311. public:
  312. CvvImage();
  313. virtual ~CvvImage();
  314. /* Create image (BGR or grayscale) */
  315. virtual bool Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
  316. /* Load image from specified file */
  317. virtual bool Load( const char* filename, int desired_color = 1 );
  318. /* Load rectangle from the file */
  319. virtual bool LoadRect( const char* filename,
  320. int desired_color, CvRect r );
  321. #ifdef WIN32
  322. virtual bool LoadRect( const char* filename,
  323. int desired_color, RECT r )
  324. {
  325. return LoadRect( filename, desired_color,
  326. cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
  327. }
  328. #endif
  329. /* Save entire image to specified file. */
  330. virtual bool Save( const char* filename );
  331. /* Get copy of input image ROI */
  332. virtual void CopyOf( CvvImage& image, int desired_color = -1 );
  333. virtual void CopyOf( IplImage* img, int desired_color = -1 );
  334. IplImage* GetImage() { return m_img; };
  335. virtual void Destroy(void);
  336. /* width and height of ROI */
  337. int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
  338. int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
  339. int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
  340. virtual void Fill( int color );
  341. /* draw to highgui window */
  342. virtual void Show( const char* window );
  343. #ifdef WIN32
  344. /* draw part of image to the specified DC */
  345. virtual void Show( HDC dc, int x, int y, int width, int height,
  346. int from_x = 0, int from_y = 0 );
  347. /* draw the current image ROI to the specified rectangle of the destination DC */
  348. virtual void DrawToHDC( HDC hDCDst, RECT* pDstRect );
  349. #endif
  350. protected:
  351. IplImage* m_img;
  352. };
  353. #endif /* __cplusplus */
  354. #endif /* _HIGH_GUI_ */