Visual Servoing Platform  version 3.5.1 under development (2023-06-08)
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, unsigned int h)
874 {
876 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
877  int depth = 8;
878  int channels = 3;
879  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
880  if (m_background != NULL) {
881  if (m_background->nChannels != channels || m_background->depth != depth ||
882  m_background->height != (int)m_height || m_background->width != (int)m_width) {
883  if (m_background->nChannels != 0)
884  cvReleaseImage(&m_background);
885  m_background = cvCreateImage(size, depth, channels);
886  }
887  } else {
888  m_background = cvCreateImage(size, depth, channels);
889  }
890 
891  if (m_scale == 1) {
892  unsigned int i_min = (unsigned int)iP.get_i();
893  unsigned int j_min = (unsigned int)iP.get_j();
894  unsigned int i_max = (std::min)(i_min + h, m_height);
895  unsigned int j_max = (std::min)(j_min + w, m_width);
896  for (unsigned int i = i_min; i < i_max; i++) {
897  unsigned char *dst_24 =
898  (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep + j_min * 3);
899  for (unsigned int j = j_min; j < j_max; j++) {
900  vpRGBa val = I[i][j];
901  *(dst_24++) = val.B;
902  *(dst_24++) = val.G;
903  *(dst_24++) = val.R;
904  }
905  }
906  } else {
907  int i_min = (std::max)((int)ceil(iP.get_i() / m_scale), 0);
908  int j_min = (std::max)((int)ceil(iP.get_j() / m_scale), 0);
909  int i_max = (std::min)((int)ceil((iP.get_i() + h) / m_scale), (int)m_height);
910  int j_max = (std::min)((int)ceil((iP.get_j() + w) / m_scale), (int)m_width);
911  for (int i = i_min; i < i_max; i++) {
912  unsigned char *dst_24 =
913  (unsigned char *)m_background->imageData + (int)(i * m_background->widthStep + j_min * 3);
914  for (int j = j_min; j < j_max; j++) {
915  vpRGBa val = I[i * m_scale][j * m_scale];
916  *(dst_24++) = val.B;
917  *(dst_24++) = val.G;
918  *(dst_24++) = val.R;
919  }
920  }
921  }
922 #else
923  int depth = CV_8U;
924  int channels = 3;
925  cv::Size size((int)this->m_width, (int)this->m_height);
926  if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
927  m_background.cols != (int)m_width) {
928  m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
929  }
930 
931  if (m_scale == 1) {
932  unsigned int i_min = (unsigned int)iP.get_i();
933  unsigned int j_min = (unsigned int)iP.get_j();
934  unsigned int i_max = (std::min)(i_min + h, m_height);
935  unsigned int j_max = (std::min)(j_min + w, m_width);
936  for (unsigned int i = i_min; i < i_max; i++) {
937  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3);
938  for (unsigned int j = j_min; j < j_max; j++) {
939  vpRGBa val = I[i][j];
940  *(dst_24++) = val.B;
941  *(dst_24++) = val.G;
942  *(dst_24++) = val.R;
943  }
944  }
945  } else {
946  int i_min = (std::max)((int)ceil(iP.get_i() / m_scale), 0);
947  int j_min = (std::max)((int)ceil(iP.get_j() / m_scale), 0);
948  int i_max = (std::min)((int)ceil((iP.get_i() + h) / m_scale), (int)m_height);
949  int j_max = (std::min)((int)ceil((iP.get_j() + w) / m_scale), (int)m_width);
950  for (int i = i_min; i < i_max; i++) {
951  unsigned char *dst_24 = (unsigned char *)m_background.data + (int)(i * 3 * m_width + j_min * 3);
952  for (int j = j_min; j < j_max; j++) {
953  vpRGBa val = I[i * m_scale][j * m_scale];
954  *(dst_24++) = val.B;
955  *(dst_24++) = val.G;
956  *(dst_24++) = val.R;
957  }
958  }
959  }
960 #endif
961  } else {
962  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
963  }
964 }
965 
971 void vpDisplayOpenCV::displayImage(const unsigned char * /* I */) { vpTRACE(" not implemented "); }
972 
981 {
982  if (col != NULL) {
983  delete[] col;
984  col = NULL;
985  }
986 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
987  if (font != NULL) {
988  delete font;
989  font = NULL;
990  }
991 #endif
993 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
994  cvDestroyWindow(this->m_title.c_str());
995 #else
996  cv::destroyWindow(this->m_title);
997 #endif
998 
999  for (size_t i = 0; i < m_listTitles.size(); i++) {
1000  if (m_title == m_listTitles[i]) {
1001  m_listTitles.erase(m_listTitles.begin() + (long int)i);
1002  break;
1003  }
1004  }
1005 
1006  m_title.clear();
1007 
1009  }
1010 }
1011 
1018 {
1020 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1021  cvShowImage(this->m_title.c_str(), m_background);
1022  cvWaitKey(5);
1023 #else
1024  cv::imshow(this->m_title, m_background);
1025  cv::waitKey(5);
1026 #endif
1027  } else {
1028  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1029  }
1030 }
1031 
1037 void vpDisplayOpenCV::flushDisplayROI(const vpImagePoint & /*iP*/, const unsigned int /*width*/,
1038  const unsigned int /*height*/)
1039 {
1041 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1042  cvShowImage(this->m_title.c_str(), m_background);
1043  cvWaitKey(5);
1044 #else
1045  cv::imshow(this->m_title.c_str(), m_background);
1046  cv::waitKey(5);
1047 #endif
1048  } else {
1049  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1050  }
1051 }
1052 
1056 void vpDisplayOpenCV::clearDisplay(const vpColor & /* color */)
1057 {
1058  static bool warn_displayed = false;
1059  if (!warn_displayed) {
1060  vpTRACE("Not implemented");
1061  warn_displayed = true;
1062  }
1063 }
1064 
1072 void vpDisplayOpenCV::displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1073  unsigned int w, unsigned int h, unsigned int thickness)
1074 {
1076  double a = ip2.get_i() - ip1.get_i();
1077  double b = ip2.get_j() - ip1.get_j();
1078  double lg = sqrt(vpMath::sqr(a) + vpMath::sqr(b));
1079 
1080  // if ((a==0)&&(b==0))
1081  if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
1082  (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
1083  // DisplayCrossLarge(i1,j1,3,col) ;
1084  } else {
1085  a /= lg;
1086  b /= lg;
1087 
1088  vpImagePoint ip3;
1089  ip3.set_i(ip2.get_i() - w * a);
1090  ip3.set_j(ip2.get_j() - w * b);
1091 
1092  vpImagePoint ip4;
1093  ip4.set_i(ip3.get_i() - b * h);
1094  ip4.set_j(ip3.get_j() + a * h);
1095 
1096  if (lg > 2 * vpImagePoint::distance(ip2, ip4))
1097  displayLine(ip2, ip4, color, thickness);
1098 
1099  ip4.set_i(ip3.get_i() + b * h);
1100  ip4.set_j(ip3.get_j() - a * h);
1101 
1102  if (lg > 2 * vpImagePoint::distance(ip2, ip4))
1103  displayLine(ip2, ip4, color, thickness);
1104 
1105  displayLine(ip1, ip2, color, thickness);
1106  }
1107  } else {
1108  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1109  }
1110 }
1111 
1123 void vpDisplayOpenCV::displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color)
1124 {
1126  if (color.id < vpColor::id_unknown) {
1127 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1128  cvPutText(m_background, text,
1129  cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), font,
1130  col[color.id]);
1131 #else
1132  cv::putText(m_background, text,
1133  cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)),
1134  font, fontScale, col[color.id]);
1135 #endif
1136  } else {
1137  cvcolor = CV_RGB(color.R, color.G, color.B);
1138 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1139  cvPutText(m_background, text,
1140  cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)), font,
1141  cvcolor);
1142 #else
1143  cv::putText(m_background, text,
1144  cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale + fontHeight)),
1145  font, fontScale, cvcolor);
1146 #endif
1147  }
1148  } else {
1149  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1150  }
1151 }
1164 void vpDisplayOpenCV::displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill,
1165  unsigned int thickness)
1166 {
1168  int x = vpMath::round(center.get_u() / m_scale);
1169  int y = vpMath::round(center.get_v() / m_scale);
1170  int r = static_cast<int>(radius / m_scale);
1171  cv::Scalar cv_color;
1172  if (color.id < vpColor::id_unknown) {
1173  cv_color = col[color.id];
1174  } else {
1175  cv_color = CV_RGB(color.R, color.G, color.B);
1176  }
1177 
1178  if (fill == false) {
1179  int cv_thickness = static_cast<int>(thickness);
1180 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1181  cvCircle(m_background, cvPoint(x, y), r, cv_color, cv_thickness);
1182 #else
1183  cv::circle(m_background, cv::Point(x, y), r, cv_color, cv_thickness);
1184 #endif
1185  } else {
1186 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1187  int filled = cv::FILLED;
1188 #else
1189  int filled = CV_FILLED;
1190 #endif
1191 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1192  double opacity = static_cast<double>(color.A) / 255.0;
1193 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1194  overlay([x, y, r, cv_color, filled](cv::Mat image) { cvCircle(image, cvPoint(x, y), r, cv_color, filled); },
1195  opacity);
1196 #else
1197  overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); },
1198  opacity);
1199 #endif
1200 #else
1201 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1202  cvCircle(m_background, cvPoint(x, y), r, cv_color, filled);
1203 #else
1204  cv::circle(m_background, cv::Point(x, y), r, cv_color, filled);
1205 #endif
1206 #endif
1207  }
1208  } else {
1209  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1210  }
1211 }
1212 
1220 void vpDisplayOpenCV::displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color,
1221  unsigned int thickness)
1222 {
1224  vpImagePoint top, bottom, left, right;
1225  top.set_i(ip.get_i() - size / 2);
1226  top.set_j(ip.get_j());
1227  bottom.set_i(ip.get_i() + size / 2);
1228  bottom.set_j(ip.get_j());
1229  left.set_i(ip.get_i());
1230  left.set_j(ip.get_j() - size / 2);
1231  right.set_i(ip.get_i());
1232  right.set_j(ip.get_j() + size / 2);
1233  displayLine(top, bottom, color, thickness);
1234  displayLine(left, right, color, thickness);
1235  } else {
1236  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1237  }
1238 }
1239 
1247 void vpDisplayOpenCV::displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1248  unsigned int thickness)
1249 {
1251  vpImagePoint ip1_ = ip1;
1252  vpImagePoint ip2_ = ip2;
1253 
1254  double size = 10. * m_scale;
1255  double length = sqrt(vpMath::sqr(ip2_.get_i() - ip1_.get_i()) + vpMath::sqr(ip2_.get_j() - ip1_.get_j()));
1256  bool vertical_line = (int)ip2_.get_j() == (int)ip1_.get_j();
1257  if (vertical_line) {
1258  if (ip2_.get_i() < ip1_.get_i()) {
1259  std::swap(ip1_, ip2_);
1260  }
1261  } else if (ip2_.get_j() < ip1_.get_j()) {
1262  std::swap(ip1_, ip2_);
1263  }
1264 
1265  double diff_j = vertical_line ? 1 : ip2_.get_j() - ip1_.get_j();
1266  double deltaj = size / length * diff_j;
1267  double deltai = size / length * (ip2_.get_i() - ip1_.get_i());
1268  double slope = (ip2_.get_i() - ip1_.get_i()) / diff_j;
1269  double orig = ip1_.get_i() - slope * ip1_.get_j();
1270 
1271  if (vertical_line) {
1272  for (unsigned int i = (unsigned int)ip1_.get_i(); i < ip2_.get_i(); i += (unsigned int)(2 * deltai)) {
1273  double j = ip1_.get_j();
1274  displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j), color, thickness);
1275  }
1276  } else {
1277  for (unsigned int j = (unsigned int)ip1_.get_j(); j < ip2_.get_j(); j += (unsigned int)(2 * deltaj)) {
1278  double i = slope * j + orig;
1279  displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j + deltaj), color, thickness);
1280  }
1281  }
1282  } else {
1283  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1284  }
1285 }
1286 
1293 void vpDisplayOpenCV::displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1294  unsigned int thickness)
1295 {
1297  if (color.id < vpColor::id_unknown) {
1298 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1299  cvLine(m_background, cvPoint(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1300  cvPoint(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id],
1301  (int)thickness);
1302 #else
1303  cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1304  cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id],
1305  (int)thickness);
1306 #endif
1307  } else {
1308  cvcolor = CV_RGB(color.R, color.G, color.B);
1309 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1310  cvLine(m_background, cvPoint(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1311  cvPoint(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), cvcolor,
1312  (int)thickness);
1313 #else
1314  cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1315  cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), cvcolor,
1316  (int)thickness);
1317 #endif
1318  }
1319  } else {
1320  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1321  }
1322 }
1323 
1330 void vpDisplayOpenCV::displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness)
1331 {
1333  for (unsigned int i = 0; i < thickness; i++) {
1334  if (color.id < vpColor::id_unknown) {
1335 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1336  cvLine(m_background, cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1337  cvPoint(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1338  col[color.id], (int)thickness);
1339 #else
1340  cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1341  cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1342  col[color.id], (int)thickness);
1343 #endif
1344  } else {
1345  cvcolor = CV_RGB(color.R, color.G, color.B);
1346 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1347  cvLine(m_background, cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1348  cvPoint(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1349  cvcolor, (int)thickness);
1350 #else
1351  cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1352  cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1353  cvcolor, (int)thickness);
1354 #endif
1355  }
1356  }
1357  } else {
1358  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1359  }
1360 }
1361 
1377 void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, unsigned int w, unsigned int h,
1378  const vpColor &color, bool fill, unsigned int thickness)
1379 {
1381  int left = vpMath::round(topLeft.get_u() / m_scale);
1382  int top = vpMath::round(topLeft.get_v() / m_scale);
1383  int right = vpMath::round((topLeft.get_u() + w) / m_scale);
1384  int bottom = vpMath::round((topLeft.get_v() + h) / m_scale);
1385  cv::Scalar cv_color;
1386  if (color.id < vpColor::id_unknown) {
1387  cv_color = col[color.id];
1388  } else {
1389  cv_color = CV_RGB(color.R, color.G, color.B);
1390  }
1391 
1392  if (fill == false) {
1393  int cv_thickness = static_cast<int>(thickness);
1394 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1395  cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1396 #else
1397  cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1398 #endif
1399  } else {
1400 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1401  int filled = cv::FILLED;
1402 #else
1403  int filled = CV_FILLED;
1404 #endif
1405 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1406  double opacity = static_cast<double>(color.A) / 255.0;
1407 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1408  overlay([left, top, right, bottom, cv_color, filled](
1409  cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1410  opacity);
1411 #else
1412  overlay(
1413  [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1414  cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1415  },
1416  opacity);
1417 #endif
1418 #else
1419 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1420  cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1421 #else
1422  cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1423 #endif
1424 #endif
1425  }
1426  } else {
1427  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1428  }
1429 }
1444 void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
1445  const vpColor &color, bool fill, unsigned int thickness)
1446 {
1448  int left = vpMath::round(topLeft.get_u() / m_scale);
1449  int top = vpMath::round(topLeft.get_v() / m_scale);
1450  int right = vpMath::round(bottomRight.get_u() / m_scale);
1451  int bottom = vpMath::round(bottomRight.get_v() / m_scale);
1452  cv::Scalar cv_color;
1453  if (color.id < vpColor::id_unknown) {
1454  cv_color = col[color.id];
1455  } else {
1456  cv_color = CV_RGB(color.R, color.G, color.B);
1457  }
1458 
1459  if (fill == false) {
1460  int cv_thickness = static_cast<int>(thickness);
1461 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1462  cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1463 #else
1464  cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1465 #endif
1466  } else {
1467 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1468  int filled = cv::FILLED;
1469 #else
1470  int filled = CV_FILLED;
1471 #endif
1472 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1473  double opacity = static_cast<double>(color.A) / 255.0;
1474 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1475  overlay([left, top, right, bottom, cv_color, filled](
1476  cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1477  opacity);
1478 #else
1479  overlay(
1480  [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1481  cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1482  },
1483  opacity);
1484 #endif
1485 #else
1486 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1487  cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1488 #else
1489  cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1490 #endif
1491 #endif
1492  }
1493  } else {
1494  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1495  }
1496 }
1497 
1511 void vpDisplayOpenCV::displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill, unsigned int thickness)
1512 {
1514  int left = vpMath::round(rectangle.getLeft() / m_scale);
1515  int top = vpMath::round(rectangle.getTop() / m_scale);
1516  int right = vpMath::round(rectangle.getRight() / m_scale);
1517  int bottom = vpMath::round(rectangle.getBottom() / m_scale);
1518  cv::Scalar cv_color;
1519  if (color.id < vpColor::id_unknown) {
1520  cv_color = col[color.id];
1521  } else {
1522  cv_color = CV_RGB(color.R, color.G, color.B);
1523  }
1524 
1525  if (fill == false) {
1526  int cv_thickness = static_cast<int>(thickness);
1527 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1528  cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1529 #else
1530  cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1531 #endif
1532  } else {
1533 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1534  int filled = cv::FILLED;
1535 #else
1536  int filled = CV_FILLED;
1537 #endif
1538 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1539  double opacity = static_cast<double>(color.A) / 255.0;
1540 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1541  overlay([left, top, right, bottom, cv_color, filled](
1542  cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1543  opacity);
1544 #else
1545  overlay(
1546  [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1547  cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1548  },
1549  opacity);
1550 #endif
1551 #else
1552 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1553  cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1554 #else
1555  cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1556 #endif
1557 #endif
1558  }
1559  } else {
1560  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1561  }
1562 }
1563 
1579 bool vpDisplayOpenCV::getClick(bool blocking)
1580 {
1581  bool ret = false;
1583  flushDisplay();
1584  if (blocking) {
1585  lbuttondown = false;
1586  mbuttondown = false;
1587  rbuttondown = false;
1588  }
1589  do {
1590  if (lbuttondown) {
1591  ret = true;
1592  lbuttondown = false;
1593  }
1594  if (mbuttondown) {
1595  ret = true;
1596  mbuttondown = false;
1597  }
1598  if (rbuttondown) {
1599  ret = true;
1600  rbuttondown = false;
1601  }
1602  if (blocking)
1603 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1604  cvWaitKey(10);
1605 #else
1606  cv::waitKey(10);
1607 #endif
1608  } while (ret == false && blocking == true);
1609  } else {
1610  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1611  }
1612  return ret;
1613 }
1614 
1630 bool vpDisplayOpenCV::getClick(vpImagePoint &ip, bool blocking)
1631 {
1632  bool ret = false;
1633 
1635  flushDisplay();
1636 
1637  double u, v;
1638 
1639  if (blocking) {
1640  lbuttondown = false;
1641  mbuttondown = false;
1642  rbuttondown = false;
1643  }
1644  do {
1645  if (lbuttondown) {
1646  ret = true;
1647  u = (unsigned int)x_lbuttondown * m_scale;
1648  v = (unsigned int)y_lbuttondown * m_scale;
1649  ip.set_u(u);
1650  ip.set_v(v);
1651  lbuttondown = false;
1652  }
1653  if (mbuttondown) {
1654  ret = true;
1655  u = (unsigned int)x_mbuttondown * m_scale;
1656  v = (unsigned int)y_mbuttondown * m_scale;
1657  ip.set_u(u);
1658  ip.set_v(v);
1659  mbuttondown = false;
1660  }
1661  if (rbuttondown) {
1662  ret = true;
1663  u = (unsigned int)x_rbuttondown * m_scale;
1664  v = (unsigned int)y_rbuttondown * m_scale;
1665  ip.set_u(u);
1666  ip.set_v(v);
1667  rbuttondown = false;
1668  }
1669  if (blocking)
1670 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1671  cvWaitKey(10);
1672 #else
1673  cv::waitKey(10);
1674 #endif
1675  } while (ret == false && blocking == true);
1676  } else {
1677  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1678  }
1679  return ret;
1680 }
1681 
1701 {
1702  bool ret = false;
1703 
1705  // flushDisplay() ;
1706  double u, v;
1707  if (blocking) {
1708  lbuttondown = false;
1709  mbuttondown = false;
1710  rbuttondown = false;
1711  }
1712  do {
1713  if (lbuttondown) {
1714  ret = true;
1715  u = (unsigned int)x_lbuttondown * m_scale;
1716  v = (unsigned int)y_lbuttondown * m_scale;
1717  ip.set_u(u);
1718  ip.set_v(v);
1719  button = vpMouseButton::button1;
1720  lbuttondown = false;
1721  }
1722  if (mbuttondown) {
1723  ret = true;
1724  u = (unsigned int)x_mbuttondown * m_scale;
1725  v = (unsigned int)y_mbuttondown * m_scale;
1726  ip.set_u(u);
1727  ip.set_v(v);
1728  button = vpMouseButton::button2;
1729  mbuttondown = false;
1730  }
1731  if (rbuttondown) {
1732  ret = true;
1733  u = (unsigned int)x_rbuttondown * m_scale;
1734  v = (unsigned int)y_rbuttondown * m_scale;
1735  ip.set_u(u);
1736  ip.set_v(v);
1737  button = vpMouseButton::button3;
1738  rbuttondown = false;
1739  }
1740  if (blocking)
1741 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1742  cvWaitKey(10);
1743 #else
1744  cv::waitKey(10);
1745 #endif
1746  } while (ret == false && blocking == true);
1747  } else {
1748  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1749  }
1750  return ret;
1751 }
1752 
1775 {
1776  bool ret = false;
1778  // flushDisplay() ;
1779  double u, v;
1780  if (blocking) {
1781  lbuttonup = false;
1782  mbuttonup = false;
1783  rbuttonup = false;
1784  }
1785  do {
1786  if (lbuttonup) {
1787  ret = true;
1788  u = (unsigned int)x_lbuttonup * m_scale;
1789  v = (unsigned int)y_lbuttonup * m_scale;
1790  ip.set_u(u);
1791  ip.set_v(v);
1792  button = vpMouseButton::button1;
1793  lbuttonup = false;
1794  }
1795  if (mbuttonup) {
1796  ret = true;
1797  u = (unsigned int)x_mbuttonup * m_scale;
1798  v = (unsigned int)y_mbuttonup * m_scale;
1799  ip.set_u(u);
1800  ip.set_v(v);
1801  button = vpMouseButton::button2;
1802  mbuttonup = false;
1803  }
1804  if (rbuttonup) {
1805  ret = true;
1806  u = (unsigned int)x_rbuttonup * m_scale;
1807  v = (unsigned int)y_rbuttonup * m_scale;
1808  ip.set_u(u);
1809  ip.set_v(v);
1810  button = vpMouseButton::button3;
1811  rbuttonup = false;
1812  }
1813  if (blocking)
1814 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1815  cvWaitKey(10);
1816 #else
1817  cv::waitKey(10);
1818 #endif
1819  } while (ret == false && blocking == true);
1820  } else {
1821  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1822  }
1823  return ret;
1824 }
1825 
1826 /*
1827  Gets the displayed image (including the overlay plane)
1828  and returns an RGBa image.
1829 */
1831 {
1832  vpImageConvert::convert(m_background, I);
1833  // should certainly be optimized.
1834 }
1835 
1836 void vpDisplayOpenCV::on_mouse(int event, int x, int y, int /*flags*/, void *display)
1837 {
1838  vpDisplayOpenCV *disp = static_cast<vpDisplayOpenCV *>(display);
1839  switch (event) {
1840 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1841  case CV_EVENT_MOUSEMOVE:
1842 #else
1843  case cv::EVENT_MOUSEMOVE:
1844 #endif
1845  {
1846  disp->move = true;
1847  disp->x_move = x;
1848  disp->y_move = y;
1849  break;
1850  }
1851 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1852  case CV_EVENT_LBUTTONDOWN:
1853 #else
1854  case cv::EVENT_LBUTTONDOWN:
1855 #endif
1856  {
1857  disp->lbuttondown = true;
1858  disp->x_lbuttondown = x;
1859  disp->y_lbuttondown = y;
1860  break;
1861  }
1862 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1863  case CV_EVENT_MBUTTONDOWN:
1864 #else
1865  case cv::EVENT_MBUTTONDOWN:
1866 #endif
1867  {
1868  disp->mbuttondown = true;
1869  disp->x_mbuttondown = x;
1870  disp->y_mbuttondown = y;
1871  break;
1872  }
1873 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1874  case CV_EVENT_RBUTTONDOWN:
1875 #else
1876  case cv::EVENT_RBUTTONDOWN:
1877 #endif
1878  {
1879  disp->rbuttondown = true;
1880  disp->x_rbuttondown = x;
1881  disp->y_rbuttondown = y;
1882  break;
1883  }
1884 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1885  case CV_EVENT_LBUTTONUP:
1886 #else
1887  case cv::EVENT_LBUTTONUP:
1888 #endif
1889  {
1890  disp->lbuttonup = true;
1891  disp->x_lbuttonup = x;
1892  disp->y_lbuttonup = y;
1893  break;
1894  }
1895 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1896  case CV_EVENT_MBUTTONUP:
1897 #else
1898  case cv::EVENT_MBUTTONUP:
1899 #endif
1900  {
1901  disp->mbuttonup = true;
1902  disp->x_mbuttonup = x;
1903  disp->y_mbuttonup = y;
1904  break;
1905  }
1906 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1907  case CV_EVENT_RBUTTONUP:
1908 #else
1909  case cv::EVENT_RBUTTONUP:
1910 #endif
1911  {
1912  disp->rbuttonup = true;
1913  disp->x_rbuttonup = x;
1914  disp->y_rbuttonup = y;
1915  break;
1916  }
1917 
1918  default:
1919  break;
1920  }
1921 }
1922 
1939 {
1941  int delay;
1942  flushDisplay();
1943  if (blocking)
1944  delay = 0;
1945  else
1946  delay = 10;
1947 
1948 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1949  int key_pressed = cvWaitKey(delay);
1950 #else
1951  int key_pressed = cv::waitKey(delay);
1952 #endif
1953 
1954  if (key_pressed == -1)
1955  return false;
1956  return true;
1957  } else {
1958  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1959  }
1960  // return false; // Never reached after throw()
1961 }
1980 bool vpDisplayOpenCV::getKeyboardEvent(std::string &key, bool blocking)
1981 {
1983  int delay;
1984  flushDisplay();
1985  if (blocking)
1986  delay = 0;
1987  else
1988  delay = 10;
1989 
1990 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1991  int key_pressed = cvWaitKey(delay);
1992 #else
1993  int key_pressed = cv::waitKey(delay);
1994 #endif
1995  if (key_pressed == -1)
1996  return false;
1997  else {
1998  // std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl;
1999  std::stringstream ss;
2000  ss << key_pressed;
2001  key = ss.str();
2002  }
2003  return true;
2004  } else {
2005  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2006  }
2007  // return false; // Never reached after throw()
2008 }
2009 
2021 {
2022  bool ret = false;
2023 
2025  // flushDisplay() ;
2026  if (move) {
2027  ret = true;
2028  double u = (unsigned int)x_move / m_scale;
2029  double v = (unsigned int)y_move / m_scale;
2030  ip.set_u(u);
2031  ip.set_v(v);
2032  move = false;
2033  }
2034  }
2035 
2036  else {
2037  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2038  }
2039  return ret;
2040 }
2041 
2053 {
2055  bool moved = getPointerMotionEvent(ip);
2056  if (!moved) {
2057  double u, v;
2058  u = (unsigned int)x_move / m_scale;
2059  v = (unsigned int)y_move / m_scale;
2060  ip.set_u(u);
2061  ip.set_v(v);
2062  }
2063  return false;
2064  } else {
2065  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2066  }
2067 }
2068 
2073 void vpDisplayOpenCV::getScreenSize(unsigned int &w, unsigned int &h)
2074 {
2075  w = h = 0;
2076 
2077 #if defined(VISP_HAVE_X11)
2078  vpDisplayX d;
2079  d.getScreenSize(w, h);
2080 #elif defined(VISP_HAVE_XRANDR)
2081  std::string command = "xrandr | grep '*'";
2082  FILE *fpipe = (FILE *)popen(command.c_str(), "r");
2083  char line[256];
2084  while (fgets(line, sizeof(line), fpipe)) {
2085  std::string str(line);
2086  std::size_t found = str.find("Failed");
2087 
2088  if (found == std::string::npos) {
2089  std::vector<std::string> elm;
2090  elm = vpIoTools::splitChain(str, " ");
2091  for (size_t i = 0; i < elm.size(); i++) {
2092  if (!elm[i].empty()) {
2093  std::vector<std::string> resolution = vpIoTools::splitChain(elm[i], "x");
2094  if (resolution.size() == 2) {
2095  std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2096  sswidth >> w;
2097  ssheight >> h;
2098  break;
2099  }
2100  }
2101  }
2102  }
2103  }
2104  pclose(fpipe);
2105 #elif defined(_WIN32)
2106 #if !defined(WINRT)
2107  w = GetSystemMetrics(SM_CXSCREEN);
2108  h = GetSystemMetrics(SM_CYSCREEN);
2109 #else
2110  throw(vpException(vpException::functionNotImplementedError, "The function vpDisplayOpenCV::getScreenSize() is not "
2111  "implemented on winrt"));
2112 #endif
2113 #endif
2114 }
2115 
2120 {
2121  unsigned int width, height;
2122  getScreenSize(width, height);
2123  return width;
2124 }
2125 
2130 {
2131  unsigned int width, height;
2132  getScreenSize(width, height);
2133  return height;
2134 }
2135 
2136 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
2142 void vpDisplayOpenCV::overlay(std::function<void(cv::Mat &)> overlay_function, double opacity)
2143 {
2144  // Initialize overlay layer for transparency
2145  cv::Mat overlay;
2146  if (opacity < 1.0) {
2147  // Deep copy
2148  overlay = m_background.clone();
2149  } else {
2150  // Shallow copy
2151  overlay = m_background;
2152  }
2153 
2154  overlay_function(overlay);
2155 
2156  // Blend background and overlay
2157  if (opacity < 1.0) {
2158  cv::addWeighted(overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background);
2159  }
2160 }
2161 #endif
2162 
2163 #elif !defined(VISP_BUILD_SHARED_LIBS)
2164 // Work around to avoid warning: libvisp_core.a(vpDisplayOpenCV.cpp.o) has no
2165 // symbols
2166 void dummy_vpDisplayOpenCV(){};
2167 #endif
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:158
static const vpColor white
Definition: vpColor.h:212
vpColorIdentifier id
Definition: vpColor.h:206
static const vpColor red
Definition: vpColor.h:217
static const vpColor darkGray
Definition: vpColor.h:215
static const vpColor black
Definition: vpColor.h:211
static const vpColor cyan
Definition: vpColor.h:226
static const vpColor orange
Definition: vpColor.h:227
static const vpColor darkRed
Definition: vpColor.h:218
static const vpColor blue
Definition: vpColor.h:223
static const vpColor lightGray
Definition: vpColor.h:213
static const vpColor lightBlue
Definition: vpColor.h:222
static const vpColor darkGreen
Definition: vpColor.h:221
static const vpColor darkBlue
Definition: vpColor.h:224
static const vpColor purple
Definition: vpColor.h:228
static const vpColor lightGreen
Definition: vpColor.h:219
static const vpColor yellow
Definition: vpColor.h:225
@ id_lightBlue
Definition: vpColor.h:184
@ id_yellow
Definition: vpColor.h:190
@ id_darkGray
Definition: vpColor.h:170
@ id_green
Definition: vpColor.h:180
@ id_darkRed
Definition: vpColor.h:176
@ id_lightGray
Definition: vpColor.h:166
@ id_red
Definition: vpColor.h:174
@ id_lightRed
Definition: vpColor.h:172
@ id_white
Definition: vpColor.h:164
@ id_black
Definition: vpColor.h:162
@ id_blue
Definition: vpColor.h:186
@ id_darkGreen
Definition: vpColor.h:182
@ id_gray
Definition: vpColor.h:168
@ id_lightGreen
Definition: vpColor.h:178
@ id_purple
Definition: vpColor.h:196
@ id_orange
Definition: vpColor.h:194
@ id_cyan
Definition: vpColor.h:192
@ id_darkBlue
Definition: vpColor.h:188
@ id_unknown
Definition: vpColor.h:199
static const vpColor lightRed
Definition: vpColor.h:216
static const vpColor green
Definition: vpColor.h:220
static const vpColor gray
Definition: vpColor.h:214
Error that can be emited by the vpDisplay class and its derivates.
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void overlay(std::function< void(cv::Mat &)> overlay_function, double opacity)
void setWindowPosition(int winx, int winy)
void displayImage(const vpImage< unsigned char > &I)
unsigned int getScreenWidth()
void clearDisplay(const vpColor &color=vpColor::white)
bool getPointerMotionEvent(vpImagePoint &ip)
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height)
void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
bool getKeyboardEvent(bool blocking=true)
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void setFont(const std::string &font)
void setTitle(const std::string &title)
bool getClick(bool blocking=true)
virtual ~vpDisplayOpenCV()
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height)
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
void getScreenSize(unsigned int &width, unsigned int &height)
bool getPointerPosition(vpImagePoint &ip)
unsigned int getScreenHeight()
static void on_mouse(int event, int x, int y, int flags, void *param)
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
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)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:135
void getScreenSize(unsigned int &width, unsigned int &height)
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:178
unsigned int m_height
Definition: vpDisplay.h:216
vpScaleType m_scaleType
Definition: vpDisplay.h:219
unsigned int m_width
Definition: vpDisplay.h:215
static void display(const vpImage< unsigned char > &I)
int m_windowXPosition
display position
Definition: vpDisplay.h:212
std::string m_title
Definition: vpDisplay.h:217
int m_windowYPosition
display position
Definition: vpDisplay.h:214
unsigned int m_scale
Definition: vpDisplay.h:218
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:210
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:259
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ functionNotImplementedError
Function not implemented.
Definition: vpException.h:90
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 ...
Definition: vpImagePoint.h:89
void set_j(double jj)
Definition: vpImagePoint.h:309
double get_j() const
Definition: vpImagePoint.h:132
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
void set_i(double ii)
Definition: vpImagePoint.h:298
double get_u() const
Definition: vpImagePoint.h:143
void set_u(double u)
Definition: vpImagePoint.h:335
void set_v(double v)
Definition: vpImagePoint.h:346
double get_i() const
Definition: vpImagePoint.h:121
double get_v() const
Definition: vpImagePoint.h:154
unsigned int getWidth() const
Definition: vpImage.h:247
unsigned int getHeight() const
Definition: vpImage.h:189
vpDisplay * display
Definition: vpImage.h:145
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1994
static double sqr(double x)
Definition: vpMath.h:122
static int round(double x)
Definition: vpMath.h:321
Definition: vpRGBa.h:67
unsigned char B
Blue component.
Definition: vpRGBa.h:146
unsigned char R
Red component.
Definition: vpRGBa.h:144
unsigned char G
Green component.
Definition: vpRGBa.h:145
unsigned char A
Additionnal component.
Definition: vpRGBa.h:147
Defines a rectangle in the plane.
Definition: vpRect.h:78
double getLeft() const
Definition: vpRect.h:172
double getRight() const
Definition: vpRect.h:178
double getBottom() const
Definition: vpRect.h:96
double getTop() const
Definition: vpRect.h:191
#define vpTRACE
Definition: vpDebug.h:416
#define vpERROR_TRACE
Definition: vpDebug.h:393