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