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