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 
42 #ifndef _HIGH_GUI_
43 #define _HIGH_GUI_
44 
45 #ifndef SKIP_INCLUDES
46 
47   #include "cxcore.h"
48   #if defined WIN32 || defined WIN64
49     #include <windows.h>
50   #endif
51 
52 #else // SKIP_INCLUDES
53 
54   #if defined WIN32 || defined WIN64
55     #define CV_CDECL __cdecl
56     #define CV_STDCALL __stdcall
57   #else
58     #define CV_CDECL
59     #define CV_STDCALL
60   #endif
61 
62   #ifndef CV_EXTERN_C
63     #ifdef __cplusplus
64       #define CV_EXTERN_C extern "C"
65       #define CV_DEFAULT(val) = val
66     #else
67       #define CV_EXTERN_C
68       #define CV_DEFAULT(val)
69     #endif
70   #endif
71 
72   #ifndef CV_EXTERN_C_FUNCPTR
73     #ifdef __cplusplus
74       #define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
75     #else
76       #define CV_EXTERN_C_FUNCPTR(x) typedef x
77     #endif
78   #endif
79 
80   #ifndef CV_INLINE
81     #if defined __cplusplus
82       #define CV_INLINE inline
83     #elif (defined WIN32 || defined WIN64) && !defined __GNUC__
84       #define CV_INLINE __inline
85     #else
86       #define CV_INLINE static
87     #endif
88   #endif /* CV_INLINE */
89 
90   #if (defined WIN32 || defined WIN64) && defined CVAPI_EXPORTS
91     #define CV_EXPORTS __declspec(dllexport)
92   #else
93     #define CV_EXPORTS
94   #endif
95 
96   #ifndef CVAPI
97     #define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
98   #endif
99 
100 #endif // SKIP_INCLUDES
101 
102 #if defined(_CH_)
103   #pragma package <chopencv>
104   #include <chdl.h>
LOAD_CHDL(highgui)105   LOAD_CHDL(highgui)
106 #endif
107 
108 #ifdef __cplusplus
109   extern "C" {
110 #endif /* __cplusplus */
111 
112 #define CV_EVENT_MOUSEMOVE      0
113 #define CV_EVENT_LBUTTONDOWN    1
114 #define CV_EVENT_RBUTTONDOWN    2
115 #define CV_EVENT_MBUTTONDOWN    3
116 #define CV_EVENT_LBUTTONUP      4
117 #define CV_EVENT_RBUTTONUP      5
118 #define CV_EVENT_MBUTTONUP      6
119 #define CV_EVENT_LBUTTONDBLCLK  7
120 #define CV_EVENT_RBUTTONDBLCLK  8
121 #define CV_EVENT_MBUTTONDBLCLK  9
122 
123 #define CV_EVENT_FLAG_LBUTTON   1
124 #define CV_EVENT_FLAG_RBUTTON   2
125 #define CV_EVENT_FLAG_MBUTTON   4
126 #define CV_EVENT_FLAG_CTRLKEY   8
127 #define CV_EVENT_FLAG_SHIFTKEY  16
128 #define CV_EVENT_FLAG_ALTKEY    32
129 
130 
131 /* 8bit, color or not */
132 #define CV_LOAD_IMAGE_UNCHANGED  -1
133 /* 8bit, gray */
134 #define CV_LOAD_IMAGE_GRAYSCALE   0
135 /* ?, color */
136 #define CV_LOAD_IMAGE_COLOR       1
137 /* any depth, ? */
138 #define CV_LOAD_IMAGE_ANYDEPTH    2
139 /* ?, any color */
140 #define CV_LOAD_IMAGE_ANYCOLOR    4
141 
142 /* load image from file
143   iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
144   overrides the other flags
145   using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
146   unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
147 */
148 CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
149 CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
150 
151 /* save image to file */
152 CVAPI(int) cvSaveImage( const char* filename, const CvArr* image );
153 
154 #define CV_CVTIMG_FLIP      1
155 #define CV_CVTIMG_SWAP_RB   2
156 /* utility function: convert one image to another with optional vertical flip */
157 CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
158 
159 /* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
160 CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
161 
162 
163 /****************************************************************************************\
164 *                         Working with Video Files and Cameras                           *
165 \****************************************************************************************/
166 
167 /* "black box" capture structure */
168 typedef struct CvCapture CvCapture;
169 
170 /* start capturing frames from video file */
171 CVAPI(CvCapture*) cvCreateSocketCapture( const char *address, const char* port, int width, int height );
172 
173 /* grab a frame, return 1 on success, 0 on fail.
174   this function is thought to be fast               */
175 CVAPI(int) cvGrabFrame( CvCapture* capture );
176 
177 /* get the frame grabbed with cvGrabFrame(..)
178   This function may apply some frame processing like
179   frame decompression, flipping etc.
180   !!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
181 CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture );
182 
183 /* Just a combination of cvGrabFrame and cvRetrieveFrame
184    !!!DO NOT RELEASE or MODIFY the retrieved frame!!!      */
185 CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
186 
187 /* stop capturing/reading and free resources */
188 CVAPI(void) cvReleaseCapture( CvCapture** capture );
189 
190 #define CV_CAP_PROP_POS_MSEC       0
191 #define CV_CAP_PROP_POS_FRAMES     1
192 #define CV_CAP_PROP_POS_AVI_RATIO  2
193 #define CV_CAP_PROP_FRAME_WIDTH    3
194 #define CV_CAP_PROP_FRAME_HEIGHT   4
195 #define CV_CAP_PROP_FPS            5
196 #define CV_CAP_PROP_FOURCC         6
197 #define CV_CAP_PROP_FRAME_COUNT    7
198 #define CV_CAP_PROP_FORMAT         8
199 #define CV_CAP_PROP_MODE           9
200 #define CV_CAP_PROP_BRIGHTNESS    10
201 #define CV_CAP_PROP_CONTRAST      11
202 #define CV_CAP_PROP_SATURATION    12
203 #define CV_CAP_PROP_HUE           13
204 #define CV_CAP_PROP_GAIN          14
205 #define CV_CAP_PROP_CONVERT_RGB   15
206 
207 
208 /* retrieve or set capture properties */
209 CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
210 CVAPI(int)    cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
211 
212 /****************************************************************************************\
213 *                              Obsolete functions/synonyms                               *
214 \****************************************************************************************/
215 
216 #ifndef HIGHGUI_NO_BACKWARD_COMPATIBILITY
217     #define HIGHGUI_BACKWARD_COMPATIBILITY
218 #endif
219 
220 #ifdef HIGHGUI_BACKWARD_COMPATIBILITY
221 
222 #define cvCaptureFromFile cvCreateFileCapture
223 #define cvCaptureFromCAM cvCreateCameraCapture
224 #define cvCaptureFromAVI cvCaptureFromFile
225 #define cvCreateAVIWriter cvCreateVideoWriter
226 #define cvWriteToAVI cvWriteFrame
227 #define cvAddSearchPath(path)
228 #define cvvInitSystem cvInitSystem
229 #define cvvNamedWindow cvNamedWindow
230 #define cvvResizeWindow cvResizeWindow
231 #define cvvDestroyWindow cvDestroyWindow
232 #define cvvCreateTrackbar cvCreateTrackbar
233 #define cvvLoadImage(name) cvLoadImage((name),1)
234 #define cvvSaveImage cvSaveImage
235 #define cvvAddSearchPath cvAddSearchPath
236 #define cvvWaitKey(name) cvWaitKey(0)
237 #define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
238 #define cvvConvertImage cvConvertImage
239 #define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
240 #define set_preprocess_func cvSetPreprocessFuncWin32
241 #define set_postprocess_func cvSetPostprocessFuncWin32
242 
243 #ifdef WIN32
244 
245 typedef int (CV_CDECL * CvWin32WindowCallback)(HWND, UINT, WPARAM, LPARAM, int*);
246 CVAPI(void) cvSetPreprocessFuncWin32( CvWin32WindowCallback on_preprocess );
247 CVAPI(void) cvSetPostprocessFuncWin32( CvWin32WindowCallback on_postprocess );
248 
249 CV_INLINE int iplWidth( const IplImage* img );
250 CV_INLINE int iplWidth( const IplImage* img )
251 {
252     return !img ? 0 : !img->roi ? img->width : img->roi->width;
253 }
254 
255 CV_INLINE int iplHeight( const IplImage* img );
256 CV_INLINE int iplHeight( const IplImage* img )
257 {
258     return !img ? 0 : !img->roi ? img->height : img->roi->height;
259 }
260 
261 #endif
262 
263 #endif /* obsolete functions */
264 
265 /* For use with Win32 */
266 #ifdef WIN32
267 
268 CV_INLINE RECT NormalizeRect( RECT r );
269 CV_INLINE RECT NormalizeRect( RECT r )
270 {
271     int t;
272 
273     if( r.left > r.right )
274     {
275         t = r.left;
276         r.left = r.right;
277         r.right = t;
278     }
279 
280     if( r.top > r.bottom )
281     {
282         t = r.top;
283         r.top = r.bottom;
284         r.bottom = t;
285     }
286 
287     return r;
288 }
289 
290 CV_INLINE CvRect RectToCvRect( RECT sr );
291 CV_INLINE CvRect RectToCvRect( RECT sr )
292 {
293     sr = NormalizeRect( sr );
294     return cvRect( sr.left, sr.top, sr.right - sr.left, sr.bottom - sr.top );
295 }
296 
297 CV_INLINE RECT CvRectToRect( CvRect sr );
298 CV_INLINE RECT CvRectToRect( CvRect sr )
299 {
300     RECT dr;
301     dr.left = sr.x;
302     dr.top = sr.y;
303     dr.right = sr.x + sr.width;
304     dr.bottom = sr.y + sr.height;
305 
306     return dr;
307 }
308 
309 CV_INLINE IplROI RectToROI( RECT r );
310 CV_INLINE IplROI RectToROI( RECT r )
311 {
312     IplROI roi;
313     r = NormalizeRect( r );
314     roi.xOffset = r.left;
315     roi.yOffset = r.top;
316     roi.width = r.right - r.left;
317     roi.height = r.bottom - r.top;
318     roi.coi = 0;
319 
320     return roi;
321 }
322 
323 #endif /* WIN32 */
324 
325 #ifdef __cplusplus
326 }  /* end of extern "C" */
327 #endif /* __cplusplus */
328 
329 
330 #if defined __cplusplus && (!defined WIN32 || !defined (__GNUC__)) && !defined CV_NO_CVV_IMAGE
331 
332 #define CImage CvvImage
333 
334 /* CvvImage class definition */
335 class CV_EXPORTS CvvImage
336 {
337 public:
338     CvvImage();
339     virtual ~CvvImage();
340 
341     /* Create image (BGR or grayscale) */
342     virtual bool  Create( int width, int height, int bits_per_pixel, int image_origin = 0 );
343 
344     /* Load image from specified file */
345     virtual bool  Load( const char* filename, int desired_color = 1 );
346 
347     /* Load rectangle from the file */
348     virtual bool  LoadRect( const char* filename,
349                             int desired_color, CvRect r );
350 
351 #ifdef WIN32
LoadRect(const char * filename,int desired_color,RECT r)352     virtual bool  LoadRect( const char* filename,
353                             int desired_color, RECT r )
354     {
355         return LoadRect( filename, desired_color,
356                          cvRect( r.left, r.top, r.right - r.left, r.bottom - r.top ));
357     }
358 #endif
359 
360     /* Save entire image to specified file. */
361     virtual bool  Save( const char* filename );
362 
363     /* Get copy of input image ROI */
364     virtual void  CopyOf( CvvImage& image, int desired_color = -1 );
365     virtual void  CopyOf( IplImage* img, int desired_color = -1 );
366 
GetImage()367     IplImage* GetImage() { return m_img; };
368     virtual void  Destroy(void);
369 
370     /* width and height of ROI */
Width()371     int Width() { return !m_img ? 0 : !m_img->roi ? m_img->width : m_img->roi->width; };
Height()372     int Height() { return !m_img ? 0 : !m_img->roi ? m_img->height : m_img->roi->height;};
Bpp()373     int Bpp() { return m_img ? (m_img->depth & 255)*m_img->nChannels : 0; };
374 
375     virtual void  Fill( int color );
376 
377 
378 protected:
379 
380     IplImage*  m_img;
381 };
382 
383 #endif /* __cplusplus */
384 
385 #endif /* _HIGH_GUI_ */
386