Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpDisplayOpenCV.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 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 https://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*****************************************************************************/
35
36#ifndef _vpDisplayOpenCV_h_
37#define _vpDisplayOpenCV_h_
38
39#include <visp3/core/vpConfig.h>
40
41#if defined(HAVE_OPENCV_HIGHGUI)
42
43#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
44#include <functional>
45#endif
46
47#include <visp3/core/vpDisplay.h>
48#include <visp3/core/vpImage.h>
49#include <visp3/core/vpImageConvert.h>
50
51#include <opencv2/core/core.hpp>
52#include <opencv2/highgui/highgui.hpp>
53
141class VISP_EXPORT vpDisplayOpenCV : public vpDisplay
142{
143private:
144 cv::Mat m_background;
145 cv::Scalar *col;
146 cv::Scalar cvcolor;
147 int font;
148 float fontScale;
149 static std::vector<std::string> m_listTitles;
150 static unsigned int m_nbWindows;
151 int fontHeight;
152 int x_move;
153 int y_move;
154 bool move;
155 int x_lbuttondown;
156 int y_lbuttondown;
157 bool lbuttondown;
158 int x_mbuttondown;
159 int y_mbuttondown;
160 bool mbuttondown;
161 int x_rbuttondown;
162 int y_rbuttondown;
163 bool rbuttondown;
164 int x_lbuttonup;
165 int y_lbuttonup;
166 bool lbuttonup;
167 int x_mbuttonup;
168 int y_mbuttonup;
169 bool mbuttonup;
170 int x_rbuttonup;
171 int y_rbuttonup;
172 bool rbuttonup;
173
174 // private:
175 //#ifndef DOXYGEN_SHOULD_SKIP_THIS
176 // vpDisplayOpenCV(const vpDisplayOpenCV &)
177 // : vpDisplay(),
178 // #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
179 // background(NULL), col(NULL), cvcolor(), font(NULL),
180 // #else
181 // background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN),
182 // fontScale(0.8f),
183 // #endif
184 // fontHeight(10), x_move(0), y_move(0) , move(false),
185 // x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
186 // x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
187 // x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
188 // x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
189 // x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
190 // x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
191 // {
192 // throw vpException(vpException::functionNotImplementedError, "Not
193 // implemented!");
194 // }
195 // vpDisplayOpenCV &operator=(const vpDisplayOpenCV &){
196 // throw vpException(vpException::functionNotImplementedError, "Not
197 // implemented!"); return *this;
198 // }
199 //#endif
200
201public:
203 vpDisplayOpenCV(int winx, int winy, const std::string &title = "");
205 vpDisplayOpenCV(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "",
206 vpScaleType type = SCALE_DEFAULT);
208 vpDisplayOpenCV(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "",
209 vpScaleType type = SCALE_DEFAULT);
210
211 virtual ~vpDisplayOpenCV();
212
213 void getImage(vpImage<vpRGBa> &I);
214 unsigned int getScreenHeight();
215 void getScreenSize(unsigned int &width, unsigned int &height);
216 unsigned int getScreenWidth();
217
218 void init(vpImage<unsigned char> &I, int winx = -1, int winy = -1, const std::string &title = "");
219 void init(vpImage<vpRGBa> &I, int winx = -1, int winy = -1, const std::string &title = "");
220 void init(unsigned int width, unsigned int height, int winx = -1, int winy = -1, const std::string &title = "");
221
222protected:
223 void setFont(const std::string &font);
224 void setTitle(const std::string &title);
225 void setWindowPosition(int winx, int winy);
226
227 void clearDisplay(const vpColor &color = vpColor::white);
228
229 void closeDisplay();
230
231 void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color = vpColor::white,
232 unsigned int w = 4, unsigned int h = 2, unsigned int thickness = 1);
233
234 void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color = vpColor::green);
235
236 void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill = false,
237 unsigned int thickness = 1);
238 void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness = 1);
239 void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
240 unsigned int thickness = 1);
241
242 void displayImage(const vpImage<unsigned char> &I);
243 void displayImage(const vpImage<vpRGBa> &I);
244 void displayImage(const unsigned char *I);
245
246 void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, unsigned int width,
247 unsigned int height);
248 void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int width, unsigned int height);
249
250 void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness = 1);
251 void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness = 1);
252
253 void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color,
254 bool fill = false, unsigned int thickness = 1);
255 void displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight, const vpColor &color,
256 bool fill = false, unsigned int thickness = 1);
257 void displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill = false, unsigned int thickness = 1);
258
259 void flushDisplay();
260 void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height);
261
262 bool getClick(bool blocking = true);
263 bool getClick(vpImagePoint &ip, bool blocking = true);
264 bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
265 bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking = true);
266
267 bool getKeyboardEvent(bool blocking = true);
268 bool getKeyboardEvent(std::string &key, bool blocking = true);
271
272 static void on_mouse(int event, int x, int y, int flags, void *param);
273
274#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
275 void overlay(std::function<void(cv::Mat &)> overlay_function, double opacity);
276#endif
277};
278
279#endif
280#endif
Class to define RGB colors available for display functionalities.
Definition vpColor.h:152
static const vpColor white
Definition vpColor.h:206
static const vpColor green
Definition vpColor.h:214
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Class that defines generic functionalities for display.
Definition vpDisplay.h:173
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
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 getImage(const vpImage< unsigned char > &Is, vpImage< vpRGBa > &Id)
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
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 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)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void setFont(const vpImage< unsigned char > &I, const std::string &font)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getPointerMotionEvent(const vpImage< unsigned char > &I, vpImagePoint &ip)
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 setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:135
Defines a rectangle in the plane.
Definition vpRect.h:76