Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDisplayOpenCV.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Image display.
32 */
33
38
39#include <visp3/core/vpConfig.h>
40
41#if defined(HAVE_OPENCV_HIGHGUI)
42
43#include <cmath> // std::fabs
44#include <iostream>
45#include <limits> // numeric_limits
46#include <stdio.h>
47#include <stdlib.h>
48
49// Display stuff
50#include <visp3/core/vpDisplay.h>
51#include <visp3/core/vpImageTools.h>
52#include <visp3/core/vpIoTools.h>
53#include <visp3/core/vpMath.h>
54#include <visp3/gui/vpDisplayOpenCV.h>
55
56// debug / exception
57#include <visp3/core/vpDisplayException.h>
58
59#include <opencv2/core/core.hpp>
60#include <opencv2/highgui/highgui.hpp>
61#if (VISP_HAVE_OPENCV_VERSION < 0x050000)
62#include <opencv2/core/core_c.h> // for CV_FILLED versus cv::FILLED
63#endif
64#if defined(HAVE_OPENCV_IMGPROC)
65#include <opencv2/imgproc/imgproc.hpp>
66#endif
67
68#ifndef CV_RGB
69#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)
70#endif
71
72#ifdef VISP_HAVE_X11
73#include <visp3/gui/vpDisplayX.h> // to get screen resolution
74#elif defined(_WIN32)
75
76// Mute warning with clang-cl
77// warning : non-portable path to file '<Windows.h>'; specified path differs in case from file name on disk [-Wnonportable-system-include-path]
78#if defined(__clang__)
79# pragma clang diagnostic push
80# pragma clang diagnostic ignored "-Wnonportable-system-include-path"
81#endif
82
83#include <windows.h>
84
85#if defined(__clang__)
86# pragma clang diagnostic pop
87#endif
88
89#endif
90
92
93#ifndef DOXYGEN_SHOULD_SKIP_THIS
94class vpDisplayOpenCV::Impl
95{
96private:
97 cv::Mat m_background;
98 cv::Scalar *col;
99 cv::Scalar cvcolor;
100 int font;
101 double fontScale;
102 static std::vector<std::string> m_listTitles;
103 static unsigned int m_nbWindows;
104 int fontHeight;
105 int x_move;
106 int y_move;
107 bool move;
108 int x_lbuttondown;
109 int y_lbuttondown;
110 bool lbuttondown;
111 int x_mbuttondown;
112 int y_mbuttondown;
113 bool mbuttondown;
114 int x_rbuttondown;
115 int y_rbuttondown;
116 bool rbuttondown;
117 int x_lbuttonup;
118 int y_lbuttonup;
119 bool lbuttonup;
120 int x_mbuttonup;
121 int y_mbuttonup;
122 bool mbuttonup;
123 int x_rbuttonup;
124 int y_rbuttonup;
125 bool rbuttonup;
126
127 friend class vpDisplayOpenCV;
128
129public:
130 Impl() :
131 m_background(), col(nullptr), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8),
132 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
133 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
134 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
135 y_rbuttonup(0), rbuttonup(false)
136 { }
137
138 virtual ~Impl()
139 {
140 if (col != nullptr) {
141 delete[] col;
142 col = nullptr;
143 }
144 }
145
146 void getImage(vpImage<vpRGBa> &I)
147 {
148 // Should be optimized
149 vpImageConvert::convert(m_background, I);
150 }
151
152 std::string init(const std::string &title, const int &windowXPosition, const int &windowYPosition)
153 {
154 int flags = cv::WINDOW_AUTOSIZE;
155 std::string outTitle = title;
156 if (outTitle.empty()) {
157 std::ostringstream s;
158 s << m_nbWindows++;
159 outTitle = std::string("Window ") + s.str();
160 }
161
162 bool isInList;
163 do {
164 isInList = false;
165 size_t i = 0;
166 while (i < m_listTitles.size() && !isInList) {
167 if (m_listTitles[i] == outTitle) {
168 std::ostringstream s;
169 s << m_nbWindows++;
170 outTitle = std::string("Window ") + s.str();
171 isInList = true;
172 }
173 i++;
174 }
175 } while (isInList);
176
177 m_listTitles.push_back(outTitle);
178
179
180 /* Create the window*/
181 cv::namedWindow(outTitle, flags);
182 cv::moveWindow(outTitle.c_str(), windowXPosition, windowYPosition);
183
184 move = false;
185 lbuttondown = false;
186 mbuttondown = false;
187 rbuttondown = false;
188 lbuttonup = false;
189 mbuttonup = false;
190 rbuttonup = false;
191
192 cv::setMouseCallback(outTitle, on_mouse, this);
193 col = new cv::Scalar[vpColor::id_unknown];
194
195 /* Create color */
196 vpColor pcolor; // Predefined colors
197 pcolor = vpColor::lightBlue;
198 col[vpColor::id_lightBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
199 pcolor = vpColor::blue;
200 col[vpColor::id_blue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
201 pcolor = vpColor::darkBlue;
202 col[vpColor::id_darkBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
203 pcolor = vpColor::lightRed;
204 col[vpColor::id_lightRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
205 pcolor = vpColor::red;
206 col[vpColor::id_red] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
207 pcolor = vpColor::darkRed;
208 col[vpColor::id_darkRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
209 pcolor = vpColor::lightGreen;
210 col[vpColor::id_lightGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
211 pcolor = vpColor::green;
212 col[vpColor::id_green] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
213 pcolor = vpColor::darkGreen;
214 col[vpColor::id_darkGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
215 pcolor = vpColor::yellow;
216 col[vpColor::id_yellow] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
217 pcolor = vpColor::cyan;
218 col[vpColor::id_cyan] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
219 pcolor = vpColor::orange;
220 col[vpColor::id_orange] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
221 pcolor = vpColor::purple;
222 col[vpColor::id_purple] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
223 pcolor = vpColor::white;
224 col[vpColor::id_white] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
225 pcolor = vpColor::black;
226 col[vpColor::id_black] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
227 pcolor = vpColor::lightGray;
228 col[vpColor::id_lightGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
229 pcolor = vpColor::gray;
230 col[vpColor::id_gray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
231 pcolor = vpColor::darkGray;
232 col[vpColor::id_darkGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
233
234 int thickness = 1;
235 cv::Size fontSize;
236 int baseline;
237 fontSize = cv::getTextSize("A", font, fontScale, thickness, &baseline);
238
239 fontHeight = fontSize.height + baseline;
240 return outTitle;
241 }
242
243 void closeDisplay(const std::string &title)
244 {
245 if (col != nullptr) {
246 delete[] col;
247 col = nullptr;
248 }
249
250 cv::destroyWindow(title);
251 for (size_t i = 0; i < m_listTitles.size(); i++) {
252 if (title == m_listTitles[i]) {
253 m_listTitles.erase(m_listTitles.begin() + static_cast<long int>(i));
254 break;
255 }
256 }
257 }
258
259 void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
260 const unsigned int &w, const unsigned int &h, const unsigned int &thickness, const unsigned int &scale)
261 {
262 double a = ip2.get_i() - ip1.get_i();
263 double b = ip2.get_j() - ip1.get_j();
264 double lg = sqrt(vpMath::sqr(a) + vpMath::sqr(b));
265
266 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
267 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
268 }
269 else {
270 a /= lg;
271 b /= lg;
272
273 vpImagePoint ip3;
274 ip3.set_i(ip2.get_i() - w * a);
275 ip3.set_j(ip2.get_j() - w * b);
276
277 vpImagePoint ip4;
278 ip4.set_i(ip3.get_i() - b * h);
279 ip4.set_j(ip3.get_j() + a * h);
280
281 if (lg > 2 * vpImagePoint::distance(ip2, ip4))
282 displayLine(ip2, ip4, color, thickness, scale);
283
284 ip4.set_i(ip3.get_i() + b * h);
285 ip4.set_j(ip3.get_j() - a * h);
286
287 if (lg > 2 * vpImagePoint::distance(ip2, ip4))
288 displayLine(ip2, ip4, color, thickness, scale);
289
290 displayLine(ip1, ip2, color, thickness, scale);
291 }
292 }
293
294 void displayCircle(const vpImagePoint &center, const unsigned int &radius, const vpColor &color, const bool &fill,
295 const unsigned int &thickness, const unsigned int &scale)
296 {
297 int x = vpMath::round(center.get_u() / scale);
298 int y = vpMath::round(center.get_v() / scale);
299 int r = static_cast<int>(radius / scale);
300 cv::Scalar cv_color;
301 if ((color.id < vpColor::id_black) || (color.id >= vpColor::id_unknown)) {
302 cv_color = CV_RGB(color.R, color.G, color.B);
303 }
304 else {
305 cv_color = col[color.id];
306 }
307
308 if (fill == false) {
309 int cv_thickness = static_cast<int>(thickness);
310 cv::circle(m_background, cv::Point(x, y), r, cv_color, cv_thickness);
311 }
312 else {
313#if VISP_HAVE_OPENCV_VERSION >= 0x030000
314 int filled = cv::FILLED;
315#else
316 int filled = CV_FILLED;
317#endif
318 double opacity = static_cast<double>(color.A) / 255.0;
319 overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); },
320 opacity);
321 }
322 }
323
324 void displayCross(const vpImagePoint &ip, const unsigned int &size, const vpColor &color, const unsigned int &thickness, const unsigned int &scale)
325 {
326 vpImagePoint top, bottom, left, right;
327 top.set_i(ip.get_i() - size / 2);
328 top.set_j(ip.get_j());
329 bottom.set_i(ip.get_i() + size / 2);
330 bottom.set_j(ip.get_j());
331 left.set_i(ip.get_i());
332 left.set_j(ip.get_j() - size / 2);
333 right.set_i(ip.get_i());
334 right.set_j(ip.get_j() + size / 2);
335 displayLine(top, bottom, color, thickness, scale);
336 displayLine(left, right, color, thickness, scale);
337 }
338
339 void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
340 const unsigned int &thickness, const unsigned int &scale)
341 {
342 vpImagePoint ip1_ = ip1;
343 vpImagePoint ip2_ = ip2;
344
345 double size = 10. * scale;
346 double length = sqrt(vpMath::sqr(ip2_.get_i() - ip1_.get_i()) + vpMath::sqr(ip2_.get_j() - ip1_.get_j()));
347 bool vertical_line = static_cast<int>(ip2_.get_j()) == static_cast<int>(ip1_.get_j());
348 if (vertical_line) {
349 if (ip2_.get_i() < ip1_.get_i()) {
350 std::swap(ip1_, ip2_);
351 }
352 }
353 else if (ip2_.get_j() < ip1_.get_j()) {
354 std::swap(ip1_, ip2_);
355 }
356
357 double diff_j = vertical_line ? 1 : ip2_.get_j() - ip1_.get_j();
358 double deltaj = size / length * diff_j;
359 double deltai = size / length * (ip2_.get_i() - ip1_.get_i());
360 double slope = (ip2_.get_i() - ip1_.get_i()) / diff_j;
361 double orig = ip1_.get_i() - slope * ip1_.get_j();
362
363 if (vertical_line) {
364 for (unsigned int i = static_cast<unsigned int>(ip1_.get_i()); i < ip2_.get_i(); i += static_cast<unsigned int>(2 * deltai)) {
365 double j = ip1_.get_j();
366 displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j), color, thickness, scale);
367 }
368 }
369 else {
370 for (unsigned int j = static_cast<unsigned int>(ip1_.get_j()); j < ip2_.get_j(); j += static_cast<unsigned int>(2 * deltaj)) {
371 double i = slope * j + orig;
372 displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j + deltaj), color, thickness, scale);
373 }
374 }
375 }
376
377 void displayImage(const vpImage<unsigned char> &I, const unsigned int &scale, const unsigned int &width, const unsigned int &height)
378 {
379 int depth = CV_8U;
380 int channels = 3;
381 cv::Size size(static_cast<int>(width), static_cast<int>(height));
382 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != static_cast<int>(height) ||
383 m_background.cols != static_cast<int>(width)) {
384 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
385 }
386
387 if (scale == 1) {
388 for (unsigned int i = 0; i < height; i++) {
389 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3 * width);
390 for (unsigned int j = 0; j < width; j++) {
391 unsigned char val = I[i][j];
392 *(dst_24++) = val;
393 *(dst_24++) = val;
394 *(dst_24++) = val;
395 }
396 }
397 }
398 else {
399 for (unsigned int i = 0; i < height; i++) {
400 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3 * width);
401 for (unsigned int j = 0; j < width; j++) {
402 unsigned char val = I[i * scale][j * scale];
403 *(dst_24++) = val;
404 *(dst_24++) = val;
405 *(dst_24++) = val;
406 }
407 }
408 }
409 }
410
411 void displayImage(const vpImage<vpRGBa> &I, const unsigned int &scale, const unsigned int &width, const unsigned int &height)
412 {
413 int depth = CV_8U;
414 int channels = 3;
415 cv::Size size(static_cast<int>(width), static_cast<int>(height));
416 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != static_cast<int>(height) ||
417 m_background.cols != static_cast<int>(width)) {
418 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
419 }
420
421 if (scale == 1) {
422 for (unsigned int i = 0; i < height; i++) {
423 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3 * width);
424 for (unsigned int j = 0; j < width; j++) {
425 vpRGBa val = I[i][j];
426 *(dst_24++) = val.B;
427 *(dst_24++) = val.G;
428 *(dst_24++) = val.R;
429 }
430 }
431 }
432 else {
433 for (unsigned int i = 0; i < height; i++) {
434 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3 * width);
435 for (unsigned int j = 0; j < width; j++) {
436 vpRGBa val = I[i * scale][j * scale];
437 *(dst_24++) = val.B;
438 *(dst_24++) = val.G;
439 *(dst_24++) = val.R;
440 }
441 }
442 }
443 }
444
445 void displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int &w,
446 const unsigned int &h, const unsigned int &imgWidth, const unsigned int &imgHeight, const unsigned int &scale)
447 {
448 int depth = CV_8U;
449 int channels = 3;
450 cv::Size size(static_cast<int>(imgWidth), static_cast<int>(imgHeight));
451 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != static_cast<int>(imgHeight) ||
452 m_background.cols != static_cast<int>(imgWidth)) {
453 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
454 }
455
456 if (scale == 1) {
457 unsigned int i_min = static_cast<unsigned int>(iP.get_i());
458 unsigned int j_min = static_cast<unsigned int>(iP.get_j());
459 unsigned int i_max = std::min<unsigned int>(i_min + h, imgHeight);
460 unsigned int j_max = std::min<unsigned int>(j_min + w, imgWidth);
461 for (unsigned int i = i_min; i < i_max; i++) {
462 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3u * imgWidth + j_min * 3u);
463 for (unsigned int j = j_min; j < j_max; j++) {
464 unsigned char val = I[i][j];
465 *(dst_24++) = val;
466 *(dst_24++) = val;
467 *(dst_24++) = val;
468 }
469 }
470 }
471 else {
472 unsigned int i_min = std::max<unsigned int>(static_cast<unsigned int>(ceil(iP.get_i() / scale)), 0);
473 unsigned int j_min = std::max<unsigned int>(static_cast<unsigned int>(ceil(iP.get_j() / scale)), 0);
474 unsigned int i_max = std::min<unsigned int>(static_cast<unsigned int>(ceil((iP.get_i() + h) / scale)), imgHeight);
475 unsigned int j_max = std::min<unsigned int>(static_cast<unsigned int>(ceil((iP.get_j() + w) / scale)), imgWidth);
476 for (unsigned int i = i_min; i < i_max; i++) {
477 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3u * imgWidth + j_min * 3u);
478 for (unsigned int j = j_min; j < j_max; j++) {
479 unsigned char val = I[i * scale][j * scale];
480 *(dst_24++) = val;
481 *(dst_24++) = val;
482 *(dst_24++) = val;
483 }
484 }
485 }
486 }
487
488 void displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, const unsigned int &w, const unsigned int &h, const unsigned int &imgWidth, const unsigned int &imgHeight, const unsigned int &scale)
489 {
490 int depth = CV_8U;
491 int channels = 3;
492 cv::Size size(static_cast<int>(imgWidth), static_cast<int>(imgHeight));
493 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != static_cast<int>(imgHeight) ||
494 m_background.cols != static_cast<int>(imgWidth)) {
495 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
496 }
497
498 if (scale == 1) {
499 unsigned int i_min = static_cast<unsigned int>(iP.get_i());
500 unsigned int j_min = static_cast<unsigned int>(iP.get_j());
501 unsigned int i_max = std::min<unsigned int>(i_min + h, imgHeight);
502 unsigned int j_max = std::min<unsigned int>(j_min + w, imgWidth);
503 for (unsigned int i = i_min; i < i_max; i++) {
504 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3 * imgWidth + j_min * 3);
505 for (unsigned int j = j_min; j < j_max; j++) {
506 vpRGBa val = I[i][j];
507 *(dst_24++) = val.B;
508 *(dst_24++) = val.G;
509 *(dst_24++) = val.R;
510 }
511 }
512 }
513 else {
514 unsigned int i_min = std::max<unsigned int>(static_cast<unsigned int>(ceil(iP.get_i() / scale)), 0);
515 unsigned int j_min = std::max<unsigned int>(static_cast<unsigned int>(ceil(iP.get_j() / scale)), 0);
516 unsigned int i_max = std::min<unsigned int>(static_cast<unsigned int>(ceil((iP.get_i() + h) / scale)), imgHeight);
517 unsigned int j_max = std::min<unsigned int>(static_cast<unsigned int>(ceil((iP.get_j() + w) / scale)), imgWidth);
518 for (unsigned int i = i_min; i < i_max; i++) {
519 unsigned char *dst_24 = static_cast<unsigned char *>(m_background.data) + static_cast<int>(i * 3 * imgWidth + j_min * 3);
520 for (unsigned int j = j_min; j < j_max; j++) {
521 vpRGBa val = I[i * scale][j * scale];
522 *(dst_24++) = val.B;
523 *(dst_24++) = val.G;
524 *(dst_24++) = val.R;
525 }
526 }
527 }
528 }
529
530 void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, const unsigned int &thickness, const unsigned int &scale)
531 {
532 if ((color.id < vpColor::id_black) || (color.id >= vpColor::id_unknown)) {
533 cvcolor = CV_RGB(color.R, color.G, color.B);
534 cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / scale), vpMath::round(ip1.get_v() / scale)),
535 cv::Point(vpMath::round(ip2.get_u() / scale), vpMath::round(ip2.get_v() / scale)), cvcolor,
536 static_cast<int>(thickness));
537 }
538 else {
539 cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / scale), vpMath::round(ip1.get_v() / scale)),
540 cv::Point(vpMath::round(ip2.get_u() / scale), vpMath::round(ip2.get_v() / scale)), col[color.id],
541 static_cast<int>(thickness));
542 }
543 }
544
545 void displayPoint(const vpImagePoint &ip, const vpColor &color, const unsigned int &thickness, const unsigned int &scale)
546 {
547 for (unsigned int i = 0; i < thickness; i++) {
548 if ((color.id < vpColor::id_black) || (color.id >= vpColor::id_unknown)) {
549 cvcolor = CV_RGB(color.R, color.G, color.B);
550 cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale)),
551 cv::Point(vpMath::round(ip.get_u() / scale + thickness - 1), vpMath::round(ip.get_v() / scale)),
552 cvcolor, static_cast<int>(thickness));
553 }
554 else {
555 cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale)),
556 cv::Point(vpMath::round(ip.get_u() / scale + thickness - 1), vpMath::round(ip.get_v() / scale)),
557 col[color.id], static_cast<int>(thickness));
558 }
559 }
560 }
561
562 void displayRectangle(const vpImagePoint &topLeft, const unsigned int &w, const unsigned int &h, const vpColor &color,
563 const bool &fill, const unsigned int &thickness, const unsigned int &scale)
564 {
565 int left = vpMath::round(topLeft.get_u() / scale);
566 int top = vpMath::round(topLeft.get_v() / scale);
567 int right = vpMath::round((topLeft.get_u() + w) / scale);
568 int bottom = vpMath::round((topLeft.get_v() + h) / scale);
569 cv::Scalar cv_color;
570 if ((color.id < vpColor::id_black) || (color.id >= vpColor::id_unknown)) {
571 cv_color = CV_RGB(color.R, color.G, color.B);
572 }
573 else {
574 cv_color = col[color.id];
575 }
576
577 if (fill == false) {
578 int cv_thickness = static_cast<int>(thickness);
579 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
580 }
581 else {
582#if VISP_HAVE_OPENCV_VERSION >= 0x030000
583 int filled = cv::FILLED;
584#else
585 int filled = CV_FILLED;
586#endif
587 double opacity = static_cast<double>(color.A) / 255.0;
588 overlay([left, top, right, bottom, cv_color, filled](cv::Mat image) {
589 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
590 },
591 opacity);
592 }
593 }
594
595 void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color, const unsigned int &scale)
596 {
597 if ((color.id < vpColor::id_black) || (color.id >= vpColor::id_unknown)) {
598 cvcolor = CV_RGB(color.R, color.G, color.B);
599 cv::putText(m_background, text,
600 cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale + fontHeight)), font,
601 fontScale, cvcolor);
602 }
603 else {
604 cv::putText(m_background, text,
605 cv::Point(vpMath::round(ip.get_u() / scale), vpMath::round(ip.get_v() / scale + fontHeight)), font,
606 fontScale, col[color.id]);
607 }
608 }
609
610 void flushDisplay(const std::string &title)
611 {
612 cv::imshow(title, m_background);
613 cv::waitKey(5);
614 }
615
616 void flushDisplayROI(const std::string &title)
617 {
618 cv::imshow(title.c_str(), m_background);
619 cv::waitKey(5);
620 }
621
622 bool getClick(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, const bool &blocking, const std::string &title, const unsigned int &scale)
623 {
624 flushDisplay(title);
625 bool ret = false;
626 double u, v;
627 if (blocking) {
628 lbuttondown = false;
629 mbuttondown = false;
630 rbuttondown = false;
631 }
632 do {
633 if (lbuttondown) {
634 ret = true;
635 u = static_cast<unsigned int>(x_lbuttondown) * scale;
636 v = static_cast<unsigned int>(y_lbuttondown) * scale;
637 ip.set_u(u);
638 ip.set_v(v);
639 button = vpMouseButton::button1;
640 lbuttondown = false;
641 }
642 if (mbuttondown) {
643 ret = true;
644 u = static_cast<unsigned int>(x_mbuttondown) * scale;
645 v = static_cast<unsigned int>(y_mbuttondown) * scale;
646 ip.set_u(u);
647 ip.set_v(v);
648 button = vpMouseButton::button2;
649 mbuttondown = false;
650 }
651 if (rbuttondown) {
652 ret = true;
653 u = static_cast<unsigned int>(x_rbuttondown) * scale;
654 v = static_cast<unsigned int>(y_rbuttondown) * scale;
655 ip.set_u(u);
656 ip.set_v(v);
657 button = vpMouseButton::button3;
658 rbuttondown = false;
659 }
660 if (blocking) {
661 cv::waitKey(10);
662 }
663 } while (ret == false && blocking == true);
664 return ret;
665 }
666
667 bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, const bool &blocking, const unsigned int &scale)
668 {
669 bool ret = false;
670 double u, v;
671 if (blocking) {
672 lbuttonup = false;
673 mbuttonup = false;
674 rbuttonup = false;
675 }
676 do {
677 if (lbuttonup) {
678 ret = true;
679 u = static_cast<unsigned int>(x_lbuttonup) * scale;
680 v = static_cast<unsigned int>(y_lbuttonup) * scale;
681 ip.set_u(u);
682 ip.set_v(v);
683 button = vpMouseButton::button1;
684 lbuttonup = false;
685 }
686 if (mbuttonup) {
687 ret = true;
688 u = static_cast<unsigned int>(x_mbuttonup) * scale;
689 v = static_cast<unsigned int>(y_mbuttonup) * scale;
690 ip.set_u(u);
691 ip.set_v(v);
692 button = vpMouseButton::button2;
693 mbuttonup = false;
694 }
695 if (rbuttonup) {
696 ret = true;
697 u = static_cast<unsigned int>(x_rbuttonup) * scale;
698 v = static_cast<unsigned int>(y_rbuttonup) * scale;
699 ip.set_u(u);
700 ip.set_v(v);
701 button = vpMouseButton::button3;
702 rbuttonup = false;
703 }
704 if (blocking) {
705 cv::waitKey(10);
706 }
707 } while (ret == false && blocking == true);
708 return ret;
709 }
710
711 bool getPointerMotionEvent(vpImagePoint &ip, const unsigned int &scale)
712 {
713 bool ret = false;
714 if (move) {
715 ret = true;
716 double u = static_cast<unsigned int>(x_move) / scale;
717 double v = static_cast<unsigned int>(y_move) / scale;
718 ip.set_u(u);
719 ip.set_v(v);
720 move = false;
721 }
722 return ret;
723 }
724
725 void getPointerPosition(vpImagePoint &ip, const unsigned int &scale)
726 {
727 bool moved = getPointerMotionEvent(ip, scale);
728 if (!moved) {
729 double u, v;
730 u = static_cast<unsigned int>(x_move) / scale;
731 v = static_cast<unsigned int>(y_move) / scale;
732 ip.set_u(u);
733 ip.set_v(v);
734 }
735 }
736
737 static void on_mouse(int event, int x, int y, int /*flags*/, void *display)
738 {
739 Impl *disp = static_cast<Impl *>(display);
740
741 switch (event) {
742 case cv::EVENT_MOUSEMOVE:
743 {
744 disp->move = true;
745 disp->x_move = x;
746 disp->y_move = y;
747 break;
748 }
749 case cv::EVENT_LBUTTONDOWN:
750 {
751 disp->lbuttondown = true;
752 disp->x_lbuttondown = x;
753 disp->y_lbuttondown = y;
754 break;
755 }
756 case cv::EVENT_MBUTTONDOWN:
757 {
758 disp->mbuttondown = true;
759 disp->x_mbuttondown = x;
760 disp->y_mbuttondown = y;
761 break;
762 }
763 case cv::EVENT_RBUTTONDOWN:
764 {
765 disp->rbuttondown = true;
766 disp->x_rbuttondown = x;
767 disp->y_rbuttondown = y;
768 break;
769 }
770 case cv::EVENT_LBUTTONUP:
771 {
772 disp->lbuttonup = true;
773 disp->x_lbuttonup = x;
774 disp->y_lbuttonup = y;
775 break;
776 }
777 case cv::EVENT_MBUTTONUP:
778 {
779 disp->mbuttonup = true;
780 disp->x_mbuttonup = x;
781 disp->y_mbuttonup = y;
782 break;
783 }
784 case cv::EVENT_RBUTTONUP:
785 {
786 disp->rbuttonup = true;
787 disp->x_rbuttonup = x;
788 disp->y_rbuttonup = y;
789 break;
790 }
791
792 default:
793 break;
794 }
795 }
796
797 void overlay(std::function<void(cv::Mat &)> overlay_function, const double &opacity)
798 {
799 // Initialize overlay layer for transparency
800 cv::Mat overlay;
801 if (opacity < 1.0) {
802 // Deep copy
803 overlay = m_background.clone();
804 }
805 else {
806 // Shallow copy
807 overlay = m_background;
808 }
809
810 overlay_function(overlay);
811
812 // Blend background and overlay
813 if (opacity < 1.0) {
814 cv::addWeighted(overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background);
815 }
816 }
817};
818
819VP_ATTRIBUTE_NO_DESTROY std::vector<std::string> vpDisplayOpenCV::Impl::m_listTitles = std::vector<std::string>();
820unsigned int vpDisplayOpenCV::Impl::m_nbWindows = 0;
821#endif // DOXYGEN_SHOULD_SKIP_THIS
822
836 : vpDisplay()
837 , m_impl(new Impl())
838{
839 setScale(scaleType, I.getWidth(), I.getHeight());
840 init(I);
841}
842
858vpDisplayOpenCV::vpDisplayOpenCV(vpImage<unsigned char> &I, int x, int y, const std::string &title,
859 vpScaleType scaleType)
860 : vpDisplay()
861 , m_impl(new Impl())
862{
863 setScale(scaleType, I.getWidth(), I.getHeight());
864 init(I, x, y, title);
865}
866
880 : vpDisplay()
881 , m_impl(new Impl())
882{
883 setScale(scaleType, I.getWidth(), I.getHeight());
884 init(I);
885}
886
902vpDisplayOpenCV::vpDisplayOpenCV(vpImage<vpRGBa> &I, int x, int y, const std::string &title, vpScaleType scaleType)
903 : vpDisplay()
904 , m_impl(new Impl())
905{
906 setScale(scaleType, I.getWidth(), I.getHeight());
907 init(I, x, y, title);
908}
909
936vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title)
937 : vpDisplay()
938 , m_impl(new Impl())
939{
942
943 if (!title.empty()) {
944 m_title = title;
945 }
946 else {
947 std::ostringstream s;
948 s << vpDisplayOpenCV::Impl::m_nbWindows++;
949 m_title = std::string("Window ") + s.str();
950 }
951
952 bool isInList;
953 do {
954 isInList = false;
955 for (size_t i = 0; i < vpDisplayOpenCV::Impl::m_listTitles.size(); i++) {
956 if (vpDisplayOpenCV::Impl::m_listTitles[i] == m_title) {
957 std::ostringstream s;
958 s << vpDisplayOpenCV::Impl::m_nbWindows++;
959 m_title = std::string("Window ") + s.str();
960 isInList = true;
961 break;
962 }
963 }
964 } while (isInList);
965
966 vpDisplayOpenCV::Impl::m_listTitles.push_back(m_title);
967}
968
993 : vpDisplay()
994 , m_impl(new Impl())
995{ }
996
1004
1009{
1010 m_impl = display.m_impl;
1011 return *this;
1012}
1013
1018{
1019 closeDisplay();
1020 delete m_impl;
1021}
1022
1032void vpDisplayOpenCV::init(vpImage<unsigned char> &I, int x, int y, const std::string &title)
1033{
1034 if ((I.getHeight() == 0) || (I.getWidth() == 0)) {
1035 throw(vpDisplayException(vpDisplayException::notInitializedError, "Image not initialized"));
1036 }
1037 setScale(m_scaleType, I.getWidth(), I.getHeight());
1038 init(I.getWidth(), I.getHeight(), x, y, title);
1039 I.display = this;
1041}
1042
1053void vpDisplayOpenCV::init(vpImage<vpRGBa> &I, int x, int y, const std::string &title)
1054{
1055 if ((I.getHeight() == 0) || (I.getWidth() == 0)) {
1056 throw(vpDisplayException(vpDisplayException::notInitializedError, "Image not initialized"));
1057 }
1058
1059 setScale(m_scaleType, I.getWidth(), I.getHeight());
1060 init(I.getWidth(), I.getHeight(), x, y, title);
1061 I.display = this;
1063}
1064
1077void vpDisplayOpenCV::init(unsigned int w, unsigned int h, int x, int y, const std::string &title)
1078{
1079 setScale(m_scaleType, w, h);
1080
1081 this->m_width = w / m_scale;
1082 this->m_height = h / m_scale;
1083
1084 if (x != -1) {
1085 this->m_windowXPosition = x;
1086 }
1087 if (y != -1) {
1088 this->m_windowYPosition = y;
1089 }
1090
1091 if (m_title.empty()) {
1092 if (!title.empty()) {
1093 m_title = std::string(title);
1094 }
1095 }
1097
1099}
1100
1116void vpDisplayOpenCV::setFont(const std::string &font)
1117{
1118 // Not yet implemented
1119 (void)font;
1120}
1121
1129void vpDisplayOpenCV::setTitle(const std::string &title)
1130{
1131 // Not implemented
1132 (void)title;
1133}
1134
1145{
1147 this->m_windowXPosition = winx;
1148 this->m_windowYPosition = winy;
1149 cv::moveWindow(this->m_title.c_str(), winx, winy);
1150 }
1151 else {
1152 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1153 }
1154}
1155
1168{
1170 m_impl->displayImage(I, m_scale, m_width, m_height);
1171 }
1172 else {
1173 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1174 }
1175}
1176
1192 unsigned int h)
1193{
1195 m_impl->displayImageROI(I, iP, w, h, m_width, m_height, m_scale);
1196 }
1197 else {
1198 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1199 }
1200}
1201
1214{
1215
1217 m_impl->displayImage(I, m_scale, m_width, m_height);
1218 }
1219 else {
1220 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1221 }
1222}
1223
1238void vpDisplayOpenCV::displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int w, unsigned int h)
1239{
1241 m_impl->displayImageROI(I, iP, w, h, m_width, m_height, m_scale);
1242 }
1243 else {
1244 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1245 }
1246}
1247
1253void vpDisplayOpenCV::displayImage(const unsigned char * /* I */)
1254{
1255 // not implemented
1256}
1257
1266{
1268 m_impl->closeDisplay(m_title);
1269
1270 m_title.clear();
1271
1273 }
1274}
1275
1282{
1284 m_impl->flushDisplay(m_title);
1285 }
1286 else {
1287 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1288 }
1289}
1290
1296void vpDisplayOpenCV::flushDisplayROI(const vpImagePoint & /*iP*/, const unsigned int /*width*/,
1297 const unsigned int /*height*/)
1298{
1300 m_impl->flushDisplayROI(m_title);
1301 }
1302 else {
1303 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1304 }
1305}
1306
1311{
1312 // Not implemented
1313}
1314
1324void vpDisplayOpenCV::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1325 unsigned int w, unsigned int h, unsigned int thickness)
1326{
1328 m_impl->displayArrow(ip1, ip2, color, w, h, thickness, m_scale);
1329 }
1330 else {
1331 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1332 }
1333}
1334
1346void vpDisplayOpenCV::displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color)
1347{
1349 m_impl->displayText(ip, text, color, m_scale);
1350 }
1351 else {
1352 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1353 }
1354}
1355
1368void vpDisplayOpenCV::displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill,
1369 unsigned int thickness)
1370{
1372 m_impl->displayCircle(center, radius, color, fill, thickness, m_scale);
1373 }
1374 else {
1375 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1376 }
1377}
1378
1386void vpDisplayOpenCV::displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color,
1387 unsigned int thickness)
1388{
1390 m_impl->displayCross(ip, size, color, thickness, m_scale);
1391 }
1392 else {
1393 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1394 }
1395}
1396
1405void vpDisplayOpenCV::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1406 unsigned int thickness)
1407{
1409 m_impl->displayDotLine(ip1, ip2, color, thickness, m_scale);
1410 }
1411 else {
1412 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1413 }
1414}
1415
1423void vpDisplayOpenCV::displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1424 unsigned int thickness)
1425{
1427 m_impl->displayLine(ip1, ip2, color, thickness, m_scale);
1428 }
1429 else {
1430 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1431 }
1432}
1433
1440void vpDisplayOpenCV::displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness)
1441{
1443 m_impl->displayPoint(ip, color, thickness, m_scale);
1444 }
1445 else {
1446 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1447 }
1448}
1449
1466void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, unsigned int w, unsigned int h,
1467 const vpColor &color, bool fill, unsigned int thickness)
1468{
1470 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness, m_scale);
1471 }
1472 else {
1473 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1474 }
1475}
1476
1490void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
1491 const vpColor &color, bool fill, unsigned int thickness)
1492{
1494 unsigned int w = static_cast<unsigned int>(bottomRight.get_u() - topLeft.get_u() + 1);
1495 unsigned int h = static_cast<unsigned int>(bottomRight.get_v() - topLeft.get_v() + 1);
1496 displayRectangle(topLeft, w, h, color, fill, thickness);
1497 }
1498 else {
1499 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1500 }
1501}
1502
1516void vpDisplayOpenCV::displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill, unsigned int thickness)
1517{
1519 displayRectangle(rectangle.getTopLeft(), static_cast<unsigned int>(rectangle.getWidth()), static_cast<unsigned int>(rectangle.getHeight()), color, fill, thickness);
1520 }
1521 else {
1522 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1523 }
1524}
1525
1541bool vpDisplayOpenCV::getClick(bool blocking)
1542{
1543 bool ret = false;
1545 vpImagePoint ip;
1547 ret = getClick(ip, button, blocking);
1548 }
1549 else {
1550 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1551 }
1552 return ret;
1553}
1554
1571{
1572 bool ret = false;
1573
1576 ret = getClick(ip, button, blocking);
1577 }
1578 else {
1579 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1580 }
1581 return ret;
1582}
1583
1603{
1604 bool ret = false;
1605
1607 ret = m_impl->getClick(ip, button, blocking, m_title, m_scale);
1608 }
1609 else {
1610 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1611 }
1612 return ret;
1613}
1614
1637{
1638 bool ret = false;
1640 ret = m_impl->getClickUp(ip, button, blocking, m_scale);
1641 }
1642 else {
1643 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1644 }
1645 return ret;
1646}
1647
1648/*
1649 Gets the displayed image (including the overlay plane)
1650 and returns an RGBa image.
1651*/
1653{
1654 m_impl->getImage(I);
1655}
1656
1673{
1675 int delay;
1676 flushDisplay();
1677 if (blocking)
1678 delay = 0;
1679 else
1680 delay = 10;
1681
1682 int key_pressed = cv::waitKey(delay);
1683
1684 if (key_pressed == -1)
1685 return false;
1686 return true;
1687 }
1688 else {
1689 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1690 }
1691 // return false; // Never reached after throw()
1692}
1693
1712bool vpDisplayOpenCV::getKeyboardEvent(std::string &key, bool blocking)
1713{
1715 int delay;
1716 flushDisplay();
1717 if (blocking)
1718 delay = 0;
1719 else
1720 delay = 10;
1721
1722 int key_pressed = cv::waitKey(delay);
1723 if (key_pressed == -1)
1724 return false;
1725 else {
1726 // std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl;
1727 std::stringstream ss;
1728 ss << key_pressed;
1729 key = ss.str();
1730 }
1731 return true;
1732 }
1733 else {
1734 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1735 }
1736 // return false; // Never reached after throw()
1737}
1738
1750{
1751 bool ret = false;
1752
1754 ret = m_impl->getPointerMotionEvent(ip, m_scale);
1755 }
1756
1757 else {
1758 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1759 }
1760 return ret;
1761}
1762
1774{
1776 m_impl->getPointerPosition(ip, m_scale);
1777 return false;
1778 }
1779 else {
1780 throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1781 }
1782}
1783
1789void vpDisplayOpenCV::getScreenSize(unsigned int &w, unsigned int &h)
1790{
1791 w = h = 0;
1792
1793#if defined(VISP_HAVE_X11)
1794 vpDisplayX d;
1795 d.getScreenSize(w, h);
1796#elif defined(VISP_HAVE_XRANDR)
1797 std::string command = "xrandr | grep '*'";
1798 FILE *fpipe = (FILE *)popen(command.c_str(), "r");
1799 char line[256];
1800 while (fgets(line, sizeof(line), fpipe)) {
1801 std::string str(line);
1802 std::size_t found = str.find("Failed");
1803
1804 if (found == std::string::npos) {
1805 std::vector<std::string> elm;
1806 elm = vpIoTools::splitChain(str, " ");
1807 for (size_t i = 0; i < elm.size(); i++) {
1808 if (!elm[i].empty()) {
1809 std::vector<std::string> resolution = vpIoTools::splitChain(elm[i], "x");
1810 if (resolution.size() == 2) {
1811 std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
1812 sswidth >> w;
1813 ssheight >> h;
1814 break;
1815 }
1816 }
1817 }
1818 }
1819 }
1820 pclose(fpipe);
1821#elif defined(_WIN32)
1822#if !defined(WINRT)
1823 w = static_cast<unsigned int>(GetSystemMetrics(SM_CXSCREEN));
1824 h = static_cast<unsigned int>(GetSystemMetrics(SM_CYSCREEN));
1825#else
1826 throw(vpException(vpException::functionNotImplementedError, "The function vpDisplayOpenCV::getScreenSize() is not "
1827 "implemented on winrt"));
1828#endif
1829#endif
1830}
1831
1836{
1837 unsigned int width, height;
1838 getScreenSize(width, height);
1839 return width;
1840}
1841
1846{
1847 unsigned int width, height;
1848 getScreenSize(width, height);
1849 return height;
1850}
1851
1852END_VISP_NAMESPACE
1853
1854#elif !defined(VISP_BUILD_SHARED_LIBS)
1855// Work around to avoid warning: libvisp_gui.a(vpDisplayOpenCV.cpp.o) has no symbols
1856void dummy_vpDisplayOpenCV() { }
1857#endif
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor white
Definition vpColor.h:193
static const vpColor red
Definition vpColor.h:198
static const vpColor darkGray
Definition vpColor.h:196
static const vpColor cyan
Definition vpColor.h:207
static const vpColor orange
Definition vpColor.h:208
static const vpColor darkRed
Definition vpColor.h:199
static const vpColor blue
Definition vpColor.h:204
static const vpColor lightGray
Definition vpColor.h:194
static const vpColor lightBlue
Definition vpColor.h:203
static const vpColor darkGreen
Definition vpColor.h:202
static const vpColor darkBlue
Definition vpColor.h:205
static const vpColor purple
Definition vpColor.h:209
static const vpColor lightGreen
Definition vpColor.h:200
static const vpColor yellow
Definition vpColor.h:206
@ id_lightBlue
Definition vpColor.h:173
@ id_yellow
Definition vpColor.h:176
@ id_darkGray
Definition vpColor.h:166
@ id_green
Definition vpColor.h:171
@ id_darkRed
Definition vpColor.h:169
@ id_lightGray
Definition vpColor.h:164
@ id_red
Definition vpColor.h:168
@ id_lightRed
Definition vpColor.h:167
@ id_white
Definition vpColor.h:163
@ id_black
Definition vpColor.h:162
@ id_blue
Definition vpColor.h:174
@ id_darkGreen
Definition vpColor.h:172
@ id_gray
Definition vpColor.h:165
@ id_lightGreen
Definition vpColor.h:170
@ id_purple
Definition vpColor.h:179
@ id_orange
Definition vpColor.h:178
@ id_cyan
Definition vpColor.h:177
@ id_darkBlue
Definition vpColor.h:175
@ id_unknown
Definition vpColor.h:181
static const vpColor lightRed
Definition vpColor.h:197
static const vpColor black
Definition vpColor.h:192
static const vpColor green
Definition vpColor.h:201
static const vpColor gray
Definition vpColor.h:195
Error that can be emitted by the vpDisplay class and its derivatives.
@ notInitializedError
Display not initialized.
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1) VP_OVERRIDE
vpDisplayOpenCV & operator=(const vpDisplayOpenCV &display)
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE
virtual ~vpDisplayOpenCV() VP_OVERRIDE
bool getKeyboardEvent(bool blocking=true) VP_OVERRIDE
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1) VP_OVERRIDE
void setFont(const std::string &font) VP_OVERRIDE
void getImage(vpImage< vpRGBa > &I) VP_OVERRIDE
Get the window pixmap and put it in vpRGBa image.
void flushDisplay() VP_OVERRIDE
void getScreenSize(unsigned int &width, unsigned int &height) VP_OVERRIDE
void clearDisplay(const vpColor &color=vpColor::white) VP_OVERRIDE
bool getPointerMotionEvent(vpImagePoint &ip) VP_OVERRIDE
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1) VP_OVERRIDE
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) VP_OVERRIDE
unsigned int getScreenWidth() VP_OVERRIDE
void setTitle(const std::string &title) VP_OVERRIDE
void setWindowPosition(int winx, int winy) VP_OVERRIDE
void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1) VP_OVERRIDE
void closeDisplay() VP_OVERRIDE
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1) VP_OVERRIDE
void displayImage(const vpImage< unsigned char > &I) VP_OVERRIDE
bool getPointerPosition(vpImagePoint &ip) VP_OVERRIDE
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color=vpColor::green) VP_OVERRIDE
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true) VP_OVERRIDE
bool getClick(bool blocking=true) VP_OVERRIDE
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1) VP_OVERRIDE
unsigned int getScreenHeight() VP_OVERRIDE
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height) VP_OVERRIDE
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:135
unsigned int m_height
Definition vpDisplay.h:928
vpScaleType m_scaleType
Definition vpDisplay.h:931
unsigned int m_width
Definition vpDisplay.h:927
static void display(const vpImage< unsigned char > &I)
int m_windowXPosition
display position
Definition vpDisplay.h:924
std::string m_title
Definition vpDisplay.h:929
int m_windowYPosition
display position
Definition vpDisplay.h:926
unsigned int m_scale
Definition vpDisplay.h:930
bool m_displayHasBeenInitialized
display has been initialized
Definition vpDisplay.h:922
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ functionNotImplementedError
Function not implemented.
Definition vpException.h:66
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_j(double jj)
double get_j() const
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
void set_i(double ii)
double get_u() const
void set_u(double u)
void set_v(double v)
double get_i() const
double get_v() const
Definition of the vpImage class member functions.
Definition vpImage.h:131
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
static double sqr(double x)
Definition vpMath.h:203
static int round(double x)
Definition vpMath.h:413
unsigned char B
Blue component.
Definition vpRGBa.h:327
unsigned char R
Red component.
Definition vpRGBa.h:325
unsigned char G
Green component.
Definition vpRGBa.h:326
Defines a rectangle in the plane.
Definition vpRect.h:79
double getWidth() const
Definition vpRect.h:227
vpImagePoint getTopLeft() const
Definition vpRect.h:199
double getHeight() const
Definition vpRect.h:166