ViSP  2.10.0
vpDisplayOpenCV.h
1 /****************************************************************************
2  *
3  * $Id: vpDisplayOpenCV.h 5023 2014-12-03 16:07:48Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Image display.
36  *
37  * Authors:
38  * Christophe Collewet
39  * Eric Marchand
40  *
41  *****************************************************************************/
42 
43 #ifndef vpDisplayOpenCV_h
44 #define vpDisplayOpenCV_h
45 
46 #include <visp/vpConfig.h>
47 #if defined(VISP_HAVE_OPENCV)
48 
49 #include <visp/vpDisplay.h>
50 #include <visp/vpImage.h>
51 #include <visp/vpImageConvert.h>
52 
53 #if VISP_HAVE_OPENCV_VERSION >= 0x020101
54 # include <opencv2/core/core.hpp>
55 # include <opencv2/highgui/highgui.hpp>
56 #else
57 # include <cv.h>
58 # include <highgui.h>
59 # include <cxcore.h>
60 #endif
61 
144 class VISP_EXPORT vpDisplayOpenCV: public vpDisplay
145 {
146 private:
147 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
148  IplImage* background;
150  CvScalar *col ;
151  CvScalar cvcolor;
152  CvFont *font;
153 #else
154  cv::Mat background;
155  cv::Scalar *col ;
156  cv::Scalar cvcolor;
157  int font;
158  float fontScale;
159 #endif
160  static std::vector<std::string> m_listTitles;
161  static unsigned int m_nbWindows ;
162  int fontHeight;
163  int ncol, nrow ;
164  int x_move;
165  int y_move;
166  bool move;
167  int x_lbuttondown ;
168  int y_lbuttondown ;
169  bool lbuttondown;
170  int x_mbuttondown ;
171  int y_mbuttondown ;
172  bool mbuttondown;
173  int x_rbuttondown ;
174  int y_rbuttondown ;
175  bool rbuttondown;
176  int x_lbuttonup ;
177  int y_lbuttonup ;
178  bool lbuttonup;
179  int x_mbuttonup ;
180  int y_mbuttonup ;
181  bool mbuttonup;
182  int x_rbuttonup ;
183  int y_rbuttonup ;
184  bool rbuttonup;
185 
186 public:
187  vpDisplayOpenCV() ;
188  vpDisplayOpenCV(int winx, int winy, const char *title=NULL) ;
189  vpDisplayOpenCV(vpImage<unsigned char> &I, int winx=-1, int winy=-1,
190  const char *title=NULL) ;
191  vpDisplayOpenCV(vpImage<vpRGBa> &I, int winx=-1, int winy=-1,
192  const char *title=NULL) ;
193 
194  virtual ~vpDisplayOpenCV() ;
195 
197  int winx=-1, int winy=-1,
198  const char *title=NULL) ;
199  void init(vpImage<vpRGBa> &I,
200  int winx=-1, int winy=-1,
201  const char *title=NULL) ;
202 
203  void init(unsigned int width, unsigned int height,
204  int winx=-1, int winy=-1 ,
205  const char *title=NULL) ;
206  void getImage(vpImage<vpRGBa> &I) ;
207 
208 protected:
209  void setFont( const char *font );
210  void setTitle(const char *title) ;
211  void setWindowPosition(int winx, int winy);
212 
213  void clearDisplay(const vpColor &color=vpColor::white) ;
214 
215  void closeDisplay() ;
216 
217  void displayArrow(const vpImagePoint &ip1,
218  const vpImagePoint &ip2,
219  const vpColor &color=vpColor::white,
220  unsigned int w=4,unsigned int h=2,
221  unsigned int thickness=1) ;
222 
223  void displayCharString(const vpImagePoint &ip, const char *text,
224  const vpColor &color=vpColor::green) ;
225 
226  void displayCircle(const vpImagePoint &center, unsigned int radius,
227  const vpColor &color,
228  bool fill = false,
229  unsigned int thickness=1);
230  void displayCross(const vpImagePoint &ip, unsigned int size,
231  const vpColor &color, unsigned int thickness=1) ;
232  void displayDotLine(const vpImagePoint &ip1,
233  const vpImagePoint &ip2,
234  const vpColor &color, unsigned int thickness=1) ;
235 
236  void displayImage(const vpImage<vpRGBa> &I) ;
237  void displayImage(const vpImage<unsigned char> &I) ;
238  void displayImage(const unsigned char *I) ;
239 
240  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
241  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
242 
243  void displayLine(const vpImagePoint &ip1,
244  const vpImagePoint &ip2,
245  const vpColor &color, unsigned int thickness=1) ;
246  void displayPoint(const vpImagePoint &ip, const vpColor &color) ;
247 
248  void displayRectangle(const vpImagePoint &topLeft,
249  unsigned int width, unsigned int height,
250  const vpColor &color, bool fill = false,
251  unsigned int thickness=1) ;
252  void displayRectangle(const vpImagePoint &topLeft,
253  const vpImagePoint &bottomRight,
254  const vpColor &color, bool fill = false,
255  unsigned int thickness=1) ;
256  void displayRectangle(const vpRect &rectangle,
257  const vpColor &color, bool fill = false,
258  unsigned int thickness=1) ;
259 
260  void flushDisplay() ;
261  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
262 
263  bool getClick(bool blocking=true) ;
264  bool getClick(vpImagePoint &ip, bool blocking=true) ;
265  bool getClick(vpImagePoint &ip,
267  bool blocking=true) ;
268  bool getClickUp(vpImagePoint &ip,
270  bool blocking=true) ;
271 
272  inline unsigned int getWidth() const { return width ; }
273  inline unsigned int getHeight() const { return height ; }
274 
275  bool getKeyboardEvent(bool blocking=true);
276  bool getKeyboardEvent(char *string, bool blocking=true);
278  bool getPointerPosition (vpImagePoint &ip);
279 
280  static void on_mouse( int event, int x, int y, int flags, void* param );
281 } ;
282 
283 #endif
284 #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:174
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:183
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
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:170
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:184
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:328
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:85
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:93
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:162
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0