ViSP  2.8.0
vpDisplayOpenCV.h
1 /****************************************************************************
2  *
3  * $Id: vpDisplayOpenCV.h 4323 2013-07-18 09:24:01Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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 #include <visp/vpDisplay.h>
48 #if ( defined(VISP_HAVE_OPENCV) )
49 
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:
148  IplImage* background;
149  CvScalar *col ;
150  CvScalar cvcolor;
151  CvFont *font;
152  int fontHeight;
153  int ncol, nrow ;
154  int x_move;
155  int y_move;
156  bool move;
157  int x_lbuttondown ;
158  int y_lbuttondown ;
159  bool lbuttondown;
160  int x_mbuttondown ;
161  int y_mbuttondown ;
162  bool mbuttondown;
163  int x_rbuttondown ;
164  int y_rbuttondown ;
165  bool rbuttondown;
166  int x_lbuttonup ;
167  int y_lbuttonup ;
168  bool lbuttonup;
169  int x_mbuttonup ;
170  int y_mbuttonup ;
171  bool mbuttonup;
172  int x_rbuttonup ;
173  int y_rbuttonup ;
174  bool rbuttonup;
175 
176 public:
177  vpDisplayOpenCV() ;
178  vpDisplayOpenCV(int winx, int winy, const char *title=NULL) ;
179  vpDisplayOpenCV(vpImage<unsigned char> &I, int winx=-1, int winy=-1,
180  const char *title=NULL) ;
181  vpDisplayOpenCV(vpImage<vpRGBa> &I, int winx=-1, int winy=-1,
182  const char *title=NULL) ;
183 
184  virtual ~vpDisplayOpenCV() ;
185 
187  int winx=-1, int winy=-1,
188  const char *title=NULL) ;
189  void init(vpImage<vpRGBa> &I,
190  int winx=-1, int winy=-1,
191  const char *title=NULL) ;
192 
193  void init(unsigned int width, unsigned int height,
194  int winx=-1, int winy=-1 ,
195  const char *title=NULL) ;
196  void getImage(vpImage<vpRGBa> &I) ;
197 
198 protected:
199  void setFont( const char *font );
200  void setTitle(const char *title) ;
201  void setWindowPosition(int winx, int winy);
202 
203  void clearDisplay(const vpColor &color=vpColor::white) ;
204 
205  void closeDisplay() ;
206 
207  void displayArrow(const vpImagePoint &ip1,
208  const vpImagePoint &ip2,
209  const vpColor &color=vpColor::white,
210  unsigned int w=4,unsigned int h=2,
211  unsigned int thickness=1) ;
212 
213  void displayCharString(const vpImagePoint &ip, const char *text,
214  const vpColor &color=vpColor::green) ;
215 
216  void displayCircle(const vpImagePoint &center, unsigned int radius,
217  const vpColor &color,
218  bool fill = false,
219  unsigned int thickness=1);
220  void displayCross(const vpImagePoint &ip, unsigned int size,
221  const vpColor &color, unsigned int thickness=1) ;
222  void displayDotLine(const vpImagePoint &ip1,
223  const vpImagePoint &ip2,
224  const vpColor &color, unsigned int thickness=1) ;
225 
226  void displayImage(const vpImage<vpRGBa> &I) ;
227  void displayImage(const vpImage<unsigned char> &I) ;
228  void displayImage(const unsigned char *I) ;
229 
230  void displayImageROI(const vpImage<unsigned char> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
231  void displayImageROI(const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int width, const unsigned int height);
232 
233  void displayLine(const vpImagePoint &ip1,
234  const vpImagePoint &ip2,
235  const vpColor &color, unsigned int thickness=1) ;
236  void displayPoint(const vpImagePoint &ip, const vpColor &color) ;
237 
238  void displayRectangle(const vpImagePoint &topLeft,
239  unsigned int width, unsigned int height,
240  const vpColor &color, bool fill = false,
241  unsigned int thickness=1) ;
242  void displayRectangle(const vpImagePoint &topLeft,
243  const vpImagePoint &bottomRight,
244  const vpColor &color, bool fill = false,
245  unsigned int thickness=1) ;
246  void displayRectangle(const vpRect &rectangle,
247  const vpColor &color, bool fill = false,
248  unsigned int thickness=1) ;
249 
250  void flushDisplay() ;
251  void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height);
252 
253  bool getClick(bool blocking=true) ;
254  bool getClick(vpImagePoint &ip, bool blocking=true) ;
255  bool getClick(vpImagePoint &ip,
257  bool blocking=true) ;
258  bool getClickUp(vpImagePoint &ip,
260  bool blocking=true) ;
261 
262  inline unsigned int getWidth() const { return width ; }
263  inline unsigned int getHeight() const { return height ; }
264 
265  bool getKeyboardEvent(bool blocking=true);
266  bool getKeyboardEvent(char *string, bool blocking=true);
268  bool getPointerPosition (vpImagePoint &ip);
269 
270  static void on_mouse( int event, int x, int y, int flags, void* param );
271 } ;
272 
273 #endif
274 #endif
275 
276 /*
277  * Local variables:
278  * c-basic-offset: 2
279  * End:
280  */
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:175
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:187
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:188
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:321
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:82
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:92
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
char * font
Definition: vpDisplay.h:186
virtual void displayPoint(const vpImagePoint &ip, const vpColor &color)=0