Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpDisplayOpenCV.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Image display.
32  *
33  * Authors:
34  * Christophe Collewet
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
39 #ifndef vpDisplayOpenCV_h
40 #define vpDisplayOpenCV_h
41 
42 #include <visp3/core/vpConfig.h>
43 #if defined(VISP_HAVE_OPENCV)
44 
45 #include <visp3/core/vpDisplay.h>
46 #include <visp3/core/vpImage.h>
47 #include <visp3/core/vpImageConvert.h>
48 
49 #if VISP_HAVE_OPENCV_VERSION >= 0x020101
50 # include <opencv2/core/core.hpp>
51 # include <opencv2/highgui/highgui.hpp>
52 #else
53 # include <cv.h>
54 # include <highgui.h>
55 # include <cxcore.h>
56 #endif
57 
142 class VISP_EXPORT vpDisplayOpenCV: public vpDisplay
143 {
144 private:
145 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
146  IplImage* m_background;
148  CvScalar *col ;
149  CvScalar cvcolor;
150  CvFont *font;
151 #else
152  cv::Mat m_background;
153  cv::Scalar *col ;
154  cv::Scalar cvcolor;
155  int font;
156  float fontScale;
157 #endif
158  static std::vector<std::string> m_listTitles;
159  static unsigned int m_nbWindows ;
160  int fontHeight;
161  int x_move;
162  int y_move;
163  bool move;
164  int x_lbuttondown ;
165  int y_lbuttondown ;
166  bool lbuttondown;
167  int x_mbuttondown ;
168  int y_mbuttondown ;
169  bool mbuttondown;
170  int x_rbuttondown ;
171  int y_rbuttondown ;
172  bool rbuttondown;
173  int x_lbuttonup ;
174  int y_lbuttonup ;
175  bool lbuttonup;
176  int x_mbuttonup ;
177  int y_mbuttonup ;
178  bool mbuttonup;
179  int x_rbuttonup ;
180  int y_rbuttonup ;
181  bool rbuttonup;
182 
183 //private:
184 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
185 // vpDisplayOpenCV(const vpDisplayOpenCV &)
186 // : vpDisplay(),
187 // #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
188 // background(NULL), col(NULL), cvcolor(), font(NULL),
189 // #else
190 // background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
191 // #endif
192 // fontHeight(10), x_move(0), y_move(0) , move(false),
193 // x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
194 // x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
195 // x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
196 // x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
197 // x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
198 // x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
199 // {
200 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
201 // }
202 // vpDisplayOpenCV &operator=(const vpDisplayOpenCV &){
203 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
204 // return *this;
205 // }
206 //#endif
207 
208 public:
209  vpDisplayOpenCV() ;
210  vpDisplayOpenCV(int winx, int winy, const std::string &title="") ;
212  vpDisplayOpenCV(vpImage<unsigned char> &I, int winx=-1, int winy=-1, const std::string &title="", vpScaleType type=SCALE_DEFAULT) ;
214  vpDisplayOpenCV(vpImage<vpRGBa> &I, int winx=-1, int winy=-1, const std::string &title="", vpScaleType type=SCALE_DEFAULT) ;
215 
216  virtual ~vpDisplayOpenCV() ;
217 
218  void getImage(vpImage<vpRGBa> &I);
219  unsigned int getScreenHeight();
220  void getScreenSize(unsigned int &width, unsigned int &height);
221  unsigned int getScreenWidth();
222 
223  void init(vpImage<unsigned char> &I, int winx=-1, int winy=-1, const std::string &title="") ;
224  void init(vpImage<vpRGBa> &I, int winx=-1, int winy=-1, const std::string &title="") ;
225  void init(unsigned int width, unsigned int height, int winx=-1, int winy=-1, const std::string &title="") ;
226 
227 protected:
228  void setFont( const std::string &font );
229  void setTitle(const std::string &title) ;
230  void setWindowPosition(int winx, int winy);
231 
232  void clearDisplay(const vpColor &color=vpColor::white) ;
233 
234  void closeDisplay() ;
235 
236  void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4,unsigned int h=2, unsigned int thickness=1) ;
237 
238  void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green) ;
239 
240  void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false, unsigned int thickness=1);
241  void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1) ;
242  void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1) ;
243 
244  void displayImage(const vpImage<unsigned char> &I) ;
245  void displayImage(const vpImage<vpRGBa> &I) ;
246  void displayImage(const unsigned char *I) ;
247 
248  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
249  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
250 
251  void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1) ;
252  void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1) ;
253 
254  void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill = false, unsigned int thickness=1) ;
255  void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color, bool fill = false, unsigned int thickness=1) ;
256  void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness=1) ;
257 
258  void flushDisplay() ;
259  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
260 
261  bool getClick(bool blocking=true) ;
262  bool getClick(vpImagePoint &ip, bool blocking=true) ;
263  bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType& button, bool blocking=true) ;
264  bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType& button, bool blocking=true) ;
265 
266  bool getKeyboardEvent(bool blocking=true);
267  bool getKeyboardEvent(std::string &key, bool blocking=true);
269  bool getPointerPosition (vpImagePoint &ip);
270 
271  static void on_mouse( int event, int x, int y, int flags, void* param );
272 } ;
273 
274 #endif
275 #endif
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:169
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static bool getPointerMotionEvent(const vpImage< unsigned char > &I, vpImagePoint &ip)
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static const vpColor green
Definition: vpColor.h:166
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:155
static void displayCircle(const vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
vpScaleType
Values that could be applied to a display to down scale the size of the display.
Definition: vpDisplay.h:173
Defines a rectangle in the plane.
Definition: vpRect.h:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCharString(const vpImage< unsigned char > &I, const vpImagePoint &ip, const char *string, const vpColor &color)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static const vpColor white
Definition: vpColor.h:158
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)