Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpDisplayOpenCV.cpp
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  * Fabien Spindler
38  *
39  *****************************************************************************/
40 
46 #include <visp3/core/vpConfig.h>
47 
48 #if defined(VISP_HAVE_OPENCV)
49 
50 #include <cmath> // std::fabs
51 #include <iostream>
52 #include <limits> // numeric_limits
53 #include <stdio.h>
54 #include <stdlib.h>
55 
56 // Display stuff
57 #include <visp3/core/vpDisplay.h>
58 #include <visp3/core/vpImageTools.h>
59 #include <visp3/core/vpIoTools.h>
60 #include <visp3/core/vpMath.h>
61 #include <visp3/gui/vpDisplayOpenCV.h>
62 
63 // debug / exception
64 #include <visp3/core/vpDebug.h>
65 #include <visp3/core/vpDisplayException.h>
66 
67 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
68 
69 #include <opencv2/core/core_c.h> // for CV_FILLED versus cv::FILLED
70 #include <opencv2/imgproc/imgproc.hpp>
71 
72 #ifndef CV_RGB
73 #define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)
74 #endif
75 #endif
76 
77 #ifdef VISP_HAVE_X11
78 #include <visp3/gui/vpDisplayX.h> // to get screen resolution
79 #elif defined(_WIN32)
80 #include <windows.h>
81 #endif
82 
83 std::vector<std::string> vpDisplayOpenCV::m_listTitles = std::vector<std::string>();
84 unsigned int vpDisplayOpenCV::m_nbWindows = 0;
85 
108  : vpDisplay(),
109 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
110  m_background(NULL), col(NULL), cvcolor(), font(NULL),
111 #else
112  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
113 #endif
114  fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
115  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
116  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
117  y_rbuttonup(0), rbuttonup(false)
118 {
119  setScale(scaleType, I.getWidth(), I.getHeight());
120  init(I);
121 }
122 
146 vpDisplayOpenCV::vpDisplayOpenCV(vpImage<unsigned char> &I, int x, int y, const std::string &title,
147  vpScaleType scaleType)
148  : vpDisplay(),
149 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
150  m_background(NULL), col(NULL), cvcolor(), font(NULL),
151 #else
152  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
153 #endif
154  fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
155  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
156  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
157  y_rbuttonup(0), rbuttonup(false)
158 {
159  setScale(scaleType, I.getWidth(), I.getHeight());
160  init(I, x, y, title);
161 }
162 
182  :
183 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
184  m_background(NULL), col(NULL), cvcolor(), font(NULL),
185 #else
186  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
187 #endif
188  fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
189  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
190  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
191  y_rbuttonup(0), rbuttonup(false)
192 {
193  setScale(scaleType, I.getWidth(), I.getHeight());
194  init(I);
195 }
196 
217 vpDisplayOpenCV::vpDisplayOpenCV(vpImage<vpRGBa> &I, int x, int y, const std::string &title, vpScaleType scaleType)
218  :
219 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
220  m_background(NULL), col(NULL), cvcolor(), font(NULL),
221 #else
222  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
223 #endif
224  fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
225  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
226  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
227  y_rbuttonup(0), rbuttonup(false)
228 {
229  setScale(scaleType, I.getWidth(), I.getHeight());
230  init(I, x, y, title);
231 }
232 
255 vpDisplayOpenCV::vpDisplayOpenCV(int x, int y, const std::string &title)
256  :
257 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
258  m_background(NULL), col(NULL), cvcolor(), font(NULL),
259 #else
260  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
261 #endif
262  fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
263  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
264  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
265  y_rbuttonup(0), rbuttonup(false)
266 {
267  m_windowXPosition = x;
268  m_windowYPosition = y;
269 
270  if (!title.empty()) {
271  m_title = title;
272  } else {
273  std::ostringstream s;
274  s << m_nbWindows++;
275  m_title = std::string("Window ") + s.str();
276  }
277 
278  bool isInList;
279  do {
280  isInList = false;
281  for (size_t i = 0; i < m_listTitles.size(); i++) {
282  if (m_listTitles[i] == m_title) {
283  std::ostringstream s;
284  s << m_nbWindows++;
285  m_title = std::string("Window ") + s.str();
286  isInList = true;
287  break;
288  }
289  }
290  } while (isInList);
291 
292  m_listTitles.push_back(m_title);
293 }
294 
315  :
316 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
317  m_background(NULL), col(NULL), cvcolor(), font(NULL),
318 #else
319  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
320 #endif
321  fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
322  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
323  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
324  y_rbuttonup(0), rbuttonup(false)
325 {
326 }
327 
332 {
333  closeDisplay();
334 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
335  cvReleaseImage(&m_background);
336 #endif
337 }
338 
347 void vpDisplayOpenCV::init(vpImage<unsigned char> &I, int x, int y, const std::string &title)
348 {
349  if ((I.getHeight() == 0) || (I.getWidth() == 0)) {
350  throw(vpDisplayException(vpDisplayException::notInitializedError, "Image not initialized"));
351  }
353  init(I.getWidth(), I.getHeight(), x, y, title);
354  I.display = this;
356 }
357 
367 void vpDisplayOpenCV::init(vpImage<vpRGBa> &I, int x, int y, const std::string &title)
368 {
369  if ((I.getHeight() == 0) || (I.getWidth() == 0)) {
370  throw(vpDisplayException(vpDisplayException::notInitializedError, "Image not initialized"));
371  }
372 
374  init(I.getWidth(), I.getHeight(), x, y, title);
375  I.display = this;
377 }
378 
389 void vpDisplayOpenCV::init(unsigned int w, unsigned int h, int x, int y, const std::string &title)
390 {
391  setScale(m_scaleType, w, h);
392 
393  this->m_width = w / m_scale;
394  this->m_height = h / m_scale;
395 
396  if (x != -1)
397  this->m_windowXPosition = x;
398  if (y != -1)
399  this->m_windowYPosition = y;
400 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
401  int flags = CV_WINDOW_AUTOSIZE;
402 #else
403  int flags = cv::WINDOW_AUTOSIZE;
404 #endif
405 
406  if (m_title.empty()) {
407  if (!title.empty()) {
408  m_title = std::string(title);
409  } else {
410 
411  std::ostringstream s;
412  s << m_nbWindows++;
413  m_title = std::string("Window ") + s.str();
414  }
415 
416  bool isInList;
417  do {
418  isInList = false;
419  for (size_t i = 0; i < m_listTitles.size(); i++) {
420  if (m_listTitles[i] == m_title) {
421  std::ostringstream s;
422  s << m_nbWindows++;
423  m_title = std::string("Window ") + s.str();
424  isInList = true;
425  break;
426  }
427  }
428  } while (isInList);
429 
430  m_listTitles.push_back(m_title);
431  }
432 
433 /* Create the window*/
434 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
435  if (cvNamedWindow(this->m_title.c_str(), flags) < 0) {
436  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV was not built with a display device"));
437  }
438 #else
439  cv::namedWindow(this->m_title, flags);
440 #endif
441 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
442  cvMoveWindow(this->m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition);
443 #else
444  cv::moveWindow(this->m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition);
445 #endif
446  move = false;
447  lbuttondown = false;
448  mbuttondown = false;
449  rbuttondown = false;
450  lbuttonup = false;
451  mbuttonup = false;
452  rbuttonup = false;
453 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
454  cvSetMouseCallback(this->m_title.c_str(), on_mouse, this);
455  col = new CvScalar[vpColor::id_unknown];
456 #else
457  cv::setMouseCallback(this->m_title, on_mouse, this);
458  col = new cv::Scalar[vpColor::id_unknown];
459 #endif
460 
461  /* Create color */
462  vpColor pcolor; // Predefined colors
463  pcolor = vpColor::lightBlue;
464  col[vpColor::id_lightBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
465  pcolor = vpColor::blue;
466  col[vpColor::id_blue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
467  pcolor = vpColor::darkBlue;
468  col[vpColor::id_darkBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
469  pcolor = vpColor::lightRed;
470  col[vpColor::id_lightRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
471  pcolor = vpColor::red;
472  col[vpColor::id_red] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
473  pcolor = vpColor::darkRed;
474  col[vpColor::id_darkRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
475  pcolor = vpColor::lightGreen;
476  col[vpColor::id_lightGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
477  pcolor = vpColor::green;
478  col[vpColor::id_green] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
479  pcolor = vpColor::darkGreen;
480  col[vpColor::id_darkGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
481  pcolor = vpColor::yellow;
482  col[vpColor::id_yellow] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
483  pcolor = vpColor::cyan;
484  col[vpColor::id_cyan] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
485  pcolor = vpColor::orange;
486  col[vpColor::id_orange] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
487  pcolor = vpColor::purple;
488  col[vpColor::id_purple] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
489  pcolor = vpColor::white;
490  col[vpColor::id_white] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
491  pcolor = vpColor::black;
492  col[vpColor::id_black] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
493  pcolor = vpColor::lightGray;
494  col[vpColor::id_lightGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
495  pcolor = vpColor::gray;
496  col[vpColor::id_gray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
497  pcolor = vpColor::darkGray;
498  col[vpColor::id_darkGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B);
499 
500 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
501  font = new CvFont;
502  cvInitFont(font, CV_FONT_HERSHEY_PLAIN, 0.70f, 0.70f);
503  CvSize fontSize;
504  int baseline;
505  cvGetTextSize("A", font, &fontSize, &baseline);
506 #else
507  int thickness = 1;
508  cv::Size fontSize;
509  int baseline;
510  fontSize = cv::getTextSize("A", font, fontScale, thickness, &baseline);
511 #endif
512 
513  fontHeight = fontSize.height + baseline;
515 }
516 
532 void vpDisplayOpenCV::setFont(const std::string & /* font */) { vpERROR_TRACE("Not yet implemented"); }
533 
541 void vpDisplayOpenCV::setTitle(const std::string & /* title */)
542 {
543  // static bool warn_displayed = false;
544  // if (! warn_displayed) {
545  // vpTRACE("Not implemented");
546  // warn_displayed = true;
547  // }
548 }
549 
559 void vpDisplayOpenCV::setWindowPosition(int winx, int winy)
560 {
562  this->m_windowXPosition = winx;
563  this->m_windowYPosition = winy;
564 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
565  cvMoveWindow(this->m_title.c_str(), winx, winy);
566 #else
567  cv::moveWindow(this->m_title.c_str(), winx, winy);
568 #endif
569  } else {
570  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
571  }
572 }
585 {
587 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
588  int depth = 8;
589  int channels = 3;
590  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
591  if (m_background != NULL) {
592  if (m_background->nChannels != channels || m_background->depth != depth ||
593  m_background->height != (int)m_height || m_background->width != (int)m_width) {
594  if (m_background->nChannels != 0)
595  cvReleaseImage(&m_background);
596  m_background = cvCreateImage(size, depth, channels);
597  }
598  } else {
599  m_background = cvCreateImage(size, depth, channels);
600  }
601 
602  if (m_scale == 1) {
603  for (unsigned int i = 0; i < m_height; i++) {
604  unsigned char *dst_24 = (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep);
605  for (unsigned int j = 0; j < m_width; j++) {
606  unsigned char val = I[i][j];
607  *(dst_24++) = val;
608  *(dst_24++) = val;
609  *(dst_24++) = val;
610  }
611  }
612  } else {
613  for (unsigned int i = 0; i < m_height; i++) {
614  unsigned char *dst_24 = (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep);
615  for (unsigned int j = 0; j < m_width; j++) {
616  unsigned char val = I[i * m_scale][j * m_scale];
617  *(dst_24++) = val;
618  *(dst_24++) = val;
619  *(dst_24++) = val;
620  }
621  }
622  }
623 
624 #else
625  int depth = CV_8U;
626  int channels = 3;
627  cv::Size size((int)m_width, (int)m_height);
628  if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
629  m_background.cols != (int)m_width) {
630  m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
631  }
632 
633  if (m_scale == 1) {
634  for (unsigned int i = 0; i < m_height; i++) {
635  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width);
636  for (unsigned int j = 0; j < m_width; j++) {
637  unsigned char val = I[i][j];
638  *(dst_24++) = val;
639  *(dst_24++) = val;
640  *(dst_24++) = val;
641  }
642  }
643  } else {
644  for (unsigned int i = 0; i < m_height; i++) {
645  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width);
646  for (unsigned int j = 0; j < m_width; j++) {
647  unsigned char val = I[i * m_scale][j * m_scale];
648  *(dst_24++) = val;
649  *(dst_24++) = val;
650  *(dst_24++) = val;
651  }
652  }
653  }
654 #endif
655 
656  } else {
657  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
658  }
659 }
660 
677  unsigned int h)
678 {
680 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
681  int depth = 8;
682  int channels = 3;
683  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
684  if (m_background != NULL) {
685  if (m_background->nChannels != channels || m_background->depth != depth ||
686  m_background->height != (int)m_height || m_background->width != (int)m_width) {
687  if (m_background->nChannels != 0)
688  cvReleaseImage(&m_background);
689  m_background = cvCreateImage(size, depth, channels);
690  }
691  } else {
692  m_background = cvCreateImage(size, depth, channels);
693  }
694 
695  if (m_scale == 1) {
696  unsigned int i_min = (unsigned int)iP.get_i();
697  unsigned int j_min = (unsigned int)iP.get_j();
698  unsigned int i_max = (std::min)(i_min + h, m_height);
699  unsigned int j_max = (std::min)(j_min + w, m_width);
700  for (unsigned int i = i_min; i < i_max; i++) {
701  unsigned char *dst_24 =
702  (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep + j_min * 3);
703  for (unsigned int j = j_min; j < j_max; j++) {
704  unsigned char val = I[i][j];
705  *(dst_24++) = val;
706  *(dst_24++) = val;
707  *(dst_24++) = val;
708  }
709  }
710  } else {
711  int i_min = (std::max)((int)ceil(iP.get_i() / m_scale), 0);
712  int j_min = (std::max)((int)ceil(iP.get_j() / m_scale), 0);
713  int i_max = (std::min)((int)ceil((iP.get_i() + h) / m_scale), (int)m_height);
714  int j_max = (std::min)((int)ceil((iP.get_j() + w) / m_scale), (int)m_width);
715  for (int i = i_min; i < i_max; i++) {
716  unsigned char *dst_24 =
717  (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep + j_min * 3);
718  for (int j = j_min; j < j_max; j++) {
719  unsigned char val = I[i * m_scale][j * m_scale];
720  *(dst_24++) = val;
721  *(dst_24++) = val;
722  *(dst_24++) = val;
723  }
724  }
725  }
726 
727 #else
728  int depth = CV_8U;
729  int channels = 3;
730  cv::Size size((int)m_width, (int)m_height);
731  if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
732  m_background.cols != (int)m_width) {
733  m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
734  }
735 
736  if (m_scale == 1) {
737  unsigned int i_min = (unsigned int)iP.get_i();
738  unsigned int j_min = (unsigned int)iP.get_j();
739  unsigned int i_max = (std::min)(i_min + h, m_height);
740  unsigned int j_max = (std::min)(j_min + w, m_width);
741  for (unsigned int i = i_min; i < i_max; i++) {
742  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3);
743  for (unsigned int j = j_min; j < j_max; j++) {
744  unsigned char val = I[i][j];
745  *(dst_24++) = val;
746  *(dst_24++) = val;
747  *(dst_24++) = val;
748  }
749  }
750  } else {
751  int i_min = (std::max)((int)ceil(iP.get_i() / m_scale), 0);
752  int j_min = (std::max)((int)ceil(iP.get_j() / m_scale), 0);
753  int i_max = (std::min)((int)ceil((iP.get_i() + h) / m_scale), (int)m_height);
754  int j_max = (std::min)((int)ceil((iP.get_j() + w) / m_scale), (int)m_width);
755  for (int i = i_min; i < i_max; i++) {
756  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3);
757  for (int j = j_min; j < j_max; j++) {
758  unsigned char val = I[i * m_scale][j * m_scale];
759  *(dst_24++) = val;
760  *(dst_24++) = val;
761  *(dst_24++) = val;
762  }
763  }
764  }
765 #endif
766  } else {
767  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
768  }
769 }
770 
783 {
784 
786 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
787  int depth = 8;
788  int channels = 3;
789  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
790  if (m_background != NULL) {
791  if (m_background->nChannels != channels || m_background->depth != depth ||
792  m_background->height != (int)m_height || m_background->width != (int)m_width) {
793  if (m_background->nChannels != 0)
794  cvReleaseImage(&m_background);
795  m_background = cvCreateImage(size, depth, channels);
796  }
797  } else {
798  m_background = cvCreateImage(size, depth, channels);
799  }
800 
801  if (m_scale == 1) {
802  for (unsigned int i = 0; i < m_height; i++) {
803  unsigned char *dst_24 = (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep);
804  for (unsigned int j = 0; j < m_width; j++) {
805  vpRGBa val = I[i][j];
806  *(dst_24++) = val.B;
807  *(dst_24++) = val.G;
808  *(dst_24++) = val.R;
809  }
810  }
811  } else {
812  for (unsigned int i = 0; i < m_height; i++) {
813  unsigned char *dst_24 = (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep);
814  for (unsigned int j = 0; j < m_width; j++) {
815  vpRGBa val = I[i * m_scale][j * m_scale];
816  *(dst_24++) = val.B;
817  *(dst_24++) = val.G;
818  *(dst_24++) = val.R;
819  }
820  }
821  }
822 #else
823  int depth = CV_8U;
824  int channels = 3;
825  cv::Size size((int)this->m_width, (int)this->m_height);
826  if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
827  m_background.cols != (int)m_width) {
828  m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
829  }
830 
831  if (m_scale == 1) {
832  for (unsigned int i = 0; i < m_height; i++) {
833  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width);
834  for (unsigned int j = 0; j < m_width; j++) {
835  vpRGBa val = I[i][j];
836  *(dst_24++) = val.B;
837  *(dst_24++) = val.G;
838  *(dst_24++) = val.R;
839  }
840  }
841  } else {
842  for (unsigned int i = 0; i < m_height; i++) {
843  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width);
844  for (unsigned int j = 0; j < m_width; j++) {
845  vpRGBa val = I[i * m_scale][j * m_scale];
846  *(dst_24++) = val.B;
847  *(dst_24++) = val.G;
848  *(dst_24++) = val.R;
849  }
850  }
851  }
852 #endif
853  } else {
854  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
855  }
856 }
857 
873 void vpDisplayOpenCV::displayImageROI(const vpImage<vpRGBa> &I, const vpImagePoint &iP, unsigned int w,
874  unsigned int h)
875 {
877 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
878  int depth = 8;
879  int channels = 3;
880  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
881  if (m_background != NULL) {
882  if (m_background->nChannels != channels || m_background->depth != depth ||
883  m_background->height != (int)m_height || m_background->width != (int)m_width) {
884  if (m_background->nChannels != 0)
885  cvReleaseImage(&m_background);
886  m_background = cvCreateImage(size, depth, channels);
887  }
888  } else {
889  m_background = cvCreateImage(size, depth, channels);
890  }
891 
892  if (m_scale == 1) {
893  unsigned int i_min = (unsigned int)iP.get_i();
894  unsigned int j_min = (unsigned int)iP.get_j();
895  unsigned int i_max = (std::min)(i_min + h, m_height);
896  unsigned int j_max = (std::min)(j_min + w, m_width);
897  for (unsigned int i = i_min; i < i_max; i++) {
898  unsigned char *dst_24 =
899  (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep + j_min * 3);
900  for (unsigned int j = j_min; j < j_max; j++) {
901  vpRGBa val = I[i][j];
902  *(dst_24++) = val.B;
903  *(dst_24++) = val.G;
904  *(dst_24++) = val.R;
905  }
906  }
907  } else {
908  int i_min = (std::max)((int)ceil(iP.get_i() / m_scale), 0);
909  int j_min = (std::max)((int)ceil(iP.get_j() / m_scale), 0);
910  int i_max = (std::min)((int)ceil((iP.get_i() + h) / m_scale), (int)m_height);
911  int j_max = (std::min)((int)ceil((iP.get_j() + w) / m_scale), (int)m_width);
912  for (int i = i_min; i < i_max; i++) {
913  unsigned char *dst_24 =
914  (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep + j_min * 3);
915  for (int j = j_min; j < j_max; j++) {
916  vpRGBa val = I[i * m_scale][j * m_scale];
917  *(dst_24++) = val.B;
918  *(dst_24++) = val.G;
919  *(dst_24++) = val.R;
920  }
921  }
922  }
923 #else
924  int depth = CV_8U;
925  int channels = 3;
926  cv::Size size((int)this->m_width, (int)this->m_height);
927  if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
928  m_background.cols != (int)m_width) {
929  m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
930  }
931 
932  if (m_scale == 1) {
933  unsigned int i_min = (unsigned int)iP.get_i();
934  unsigned int j_min = (unsigned int)iP.get_j();
935  unsigned int i_max = (std::min)(i_min + h, m_height);
936  unsigned int j_max = (std::min)(j_min + w, m_width);
937  for (unsigned int i = i_min; i < i_max; i++) {
938  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3);
939  for (unsigned int j = j_min; j < j_max; j++) {
940  vpRGBa val = I[i][j];
941  *(dst_24++) = val.B;
942  *(dst_24++) = val.G;
943  *(dst_24++) = val.R;
944  }
945  }
946  } else {
947  int i_min = (std::max)((int)ceil(iP.get_i() / m_scale), 0);
948  int j_min = (std::max)((int)ceil(iP.get_j() / m_scale), 0);
949  int i_max = (std::min)((int)ceil((iP.get_i() + h) / m_scale), (int)m_height);
950  int j_max = (std::min)((int)ceil((iP.get_j() + w) / m_scale), (int)m_width);
951  for (int i = i_min; i < i_max; i++) {
952  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3);
953  for (int j = j_min; j < j_max; j++) {
954  vpRGBa val = I[i * m_scale][j * m_scale];
955  *(dst_24++) = val.B;
956  *(dst_24++) = val.G;
957  *(dst_24++) = val.R;
958  }
959  }
960  }
961 #endif
962  } else {
963  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
964  }
965 }
966 
972 void vpDisplayOpenCV::displayImage(const unsigned char * /* I */) { vpTRACE(" not implemented "); }
973 
982 {
983  if (col != NULL) {
984  delete[] col;
985  col = NULL;
986  }
987 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
988  if (font != NULL) {
989  delete font;
990  font = NULL;
991  }
992 #endif
994 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
995  cvDestroyWindow(this->m_title.c_str());
996 #else
997  cv::destroyWindow(this->m_title);
998 #endif
999 
1000  for (size_t i = 0; i < m_listTitles.size(); i++) {
1001  if (m_title == m_listTitles[i]) {
1002  m_listTitles.erase(m_listTitles.begin() + (long int)i);
1003  break;
1004  }
1005  }
1006 
1007  m_title.clear();
1008 
1010  }
1011 }
1012 
1019 {
1021 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1022  cvShowImage(this->m_title.c_str(), m_background);
1023  cvWaitKey(5);
1024 #else
1025  cv::imshow(this->m_title, m_background);
1026  cv::waitKey(5);
1027 #endif
1028  } else {
1029  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1030  }
1031 }
1032 
1038 void vpDisplayOpenCV::flushDisplayROI(const vpImagePoint & /*iP*/, const unsigned int /*width*/,
1039  const unsigned int /*height*/)
1040 {
1042 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1043  cvShowImage(this->m_title.c_str(), m_background);
1044  cvWaitKey(5);
1045 #else
1046  cv::imshow(this->m_title.c_str(), m_background);
1047  cv::waitKey(5);
1048 #endif
1049  } else {
1050  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1051  }
1052 }
1053 
1057 void vpDisplayOpenCV::clearDisplay(const vpColor & /* color */)
1058 {
1059  static bool warn_displayed = false;
1060  if (!warn_displayed) {
1061  vpTRACE("Not implemented");
1062  warn_displayed = true;
1063  }
1064 }
1065 
1073 void vpDisplayOpenCV::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1074  unsigned int w, unsigned int h, unsigned int thickness)
1075 {
1077  double a = ip2.get_i() - ip1.get_i();
1078  double b = ip2.get_j() - ip1.get_j();
1079  double lg = sqrt(vpMath::sqr(a) + vpMath::sqr(b));
1080 
1081  // if ((a==0)&&(b==0))
1082  if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
1083  (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
1084  // DisplayCrossLarge(i1,j1,3,col) ;
1085  } else {
1086  a /= lg;
1087  b /= lg;
1088 
1089  vpImagePoint ip3;
1090  ip3.set_i(ip2.get_i() - w * a);
1091  ip3.set_j(ip2.get_j() - w * b);
1092 
1093  vpImagePoint ip4;
1094  ip4.set_i(ip3.get_i() - b * h);
1095  ip4.set_j(ip3.get_j() + a * h);
1096 
1097  if (lg > 2 * vpImagePoint::distance(ip2, ip4))
1098  displayLine(ip2, ip4, color, thickness);
1099 
1100  ip4.set_i(ip3.get_i() + b * h);
1101  ip4.set_j(ip3.get_j() - a * h);
1102 
1103  if (lg > 2 * vpImagePoint::distance(ip2, ip4))
1104  displayLine(ip2, ip4, color, thickness);
1105 
1106  displayLine(ip1, ip2, color, thickness);
1107  }
1108  } else {
1109  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1110  }
1111 }
1112 
1124 void vpDisplayOpenCV::displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color)
1125 {
1127  if (color.id < vpColor::id_unknown) {
1128 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1129  cvPutText(m_background, text,
1130  cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), font,
1131  col[color.id]);
1132 #else
1133  cv::putText(m_background, text,
1134  cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)),
1135  font, fontScale, col[color.id]);
1136 #endif
1137  } else {
1138  cvcolor = CV_RGB(color.R, color.G, color.B);
1139 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1140  cvPutText(m_background, text,
1141  cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), font,
1142  cvcolor);
1143 #else
1144  cv::putText(m_background, text,
1145  cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)),
1146  font, fontScale, cvcolor);
1147 #endif
1148  }
1149  } else {
1150  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1151  }
1152 }
1162 void vpDisplayOpenCV::displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill,
1163  unsigned int thickness)
1164 {
1166  if (fill == false) {
1167  if (color.id < vpColor::id_unknown) {
1168 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1169  cvCircle(m_background,
1170  cvPoint(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1171  (int)radius / m_scale, col[color.id], (int)thickness);
1172 #else
1173  cv::circle(m_background,
1174  cv::Point(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1175  (int)radius / m_scale, col[color.id], (int)thickness);
1176 #endif
1177  } else {
1178  cvcolor = CV_RGB(color.R, color.G, color.B);
1179 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1180  cvCircle(m_background,
1181  cvPoint(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1182  (int)radius / m_scale, cvcolor, (int)thickness);
1183 #else
1184  cv::circle(m_background,
1185  cv::Point(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1186  (int)radius / m_scale, cvcolor, (int)thickness);
1187 #endif
1188  }
1189  } else {
1190 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1191  int filled = cv::FILLED;
1192 #else
1193  int filled = CV_FILLED;
1194 #endif
1195  if (color.id < vpColor::id_unknown) {
1196 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1197  cvCircle(m_background,
1198  cvPoint(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1199  (int)radius / m_scale, col[color.id], filled);
1200 #else
1201  cv::circle(m_background,
1202  cv::Point(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1203  (int)radius / m_scale, col[color.id], filled);
1204 #endif
1205  } else {
1206  cvcolor = CV_RGB(color.R, color.G, color.B);
1207 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1208  cvCircle(m_background,
1209  cvPoint(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1210  (int)radius / m_scale, cvcolor, filled);
1211 #else
1212  cv::circle(m_background,
1213  cv::Point(vpMath::round(center.get_u() / m_scale), vpMath::round(center.get_v() / m_scale)),
1214  (int)radius / m_scale, cvcolor, filled);
1215 #endif
1216  }
1217  }
1218  } else {
1219  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1220  }
1221 }
1222 
1230 void vpDisplayOpenCV::displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color,
1231  unsigned int thickness)
1232 {
1234  vpImagePoint top, bottom, left, right;
1235  top.set_i(ip.get_i() - size / 2);
1236  top.set_j(ip.get_j());
1237  bottom.set_i(ip.get_i() + size / 2);
1238  bottom.set_j(ip.get_j());
1239  left.set_i(ip.get_i());
1240  left.set_j(ip.get_j() - size / 2);
1241  right.set_i(ip.get_i());
1242  right.set_j(ip.get_j() + size / 2);
1243  displayLine(top, bottom, color, thickness);
1244  displayLine(left, right, color, thickness);
1245  } else {
1246  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1247  }
1248 }
1249 
1257 void vpDisplayOpenCV::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1258  unsigned int thickness)
1259 {
1261  vpImagePoint ip1_ = ip1;
1262  vpImagePoint ip2_ = ip2;
1263 
1264  double size = 10. * m_scale;
1265  double length = sqrt(vpMath::sqr(ip2_.get_i() - ip1_.get_i()) + vpMath::sqr(ip2_.get_j() - ip1_.get_j()));
1266  bool vertical_line = (int)ip2_.get_j() == (int)ip1_.get_j();
1267  if (vertical_line) {
1268  if (ip2_.get_i() < ip1_.get_i()) {
1269  std::swap(ip1_, ip2_);
1270  }
1271  } else if (ip2_.get_j() < ip1_.get_j()) {
1272  std::swap(ip1_, ip2_);
1273  }
1274 
1275  double diff_j = vertical_line ? 1 : ip2_.get_j() - ip1_.get_j();
1276  double deltaj = size / length * diff_j;
1277  double deltai = size / length * (ip2_.get_i() - ip1_.get_i());
1278  double slope = (ip2_.get_i() - ip1_.get_i()) / diff_j;
1279  double orig = ip1_.get_i() - slope * ip1_.get_j();
1280 
1281  if (vertical_line) {
1282  for (unsigned int i = (unsigned int)ip1_.get_i(); i < ip2_.get_i(); i += (unsigned int)(2 * deltai)) {
1283  double j = ip1_.get_j();
1284  displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j), color, thickness);
1285  }
1286  } else {
1287  for (unsigned int j = (unsigned int)ip1_.get_j(); j < ip2_.get_j(); j += (unsigned int)(2 * deltaj)) {
1288  double i = slope * j + orig;
1289  displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j + deltaj), color, thickness);
1290  }
1291  }
1292  } else {
1293  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1294  }
1295 }
1296 
1303 void vpDisplayOpenCV::displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1304  unsigned int thickness)
1305 {
1307  if (color.id < vpColor::id_unknown) {
1308 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1309  cvLine(m_background, cvPoint(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1310  cvPoint(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id],
1311  (int)thickness);
1312 #else
1313  cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1314  cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id],
1315  (int)thickness);
1316 #endif
1317  } else {
1318  cvcolor = CV_RGB(color.R, color.G, color.B);
1319 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1320  cvLine(m_background, cvPoint(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1321  cvPoint(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), cvcolor,
1322  (int)thickness);
1323 #else
1324  cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1325  cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), cvcolor,
1326  (int)thickness);
1327 #endif
1328  }
1329  } else {
1330  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1331  }
1332 }
1333 
1340 void vpDisplayOpenCV::displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness)
1341 {
1343  for (unsigned int i = 0; i < thickness; i++) {
1344  if (color.id < vpColor::id_unknown) {
1345 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1346  cvLine(m_background, cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1347  cvPoint(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1348  col[color.id], (int)thickness);
1349 #else
1350  cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1351  cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1352  col[color.id], (int)thickness);
1353 #endif
1354  } else {
1355  cvcolor = CV_RGB(color.R, color.G, color.B);
1356 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1357  cvLine(m_background, cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1358  cvPoint(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1359  cvcolor, (int)thickness);
1360 #else
1361  cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1362  cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1363  cvcolor, (int)thickness);
1364 #endif
1365  }
1366  }
1367  } else {
1368  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1369  }
1370 }
1371 
1385 void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, unsigned int w, unsigned int h,
1386  const vpColor &color, bool fill, unsigned int thickness)
1387 {
1389  if (fill == false) {
1390  if (color.id < vpColor::id_unknown) {
1391 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1392  cvRectangle(
1393  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1394  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1395  col[color.id], (int)thickness);
1396 #else
1397  cv::rectangle(
1398  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1399  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1400  col[color.id], (int)thickness);
1401 #endif
1402  } else {
1403  cvcolor = CV_RGB(color.R, color.G, color.B);
1404 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1405  cvRectangle(
1406  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1407  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1408  cvcolor, (int)thickness);
1409 #else
1410  cv::rectangle(
1411  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1412  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1413  cvcolor, (int)thickness);
1414 #endif
1415  }
1416  } else {
1417 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1418  int filled = cv::FILLED;
1419 #else
1420  int filled = CV_FILLED;
1421 #endif
1422  if (color.id < vpColor::id_unknown) {
1423 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1424  cvRectangle(
1425  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1426  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1427  col[color.id], filled);
1428 #else
1429  cv::rectangle(
1430  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1431  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1432  col[color.id], filled);
1433 #endif
1434  } else {
1435  cvcolor = CV_RGB(color.R, color.G, color.B);
1436 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1437  cvRectangle(
1438  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1439  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1440  cvcolor, filled);
1441 #else
1442  cv::rectangle(
1443  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1444  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1445  cvcolor, filled);
1446 #endif
1447  }
1448  }
1449  } else {
1450  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1451  }
1452 }
1465 void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
1466  const vpColor &color, bool fill, unsigned int thickness)
1467 {
1469  if (fill == false) {
1470  if (color.id < vpColor::id_unknown) {
1471 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1472  cvRectangle(m_background,
1473  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1474  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1475  col[color.id], (int)thickness);
1476 #else
1477  cv::rectangle(
1478  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1479  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1480  col[color.id], (int)thickness);
1481 #endif
1482  } else {
1483  cvcolor = CV_RGB(color.R, color.G, color.B);
1484 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1485  cvRectangle(m_background,
1486  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1487  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1488  cvcolor, (int)thickness);
1489 #else
1490  cv::rectangle(
1491  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1492  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1493  cvcolor, (int)thickness);
1494 #endif
1495  }
1496  } else {
1497 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1498  int filled = cv::FILLED;
1499 #else
1500  int filled = CV_FILLED;
1501 #endif
1502  if (color.id < vpColor::id_unknown) {
1503 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1504  cvRectangle(m_background,
1505  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1506  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1507  col[color.id], filled);
1508 #else
1509  cv::rectangle(
1510  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1511  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1512  col[color.id], filled);
1513 #endif
1514  } else {
1515  cvcolor = CV_RGB(color.R, color.G, color.B);
1516 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1517  cvRectangle(m_background,
1518  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1519  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1520  cvcolor, filled);
1521 #else
1522  cv::rectangle(
1523  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1524  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1525  cvcolor, filled);
1526 #endif
1527  }
1528  }
1529  } else {
1530  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1531  }
1532 }
1533 
1545 void vpDisplayOpenCV::displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill, unsigned int thickness)
1546 {
1548  if (fill == false) {
1549  if (color.id < vpColor::id_unknown) {
1550 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1551  cvRectangle(
1552  m_background,
1553  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1554  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1555  col[color.id], (int)thickness);
1556 #else
1557  cv::rectangle(
1558  m_background,
1559  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1560  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1561  col[color.id], (int)thickness);
1562 #endif
1563  } else {
1564  cvcolor = CV_RGB(color.R, color.G, color.B);
1565 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1566  cvRectangle(
1567  m_background,
1568  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1569  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1570  cvcolor, (int)thickness);
1571 
1572 #else
1573  cv::rectangle(
1574  m_background,
1575  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1576  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1577  cvcolor, (int)thickness);
1578 
1579 #endif
1580  }
1581  } else {
1582 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1583  int filled = cv::FILLED;
1584 #else
1585  int filled = CV_FILLED;
1586 #endif
1587  if (color.id < vpColor::id_unknown) {
1588 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1589  cvRectangle(
1590  m_background,
1591  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1592  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1593  col[color.id], filled);
1594 #else
1595  cv::rectangle(
1596  m_background,
1597  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1598  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1599  col[color.id], filled);
1600 #endif
1601  } else {
1602  cvcolor = CV_RGB(color.R, color.G, color.B);
1603 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1604  cvRectangle(
1605  m_background,
1606  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1607  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1608  cvcolor, filled);
1609 #else
1610  cv::rectangle(
1611  m_background,
1612  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1613  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1614  cvcolor, filled);
1615 #endif
1616  }
1617  }
1618  } else {
1619  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1620  }
1621 }
1622 
1638 bool vpDisplayOpenCV::getClick(bool blocking)
1639 {
1640  bool ret = false;
1642  flushDisplay();
1643  if (blocking) {
1644  lbuttondown = false;
1645  mbuttondown = false;
1646  rbuttondown = false;
1647  }
1648  do {
1649  if (lbuttondown) {
1650  ret = true;
1651  lbuttondown = false;
1652  }
1653  if (mbuttondown) {
1654  ret = true;
1655  mbuttondown = false;
1656  }
1657  if (rbuttondown) {
1658  ret = true;
1659  rbuttondown = false;
1660  }
1661  if (blocking)
1662 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1663  cvWaitKey(10);
1664 #else
1665  cv::waitKey(10);
1666 #endif
1667  } while (ret == false && blocking == true);
1668  } else {
1669  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1670  }
1671  return ret;
1672 }
1673 
1689 bool vpDisplayOpenCV::getClick(vpImagePoint &ip, bool blocking)
1690 {
1691  bool ret = false;
1692 
1694  flushDisplay();
1695 
1696  double u, v;
1697 
1698  if (blocking) {
1699  lbuttondown = false;
1700  mbuttondown = false;
1701  rbuttondown = false;
1702  }
1703  do {
1704  if (lbuttondown) {
1705  ret = true;
1706  u = (unsigned int)x_lbuttondown * m_scale;
1707  v = (unsigned int)y_lbuttondown * m_scale;
1708  ip.set_u(u);
1709  ip.set_v(v);
1710  lbuttondown = false;
1711  }
1712  if (mbuttondown) {
1713  ret = true;
1714  u = (unsigned int)x_mbuttondown * m_scale;
1715  v = (unsigned int)y_mbuttondown * m_scale;
1716  ip.set_u(u);
1717  ip.set_v(v);
1718  mbuttondown = false;
1719  }
1720  if (rbuttondown) {
1721  ret = true;
1722  u = (unsigned int)x_rbuttondown * m_scale;
1723  v = (unsigned int)y_rbuttondown * m_scale;
1724  ip.set_u(u);
1725  ip.set_v(v);
1726  rbuttondown = false;
1727  }
1728  if (blocking)
1729 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1730  cvWaitKey(10);
1731 #else
1732  cv::waitKey(10);
1733 #endif
1734  } while (ret == false && blocking == true);
1735  } else {
1736  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1737  }
1738  return ret;
1739 }
1740 
1760 {
1761  bool ret = false;
1762 
1764  // flushDisplay() ;
1765  double u, v;
1766  if (blocking) {
1767  lbuttondown = false;
1768  mbuttondown = false;
1769  rbuttondown = false;
1770  }
1771  do {
1772  if (lbuttondown) {
1773  ret = true;
1774  u = (unsigned int)x_lbuttondown * m_scale;
1775  v = (unsigned int)y_lbuttondown * m_scale;
1776  ip.set_u(u);
1777  ip.set_v(v);
1778  button = vpMouseButton::button1;
1779  lbuttondown = false;
1780  }
1781  if (mbuttondown) {
1782  ret = true;
1783  u = (unsigned int)x_mbuttondown * m_scale;
1784  v = (unsigned int)y_mbuttondown * m_scale;
1785  ip.set_u(u);
1786  ip.set_v(v);
1787  button = vpMouseButton::button2;
1788  mbuttondown = false;
1789  }
1790  if (rbuttondown) {
1791  ret = true;
1792  u = (unsigned int)x_rbuttondown * m_scale;
1793  v = (unsigned int)y_rbuttondown * m_scale;
1794  ip.set_u(u);
1795  ip.set_v(v);
1796  button = vpMouseButton::button3;
1797  rbuttondown = false;
1798  }
1799  if (blocking)
1800 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1801  cvWaitKey(10);
1802 #else
1803  cv::waitKey(10);
1804 #endif
1805  } while (ret == false && blocking == true);
1806  } else {
1807  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1808  }
1809  return ret;
1810 }
1811 
1834 {
1835  bool ret = false;
1837  // flushDisplay() ;
1838  double u, v;
1839  if (blocking) {
1840  lbuttonup = false;
1841  mbuttonup = false;
1842  rbuttonup = false;
1843  }
1844  do {
1845  if (lbuttonup) {
1846  ret = true;
1847  u = (unsigned int)x_lbuttonup * m_scale;
1848  v = (unsigned int)y_lbuttonup * m_scale;
1849  ip.set_u(u);
1850  ip.set_v(v);
1851  button = vpMouseButton::button1;
1852  lbuttonup = false;
1853  }
1854  if (mbuttonup) {
1855  ret = true;
1856  u = (unsigned int)x_mbuttonup * m_scale;
1857  v = (unsigned int)y_mbuttonup * m_scale;
1858  ip.set_u(u);
1859  ip.set_v(v);
1860  button = vpMouseButton::button2;
1861  mbuttonup = false;
1862  }
1863  if (rbuttonup) {
1864  ret = true;
1865  u = (unsigned int)x_rbuttonup * m_scale;
1866  v = (unsigned int)y_rbuttonup * m_scale;
1867  ip.set_u(u);
1868  ip.set_v(v);
1869  button = vpMouseButton::button3;
1870  rbuttonup = false;
1871  }
1872  if (blocking)
1873 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1874  cvWaitKey(10);
1875 #else
1876  cv::waitKey(10);
1877 #endif
1878  } while (ret == false && blocking == true);
1879  } else {
1880  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1881  }
1882  return ret;
1883 }
1884 
1885 /*
1886  Gets the displayed image (including the overlay plane)
1887  and returns an RGBa image.
1888 */
1890 {
1891  vpImageConvert::convert(m_background, I);
1892  // should certainly be optimized.
1893 }
1894 
1895 void vpDisplayOpenCV::on_mouse(int event, int x, int y, int /*flags*/, void *display)
1896 {
1897  vpDisplayOpenCV *disp = static_cast<vpDisplayOpenCV *>(display);
1898  switch (event) {
1899 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1900  case CV_EVENT_MOUSEMOVE:
1901 #else
1902  case cv::EVENT_MOUSEMOVE:
1903 #endif
1904  {
1905  disp->move = true;
1906  disp->x_move = x;
1907  disp->y_move = y;
1908  break;
1909  }
1910 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1911  case CV_EVENT_LBUTTONDOWN:
1912 #else
1913  case cv::EVENT_LBUTTONDOWN:
1914 #endif
1915  {
1916  disp->lbuttondown = true;
1917  disp->x_lbuttondown = x;
1918  disp->y_lbuttondown = y;
1919  break;
1920  }
1921 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1922  case CV_EVENT_MBUTTONDOWN:
1923 #else
1924  case cv::EVENT_MBUTTONDOWN:
1925 #endif
1926  {
1927  disp->mbuttondown = true;
1928  disp->x_mbuttondown = x;
1929  disp->y_mbuttondown = y;
1930  break;
1931  }
1932 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1933  case CV_EVENT_RBUTTONDOWN:
1934 #else
1935  case cv::EVENT_RBUTTONDOWN:
1936 #endif
1937  {
1938  disp->rbuttondown = true;
1939  disp->x_rbuttondown = x;
1940  disp->y_rbuttondown = y;
1941  break;
1942  }
1943 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1944  case CV_EVENT_LBUTTONUP:
1945 #else
1946  case cv::EVENT_LBUTTONUP:
1947 #endif
1948  {
1949  disp->lbuttonup = true;
1950  disp->x_lbuttonup = x;
1951  disp->y_lbuttonup = y;
1952  break;
1953  }
1954 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1955  case CV_EVENT_MBUTTONUP:
1956 #else
1957  case cv::EVENT_MBUTTONUP:
1958 #endif
1959  {
1960  disp->mbuttonup = true;
1961  disp->x_mbuttonup = x;
1962  disp->y_mbuttonup = y;
1963  break;
1964  }
1965 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1966  case CV_EVENT_RBUTTONUP:
1967 #else
1968  case cv::EVENT_RBUTTONUP:
1969 #endif
1970  {
1971  disp->rbuttonup = true;
1972  disp->x_rbuttonup = x;
1973  disp->y_rbuttonup = y;
1974  break;
1975  }
1976 
1977  default:
1978  break;
1979  }
1980 }
1981 
1998 {
2000  int delay;
2001  flushDisplay();
2002  if (blocking)
2003  delay = 0;
2004  else
2005  delay = 10;
2006 
2007 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2008  int key_pressed = cvWaitKey(delay);
2009 #else
2010  int key_pressed = cv::waitKey(delay);
2011 #endif
2012 
2013  if (key_pressed == -1)
2014  return false;
2015  return true;
2016  } else {
2017  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2018  }
2019  // return false; // Never reached after throw()
2020 }
2039 bool vpDisplayOpenCV::getKeyboardEvent(std::string &key, bool blocking)
2040 {
2042  int delay;
2043  flushDisplay();
2044  if (blocking)
2045  delay = 0;
2046  else
2047  delay = 10;
2048 
2049 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2050  int key_pressed = cvWaitKey(delay);
2051 #else
2052  int key_pressed = cv::waitKey(delay);
2053 #endif
2054  if (key_pressed == -1)
2055  return false;
2056  else {
2057  // std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl;
2058  std::stringstream ss;
2059  ss << key_pressed;
2060  key = ss.str();
2061  }
2062  return true;
2063  } else {
2064  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2065  }
2066  // return false; // Never reached after throw()
2067 }
2068 
2080 {
2081  bool ret = false;
2082 
2084  // flushDisplay() ;
2085  if (move) {
2086  ret = true;
2087  double u = (unsigned int)x_move / m_scale;
2088  double v = (unsigned int)y_move / m_scale;
2089  ip.set_u(u);
2090  ip.set_v(v);
2091  move = false;
2092  }
2093  }
2094 
2095  else {
2096  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2097  }
2098  return ret;
2099 }
2100 
2112 {
2114  bool moved = getPointerMotionEvent(ip);
2115  if (!moved) {
2116  double u, v;
2117  u = (unsigned int)x_move / m_scale;
2118  v = (unsigned int)y_move / m_scale;
2119  ip.set_u(u);
2120  ip.set_v(v);
2121  }
2122  return false;
2123  } else {
2124  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2125  }
2126 }
2127 
2132 void vpDisplayOpenCV::getScreenSize(unsigned int &w, unsigned int &h)
2133 {
2134  w = h = 0;
2135 
2136 #if defined(VISP_HAVE_X11)
2137  vpDisplayX d;
2138  d.getScreenSize(w, h);
2139 #elif defined(VISP_HAVE_XRANDR)
2140  std::string command = "xrandr | grep '*'";
2141  FILE *fpipe = (FILE *)popen(command.c_str(), "r");
2142  char line[256];
2143  while (fgets(line, sizeof(line), fpipe)) {
2144  std::string str(line);
2145  std::size_t found = str.find("Failed");
2146 
2147  if (found == std::string::npos) {
2148  std::vector<std::string> elm;
2149  elm = vpIoTools::splitChain(str, " ");
2150  for (size_t i = 0; i < elm.size(); i++) {
2151  if (!elm[i].empty()) {
2152  std::vector<std::string> resolution = vpIoTools::splitChain(elm[i], "x");
2153  if (resolution.size() == 2) {
2154  std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2155  sswidth >> w;
2156  ssheight >> h;
2157  break;
2158  }
2159  }
2160  }
2161  }
2162  }
2163  pclose(fpipe);
2164 #elif defined(_WIN32)
2165 #if !defined(WINRT)
2166  w = GetSystemMetrics(SM_CXSCREEN);
2167  h = GetSystemMetrics(SM_CYSCREEN);
2168 #else
2169  throw(vpException(vpException::functionNotImplementedError, "The function vpDisplayOpenCV::getScreenSize() is not "
2170  "implemented on winrt"));
2171 #endif
2172 #endif
2173 }
2174 
2179 {
2180  unsigned int width, height;
2181  getScreenSize(width, height);
2182  return width;
2183 }
2184 
2189 {
2190  unsigned int width, height;
2191  getScreenSize(width, height);
2192  return height;
2193 }
2194 
2195 #elif !defined(VISP_BUILD_SHARED_LIBS)
2196 // Work arround to avoid warning: libvisp_core.a(vpDisplayOpenCV.cpp.o) has no
2197 // symbols
2198 void dummy_vpDisplayOpenCV(){};
2199 #endif
void getScreenSize(unsigned int &width, unsigned int &height)
unsigned int m_height
Definition: vpDisplay.h:210
void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
vpDisplay * display
Definition: vpImage.h:142
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
unsigned int getScreenHeight()
double get_i() const
Definition: vpImagePoint.h:204
double getTop() const
Definition: vpRect.h:192
int m_windowYPosition
display position
Definition: vpDisplay.h:208
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
void clearDisplay(const vpColor &color=vpColor::white)
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height)
unsigned char B
Blue component.
Definition: vpRGBa.h:150
static const vpColor black
Definition: vpColor.h:173
void set_u(double u)
Definition: vpImagePoint.h:226
static const vpColor darkRed
Definition: vpColor.h:180
#define vpERROR_TRACE
Definition: vpDebug.h:393
bool getClick(bool blocking=true)
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
error that can be emited by ViSP classes.
Definition: vpException.h:71
static const vpColor lightGray
Definition: vpColor.h:175
void setFont(const std::string &font)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height)
bool getPointerPosition(vpImagePoint &ip)
static const vpColor darkBlue
Definition: vpColor.h:186
unsigned char G
Green component.
Definition: vpRGBa.h:149
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:204
static const vpColor green
Definition: vpColor.h:182
double getRight() const
Definition: vpRect.h:179
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static const vpColor lightRed
Definition: vpColor.h:178
virtual ~vpDisplayOpenCV()
Definition: vpRGBa.h:66
void displayImage(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:179
static const vpColor orange
Definition: vpColor.h:189
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void on_mouse(int event, int x, int y, int flags, void *param)
vpColorIdentifier id
Definition: vpColor.h:168
double get_u() const
Definition: vpImagePoint.h:263
int m_windowXPosition
display position
Definition: vpDisplay.h:206
static const vpColor cyan
Definition: vpColor.h:188
static const vpColor lightGreen
Definition: vpColor.h:181
void set_i(double ii)
Definition: vpImagePoint.h:167
unsigned int m_scale
Definition: vpDisplay.h:212
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:259
#define vpTRACE
Definition: vpDebug.h:416
static double sqr(double x)
Definition: vpMath.h:114
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void getScreenSize(unsigned int &width, unsigned int &height)
double get_j() const
Definition: vpImagePoint.h:215
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)
void setTitle(const std::string &title)
vpScaleType m_scaleType
Definition: vpDisplay.h:213
std::string m_title
Definition: vpDisplay.h:211
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1767
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static const vpColor gray
Definition: vpColor.h:176
double getLeft() const
Definition: vpRect.h:173
static const vpColor darkGray
Definition: vpColor.h:177
static int round(double x)
Definition: vpMath.h:241
void set_j(double jj)
Definition: vpImagePoint.h:178
bool getPointerMotionEvent(vpImagePoint &ip)
Error that can be emited by the vpDisplay class and its derivates.
void set_v(double v)
Definition: vpImagePoint.h:237
unsigned int getHeight() const
Definition: vpImage.h:186
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
unsigned int m_width
Definition: vpDisplay.h:209
unsigned int getScreenWidth()
unsigned char R
Red component.
Definition: vpRGBa.h:148
Defines a rectangle in the plane.
Definition: vpRect.h:78
static const vpColor darkGreen
Definition: vpColor.h:183
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static const vpColor yellow
Definition: vpColor.h:187
static const vpColor lightBlue
Definition: vpColor.h:184
static const vpColor purple
Definition: vpColor.h:190
static const vpColor white
Definition: vpColor.h:174
unsigned int getWidth() const
Definition: vpImage.h:244
Function not implemented.
Definition: vpException.h:90
double getBottom() const
Definition: vpRect.h:97
double get_v() const
Definition: vpImagePoint.h:274
bool getKeyboardEvent(bool blocking=true)
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:285
void setWindowPosition(int winx, int winy)
static const vpColor blue
Definition: vpColor.h:185