Visual Servoing Platform  version 3.0.0
vpDisplayOpenCV.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
140 class VISP_EXPORT vpDisplayOpenCV: public vpDisplay
141 {
142 private:
143 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
144  IplImage* background;
146  CvScalar *col ;
147  CvScalar cvcolor;
148  CvFont *font;
149 #else
150  cv::Mat background;
151  cv::Scalar *col ;
152  cv::Scalar cvcolor;
153  int font;
154  float fontScale;
155 #endif
156  static std::vector<std::string> m_listTitles;
157  static unsigned int m_nbWindows ;
158  int fontHeight;
159  int x_move;
160  int y_move;
161  bool move;
162  int x_lbuttondown ;
163  int y_lbuttondown ;
164  bool lbuttondown;
165  int x_mbuttondown ;
166  int y_mbuttondown ;
167  bool mbuttondown;
168  int x_rbuttondown ;
169  int y_rbuttondown ;
170  bool rbuttondown;
171  int x_lbuttonup ;
172  int y_lbuttonup ;
173  bool lbuttonup;
174  int x_mbuttonup ;
175  int y_mbuttonup ;
176  bool mbuttonup;
177  int x_rbuttonup ;
178  int y_rbuttonup ;
179  bool rbuttonup;
180 
181 //private:
182 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
183 // vpDisplayOpenCV(const vpDisplayOpenCV &)
184 // : vpDisplay(),
185 // #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
186 // background(NULL), col(NULL), cvcolor(), font(NULL),
187 // #else
188 // background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
189 // #endif
190 // fontHeight(10), x_move(0), y_move(0) , move(false),
191 // x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
192 // x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
193 // x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
194 // x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
195 // x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
196 // x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
197 // {
198 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
199 // }
200 // vpDisplayOpenCV &operator=(const vpDisplayOpenCV &){
201 // throw vpException(vpException::functionNotImplementedError, "Not implemented!");
202 // return *this;
203 // }
204 //#endif
205 
206 public:
207  vpDisplayOpenCV() ;
208  vpDisplayOpenCV(int winx, int winy, const char *title=NULL) ;
209  vpDisplayOpenCV(vpImage<unsigned char> &I, int winx=-1, int winy=-1,
210  const char *title=NULL) ;
211  vpDisplayOpenCV(vpImage<vpRGBa> &I, int winx=-1, int winy=-1,
212  const char *title=NULL) ;
213 
214  virtual ~vpDisplayOpenCV() ;
215 
217  int winx=-1, int winy=-1,
218  const char *title=NULL) ;
219  void init(vpImage<vpRGBa> &I,
220  int winx=-1, int winy=-1,
221  const char *title=NULL) ;
222 
223  void init(unsigned int width, unsigned int height,
224  int winx=-1, int winy=-1 ,
225  const char *title=NULL) ;
226  void getImage(vpImage<vpRGBa> &I) ;
227 
228 protected:
229  void setFont( const char *font );
230  void setTitle(const char *title) ;
231  void setWindowPosition(int winx, int winy);
232 
233  void clearDisplay(const vpColor &color=vpColor::white) ;
234 
235  void closeDisplay() ;
236 
237  void displayArrow(const vpImagePoint &ip1,
238  const vpImagePoint &ip2,
239  const vpColor &color=vpColor::white,
240  unsigned int w=4,unsigned int h=2,
241  unsigned int thickness=1) ;
242 
243  void displayCharString(const vpImagePoint &ip, const char *text,
244  const vpColor &color=vpColor::green) ;
245 
246  void displayCircle(const vpImagePoint &center, unsigned int radius,
247  const vpColor &color,
248  bool fill = false,
249  unsigned int thickness=1);
250  void displayCross(const vpImagePoint &ip, unsigned int size,
251  const vpColor &color, unsigned int thickness=1) ;
252  void displayDotLine(const vpImagePoint &ip1,
253  const vpImagePoint &ip2,
254  const vpColor &color, unsigned int thickness=1) ;
255 
256  void displayImage(const vpImage<vpRGBa> &I) ;
257  void displayImage(const vpImage<unsigned char> &I) ;
258  void displayImage(const unsigned char *I) ;
259 
260  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
261  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
262 
263  void displayLine(const vpImagePoint &ip1,
264  const vpImagePoint &ip2,
265  const vpColor &color, unsigned int thickness=1) ;
266  void displayPoint(const vpImagePoint &ip, const vpColor &color) ;
267 
268  void displayRectangle(const vpImagePoint &topLeft,
269  unsigned int width, unsigned int height,
270  const vpColor &color, bool fill = false,
271  unsigned int thickness=1) ;
272  void displayRectangle(const vpImagePoint &topLeft,
273  const vpImagePoint &bottomRight,
274  const vpColor &color, bool fill = false,
275  unsigned int thickness=1) ;
276  void displayRectangle(const vpRect &rectangle,
277  const vpColor &color, bool fill = false,
278  unsigned int thickness=1) ;
279 
280  void flushDisplay() ;
281  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
282 
283  bool getClick(bool blocking=true) ;
284  bool getClick(vpImagePoint &ip, bool blocking=true) ;
285  bool getClick(vpImagePoint &ip,
287  bool blocking=true) ;
288  bool getClickUp(vpImagePoint &ip,
290  bool blocking=true) ;
291 
292  inline unsigned int getWidth() const { return width ; }
293  inline unsigned int getHeight() const { return height ; }
294 
295  bool getKeyboardEvent(bool blocking=true);
296  bool getKeyboardEvent(char *string, bool blocking=true);
298  bool getPointerPosition (vpImagePoint &ip);
299 
300  static void on_mouse( int event, int x, int y, int flags, void* param );
301 } ;
302 
303 #endif
304 #endif
virtual void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
virtual void displayImage(const vpImage< unsigned char > &I)=0
virtual void init(vpImage< unsigned char > &I, int x=-1, int y=-1, const char *title=NULL)=0
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:170
virtual 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)=0
unsigned int getWidth() const
unsigned int width
Definition: vpDisplay.h:179
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
virtual void clearDisplay(const vpColor &color=vpColor::white)=0
virtual bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)=0
virtual bool getPointerMotionEvent(vpImagePoint &ip)=0
static const vpColor green
Definition: vpColor.h:166
virtual void flushDisplay()=0
unsigned int getHeight() const
virtual bool getPointerPosition(vpImagePoint &ip)=0
virtual bool getKeyboardEvent(bool blocking=true)=0
virtual void setWindowPosition(int winx, int winy)=0
unsigned int height
Definition: vpDisplay.h:180
The vpDisplayOpenCV allows to display image using the opencv library.
virtual void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)=0
virtual void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)=0
virtual void setTitle(const char *title)=0
virtual void setFont(const char *font)=0
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
static void getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
Definition: vpDisplay.cpp:324
virtual void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
virtual void closeDisplay()=0
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
Defines a rectangle in the plane.
Definition: vpRect.h:81
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
virtual void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)=0
virtual void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)=0
static const vpColor white
Definition: vpColor.h:158
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0