updated OpenGL functionality:
[profile/ivi/opencv.git] / modules / highgui / include / opencv2 / highgui / highgui.hpp
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 //                          License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42
43 #ifndef __OPENCV_HIGHGUI_HPP__
44 #define __OPENCV_HIGHGUI_HPP__
45
46 #include "opencv2/core/core.hpp"
47 #include "opencv2/highgui/highgui_c.h"
48
49 #ifdef __cplusplus
50
51 struct CvCapture;
52 struct CvVideoWriter;
53
54 namespace cv
55 {
56
57 enum {
58     // Flags for namedWindow
59     WINDOW_NORMAL   = CV_WINDOW_NORMAL,   // the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size
60     WINDOW_AUTOSIZE = CV_WINDOW_AUTOSIZE, // the user cannot resize the window, the size is constrainted by the image displayed
61     WINDOW_OPENGL   = CV_WINDOW_OPENGL,   // window with opengl support
62
63     // Flags for set / getWindowProperty
64     WND_PROP_FULLSCREEN   = CV_WND_PROP_FULLSCREEN,  // fullscreen property
65     WND_PROP_AUTOSIZE     = CV_WND_PROP_AUTOSIZE,    // autosize property
66     WND_PROP_ASPECT_RATIO = CV_WND_PROP_ASPECTRATIO, // window's aspect ration
67     WND_PROP_OPENGL       = CV_WND_PROP_OPENGL       // opengl support
68 };
69
70 CV_EXPORTS_W void namedWindow(const string& winname, int flags = WINDOW_AUTOSIZE);
71 CV_EXPORTS_W void destroyWindow(const string& winname);
72 CV_EXPORTS_W void destroyAllWindows();
73
74 CV_EXPORTS_W int startWindowThread();
75
76 CV_EXPORTS_W int waitKey(int delay = 0);
77
78 CV_EXPORTS_W void imshow(const string& winname, InputArray mat);
79
80 CV_EXPORTS_W void resizeWindow(const string& winname, int width, int height);
81 CV_EXPORTS_W void moveWindow(const string& winname, int x, int y);
82
83 CV_EXPORTS_W void setWindowProperty(const string& winname, int prop_id, double prop_value);//YV
84 CV_EXPORTS_W double getWindowProperty(const string& winname, int prop_id);//YV
85
86 enum
87 {
88     EVENT_MOUSEMOVE      =0,
89     EVENT_LBUTTONDOWN    =1,
90     EVENT_RBUTTONDOWN    =2,
91     EVENT_MBUTTONDOWN    =3,
92     EVENT_LBUTTONUP      =4,
93     EVENT_RBUTTONUP      =5,
94     EVENT_MBUTTONUP      =6,
95     EVENT_LBUTTONDBLCLK  =7,
96     EVENT_RBUTTONDBLCLK  =8,
97     EVENT_MBUTTONDBLCLK  =9
98 };
99
100 enum
101 {
102     EVENT_FLAG_LBUTTON   =1,
103     EVENT_FLAG_RBUTTON   =2,
104     EVENT_FLAG_MBUTTON   =4,
105     EVENT_FLAG_CTRLKEY   =8,
106     EVENT_FLAG_SHIFTKEY  =16,
107     EVENT_FLAG_ALTKEY    =32
108 };
109
110 typedef void (*MouseCallback)(int event, int x, int y, int flags, void* userdata);
111
112 //! assigns callback for mouse events
113 CV_EXPORTS void setMouseCallback(const string& winname, MouseCallback onMouse, void* userdata = 0);
114
115
116 typedef void (CV_CDECL *TrackbarCallback)(int pos, void* userdata);
117
118 CV_EXPORTS int createTrackbar(const string& trackbarname, const string& winname,
119                               int* value, int count,
120                               TrackbarCallback onChange = 0,
121                               void* userdata = 0);
122
123 CV_EXPORTS_W int getTrackbarPos(const string& trackbarname, const string& winname);
124 CV_EXPORTS_W void setTrackbarPos(const string& trackbarname, const string& winname, int pos);
125
126 // OpenGL support
127
128 typedef void (CV_CDECL *OpenGlDrawCallback)(void* userdata);
129 CV_EXPORTS void setOpenGlDrawCallback(const string& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0);
130
131 CV_EXPORTS void setOpenGlContext(const string& winname);
132
133 CV_EXPORTS void updateWindow(const string& winname);
134
135 //Only for Qt
136
137 CV_EXPORTS CvFont fontQt(const string& nameFont, int pointSize=-1,
138                          Scalar color=Scalar::all(0), int weight=CV_FONT_NORMAL,
139                          int style=CV_STYLE_NORMAL, int spacing=0);
140 CV_EXPORTS void addText( const Mat& img, const string& text, Point org, CvFont font);
141
142 CV_EXPORTS void displayOverlay(const string& winname, const string& text, int delayms CV_DEFAULT(0));
143 CV_EXPORTS void displayStatusBar(const string& winname, const string& text, int delayms CV_DEFAULT(0));
144
145 CV_EXPORTS void saveWindowParameters(const string& windowName);
146 CV_EXPORTS void loadWindowParameters(const string& windowName);
147 CV_EXPORTS  int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
148 CV_EXPORTS  void stopLoop();
149
150 typedef void (CV_CDECL *ButtonCallback)(int state, void* userdata);
151 CV_EXPORTS int createButton( const string& bar_name, ButtonCallback on_change,
152                              void* userdata=NULL, int type=CV_PUSH_BUTTON,
153                              bool initial_button_state=0);
154
155 //-------------------------
156
157 enum
158 {
159     // 8bit, color or not
160     IMREAD_UNCHANGED  =-1,
161     // 8bit, gray
162     IMREAD_GRAYSCALE  =0,
163     // ?, color
164     IMREAD_COLOR      =1,
165     // any depth, ?
166     IMREAD_ANYDEPTH   =2,
167     // ?, any color
168     IMREAD_ANYCOLOR   =4
169 };
170
171 enum
172 {
173     IMWRITE_JPEG_QUALITY =1,
174     IMWRITE_PNG_COMPRESSION =16,
175     IMWRITE_PNG_STRATEGY =17,
176     IMWRITE_PNG_BILEVEL =18,
177     IMWRITE_PNG_STRATEGY_DEFAULT =0,
178     IMWRITE_PNG_STRATEGY_FILTERED =1,
179     IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
180     IMWRITE_PNG_STRATEGY_RLE =3,
181     IMWRITE_PNG_STRATEGY_FIXED =4,
182     IMWRITE_PXM_BINARY =32
183 };
184
185 CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
186 CV_EXPORTS_W bool imwrite( const string& filename, InputArray img,
187               const vector<int>& params=vector<int>());
188 CV_EXPORTS_W Mat imdecode( InputArray buf, int flags );
189 CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst );
190 CV_EXPORTS_W bool imencode( const string& ext, InputArray img,
191                             CV_OUT vector<uchar>& buf,
192                             const vector<int>& params=vector<int>());
193
194 #ifndef CV_NO_VIDEO_CAPTURE_CPP_API
195
196 template<> void CV_EXPORTS Ptr<CvCapture>::delete_obj();
197 template<> void CV_EXPORTS Ptr<CvVideoWriter>::delete_obj();
198
199 class CV_EXPORTS_W VideoCapture
200 {
201 public:
202     CV_WRAP VideoCapture();
203     CV_WRAP VideoCapture(const string& filename);
204     CV_WRAP VideoCapture(int device);
205
206     virtual ~VideoCapture();
207     CV_WRAP virtual bool open(const string& filename);
208     CV_WRAP virtual bool open(int device);
209     CV_WRAP virtual bool isOpened() const;
210     CV_WRAP virtual void release();
211
212     CV_WRAP virtual bool grab();
213     CV_WRAP virtual bool retrieve(CV_OUT Mat& image, int channel=0);
214     virtual VideoCapture& operator >> (CV_OUT Mat& image);
215     CV_WRAP virtual bool read(CV_OUT Mat& image);
216
217     CV_WRAP virtual bool set(int propId, double value);
218     CV_WRAP virtual double get(int propId);
219
220 protected:
221     Ptr<CvCapture> cap;
222 };
223
224
225 class CV_EXPORTS_W VideoWriter
226 {
227 public:
228     CV_WRAP VideoWriter();
229     CV_WRAP VideoWriter(const string& filename, int fourcc, double fps,
230                 Size frameSize, bool isColor=true);
231
232     virtual ~VideoWriter();
233     CV_WRAP virtual bool open(const string& filename, int fourcc, double fps,
234                       Size frameSize, bool isColor=true);
235     CV_WRAP virtual bool isOpened() const;
236     CV_WRAP virtual void release();
237     virtual VideoWriter& operator << (const Mat& image);
238     CV_WRAP virtual void write(const Mat& image);
239
240 protected:
241     Ptr<CvVideoWriter> writer;
242 };
243
244 #endif
245
246 }
247
248 #endif
249
250 #endif