include/opencv2/highgui/highgui.hpp
Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Third party copyrights are property of their respective owners.
00016 //
00017 // Redistribution and use in source and binary forms, with or without modification,
00018 // are permitted provided that the following conditions are met:
00019 //
00020 //   * Redistribution's of source code must retain the above copyright notice,
00021 //     this list of conditions and the following disclaimer.
00022 //
00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
00024 //     this list of conditions and the following disclaimer in the documentation
00025 //     and/or other materials provided with the distribution.
00026 //
00027 //   * The name of the copyright holders may not be used to endorse or promote products
00028 //     derived from this software without specific prior written permission.
00029 //
00030 // This software is provided by the copyright holders and contributors "as is" and
00031 // any express or implied warranties, including, but not limited to, the implied
00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
00034 // indirect, incidental, special, exemplary, or consequential damages
00035 // (including, but not limited to, procurement of substitute goods or services;
00036 // loss of use, data, or profits; or business interruption) however caused
00037 // and on any theory of liability, whether in contract, strict liability,
00038 // or tort (including negligence or otherwise) arising in any way out of
00039 // the use of this software, even if advised of the possibility of such damage.
00040 //
00041 //M*/
00042 
00043 #ifndef __OPENCV_HIGHGUI_HPP__
00044 #define __OPENCV_HIGHGUI_HPP__
00045 
00046 #include "opencv2/core/core.hpp"
00047 #include "opencv2/highgui/highgui_c.h"
00048 
00049 #ifdef __cplusplus
00050 
00051 struct CvCapture;
00052 struct CvVideoWriter;
00053 
00054 namespace cv
00055 {
00056 
00057 enum {
00058     // Flags for namedWindow
00059     WINDOW_NORMAL   = CV_WINDOW_NORMAL,   // the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size
00060     WINDOW_AUTOSIZE = CV_WINDOW_AUTOSIZE, // the user cannot resize the window, the size is constrainted by the image displayed
00061     WINDOW_OPENGL   = CV_WINDOW_OPENGL,   // window with opengl support
00062 
00063     // Flags for set / getWindowProperty
00064     WND_PROP_FULLSCREEN   = CV_WND_PROP_FULLSCREEN,  // fullscreen property
00065     WND_PROP_AUTOSIZE     = CV_WND_PROP_AUTOSIZE,    // autosize property
00066     WND_PROP_ASPECT_RATIO = CV_WND_PROP_ASPECTRATIO, // window's aspect ration
00067     WND_PROP_OPENGL       = CV_WND_PROP_OPENGL       // opengl support
00068 };
00069 
00070 CV_EXPORTS_W void namedWindow(const string& winname, int flags = WINDOW_AUTOSIZE);
00071 CV_EXPORTS_W void destroyWindow(const string& winname);
00072 CV_EXPORTS_W void destroyAllWindows();
00073 
00074 CV_EXPORTS_W int startWindowThread();
00075 
00076 CV_EXPORTS_W int waitKey(int delay = 0);
00077 
00078 CV_EXPORTS_W void imshow(const string& winname, InputArray mat);
00079 
00080 CV_EXPORTS_W void resizeWindow(const string& winname, int width, int height);
00081 CV_EXPORTS_W void moveWindow(const string& winname, int x, int y);
00082 
00083 CV_EXPORTS_W void setWindowProperty(const string& winname, int prop_id, double prop_value);//YV
00084 CV_EXPORTS_W double getWindowProperty(const string& winname, int prop_id);//YV
00085 
00086 enum
00087 {
00088     EVENT_MOUSEMOVE      =0,
00089     EVENT_LBUTTONDOWN    =1,
00090     EVENT_RBUTTONDOWN    =2,
00091     EVENT_MBUTTONDOWN    =3,
00092     EVENT_LBUTTONUP      =4,
00093     EVENT_RBUTTONUP      =5,
00094     EVENT_MBUTTONUP      =6,
00095     EVENT_LBUTTONDBLCLK  =7,
00096     EVENT_RBUTTONDBLCLK  =8,
00097     EVENT_MBUTTONDBLCLK  =9
00098 };
00099 
00100 enum
00101 {
00102     EVENT_FLAG_LBUTTON   =1,
00103     EVENT_FLAG_RBUTTON   =2,
00104     EVENT_FLAG_MBUTTON   =4,
00105     EVENT_FLAG_CTRLKEY   =8,
00106     EVENT_FLAG_SHIFTKEY  =16,
00107     EVENT_FLAG_ALTKEY    =32
00108 };
00109 
00110 typedef void (*MouseCallback)(int event, int x, int y, int flags, void* userdata);
00111 
00113 CV_EXPORTS void setMouseCallback(const string& winname, MouseCallback onMouse, void* userdata = 0);
00114 
00115 
00116 typedef void (CV_CDECL *TrackbarCallback)(int pos, void* userdata);
00117 
00118 CV_EXPORTS int createTrackbar(const string& trackbarname, const string& winname,
00119                               int* value, int count,
00120                               TrackbarCallback onChange = 0,
00121                               void* userdata = 0);
00122 
00123 CV_EXPORTS_W int getTrackbarPos(const string& trackbarname, const string& winname);
00124 CV_EXPORTS_W void setTrackbarPos(const string& trackbarname, const string& winname, int pos);
00125 
00126 // OpenGL support
00127 
00128 typedef void (*OpenGlDrawCallback)(void* userdata);
00129 CV_EXPORTS void setOpenGlDrawCallback(const string& winname, OpenGlDrawCallback onOpenGlDraw, void* userdata = 0);
00130 
00131 CV_EXPORTS void setOpenGlContext(const string& winname);
00132 
00133 CV_EXPORTS void updateWindow(const string& winname);
00134 
00135 CV_EXPORTS void pointCloudShow(const string& winname, const GlCamera& camera, const GlArrays& arr);
00136 CV_EXPORTS void pointCloudShow(const string& winname, const GlCamera& camera, InputArray points, InputArray colors = noArray());
00137 
00138 //Only for Qt
00139 
00140 CV_EXPORTS CvFont fontQt(const string& nameFont, int pointSize=-1,
00141                          Scalar color=Scalar::all(0), int weight=CV_FONT_NORMAL,
00142                          int style=CV_STYLE_NORMAL, int spacing=0);
00143 CV_EXPORTS void addText( const Mat& img, const string& text, Point org, CvFont font);
00144 
00145 CV_EXPORTS void displayOverlay(const string& winname, const string& text, int delayms CV_DEFAULT(0));
00146 CV_EXPORTS void displayStatusBar(const string& winname, const string& text, int delayms CV_DEFAULT(0));
00147 
00148 CV_EXPORTS void saveWindowParameters(const string& windowName);
00149 CV_EXPORTS void loadWindowParameters(const string& windowName);
00150 CV_EXPORTS  int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]);
00151 CV_EXPORTS  void stopLoop();
00152 
00153 typedef void (CV_CDECL *ButtonCallback)(int state, void* userdata);
00154 CV_EXPORTS int createButton( const string& bar_name, ButtonCallback on_change,
00155                              void* userdata=NULL, int type=CV_PUSH_BUTTON,
00156                              bool initial_button_state=0);
00157 
00158 //-------------------------
00159 
00160 enum
00161 {
00162     // 8bit, color or not
00163     IMREAD_UNCHANGED  =-1,
00164     // 8bit, gray
00165     IMREAD_GRAYSCALE  =0,
00166     // ?, color
00167     IMREAD_COLOR      =1,
00168     // any depth, ?
00169     IMREAD_ANYDEPTH   =2,
00170     // ?, any color
00171     IMREAD_ANYCOLOR   =4
00172 };
00173 
00174 enum
00175 {
00176     IMWRITE_JPEG_QUALITY =1,
00177     IMWRITE_PNG_COMPRESSION =16,
00178     IMWRITE_PNG_STRATEGY =17,
00179     IMWRITE_PNG_BILEVEL =18,
00180     IMWRITE_PNG_STRATEGY_DEFAULT =0,
00181     IMWRITE_PNG_STRATEGY_FILTERED =1,
00182     IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
00183     IMWRITE_PNG_STRATEGY_RLE =3,
00184     IMWRITE_PNG_STRATEGY_FIXED =4,
00185     IMWRITE_PXM_BINARY =32
00186 };
00187 
00188 CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
00189 CV_EXPORTS_W bool imwrite( const string& filename, InputArray img,
00190               const vector<int>& params=vector<int>());
00191 CV_EXPORTS_W Mat imdecode( InputArray buf, int flags );
00192 CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst );
00193 CV_EXPORTS_W bool imencode( const string& ext, InputArray img,
00194                             CV_OUT vector<uchar>& buf,
00195                             const vector<int>& params=vector<int>());
00196 
00197 #ifndef CV_NO_VIDEO_CAPTURE_CPP_API
00198 
00199 template<> void CV_EXPORTS Ptr<CvCapture>::delete_obj();
00200 template<> void CV_EXPORTS Ptr<CvVideoWriter>::delete_obj();
00201 
00202 class CV_EXPORTS_W VideoCapture
00203 {
00204 public:
00205     CV_WRAP VideoCapture();
00206     CV_WRAP VideoCapture(const string& filename);
00207     CV_WRAP VideoCapture(int device);
00208 
00209     virtual ~VideoCapture();
00210     CV_WRAP virtual bool open(const string& filename);
00211     CV_WRAP virtual bool open(int device);
00212     CV_WRAP virtual bool isOpened() const;
00213     CV_WRAP virtual void release();
00214 
00215     CV_WRAP virtual bool grab();
00216     CV_WRAP virtual bool retrieve(CV_OUT Mat& image, int channel=0);
00217     virtual VideoCapture& operator >> (CV_OUT Mat& image);
00218     CV_WRAP virtual bool read(CV_OUT Mat& image);
00219 
00220     CV_WRAP virtual bool set(int propId, double value);
00221     CV_WRAP virtual double get(int propId);
00222 
00223 protected:
00224     Ptr<CvCapture> cap;
00225 };
00226 
00227 
00228 class CV_EXPORTS_W VideoWriter
00229 {
00230 public:
00231     CV_WRAP VideoWriter();
00232     CV_WRAP VideoWriter(const string& filename, int fourcc, double fps,
00233                 Size frameSize, bool isColor=true);
00234 
00235     virtual ~VideoWriter();
00236     CV_WRAP virtual bool open(const string& filename, int fourcc, double fps,
00237                       Size frameSize, bool isColor=true);
00238     CV_WRAP virtual bool isOpened() const;
00239     CV_WRAP virtual void release();
00240     virtual VideoWriter& operator << (const Mat& image);
00241     CV_WRAP virtual void write(const Mat& image);
00242 
00243 protected:
00244     Ptr<CvVideoWriter> writer;
00245 };
00246 
00247 #endif
00248 
00249 }
00250 
00251 #endif
00252 
00253 #endif