Visual Servoing Platform  version 3.1.0
vpDisplayOpenCV.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
676 void vpDisplayOpenCV::displayImageROI(const vpImage<unsigned char> &I, const vpImagePoint &iP, const unsigned int w,
677  const 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, const unsigned int w,
874  const 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  double size = 10. * m_scale;
1262  double length = sqrt(vpMath::sqr(ip2.get_i() - ip1.get_i()) + vpMath::sqr(ip2.get_j() - ip1.get_j()));
1263  double deltaj = size / length * (ip2.get_j() - ip1.get_j());
1264  double deltai = size / length * (ip2.get_i() - ip1.get_i());
1265  double slope = (ip2.get_i() - ip1.get_i()) / (ip2.get_j() - ip1.get_j());
1266  double orig = ip1.get_i() - slope * ip1.get_j();
1267  for (unsigned int j = (unsigned int)ip1.get_j(); j < ip2.get_j(); j += (unsigned int)(2 * deltaj)) {
1268  double i = slope * j + orig;
1269  displayLine(vpImagePoint(i, j), vpImagePoint(i + deltai, j + deltaj), color, thickness);
1270  }
1271  } else {
1272  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1273  }
1274 }
1275 
1282 void vpDisplayOpenCV::displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color,
1283  unsigned int thickness)
1284 {
1286  if (color.id < vpColor::id_unknown) {
1287 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1288  cvLine(m_background, cvPoint(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1289  cvPoint(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id],
1290  (int)thickness);
1291 #else
1292  cv::line(m_background, cv::Point(vpMath::round(ip1.get_u() / m_scale), vpMath::round(ip1.get_v() / m_scale)),
1293  cv::Point(vpMath::round(ip2.get_u() / m_scale), vpMath::round(ip2.get_v() / m_scale)), col[color.id],
1294  (int)thickness);
1295 #endif
1296  } else {
1297  cvcolor = CV_RGB(color.R, color.G, color.B);
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)), cvcolor,
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)), cvcolor,
1305  (int)thickness);
1306 #endif
1307  }
1308  } else {
1309  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1310  }
1311 }
1312 
1319 void vpDisplayOpenCV::displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness)
1320 {
1322  for (unsigned int i = 0; i < thickness; i++) {
1323  if (color.id < vpColor::id_unknown) {
1324 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1325  cvLine(m_background, cvPoint(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1326  cvPoint(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1327  col[color.id], (int)thickness);
1328 #else
1329  cv::line(m_background, cv::Point(vpMath::round(ip.get_u() / m_scale), vpMath::round(ip.get_v() / m_scale)),
1330  cv::Point(vpMath::round(ip.get_u() / m_scale + thickness - 1), vpMath::round(ip.get_v() / m_scale)),
1331  col[color.id], (int)thickness);
1332 #endif
1333  } else {
1334  cvcolor = CV_RGB(color.R, color.G, color.B);
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  cvcolor, (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  cvcolor, (int)thickness);
1343 #endif
1344  }
1345  }
1346  } else {
1347  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1348  }
1349 }
1350 
1364 void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, unsigned int w, unsigned int h,
1365  const vpColor &color, bool fill, unsigned int thickness)
1366 {
1368  if (fill == false) {
1369  if (color.id < vpColor::id_unknown) {
1370 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1371  cvRectangle(
1372  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1373  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1374  col[color.id], (int)thickness);
1375 #else
1376  cv::rectangle(
1377  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1378  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1379  col[color.id], (int)thickness);
1380 #endif
1381  } else {
1382  cvcolor = CV_RGB(color.R, color.G, color.B);
1383 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1384  cvRectangle(
1385  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1386  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1387  cvcolor, (int)thickness);
1388 #else
1389  cv::rectangle(
1390  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1391  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1392  cvcolor, (int)thickness);
1393 #endif
1394  }
1395  } else {
1396 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1397  int filled = cv::FILLED;
1398 #else
1399  int filled = CV_FILLED;
1400 #endif
1401  if (color.id < vpColor::id_unknown) {
1402 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1403  cvRectangle(
1404  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1405  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1406  col[color.id], filled);
1407 #else
1408  cv::rectangle(
1409  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1410  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1411  col[color.id], filled);
1412 #endif
1413  } else {
1414  cvcolor = CV_RGB(color.R, color.G, color.B);
1415 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1416  cvRectangle(
1417  m_background, cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1418  cvPoint(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1419  cvcolor, filled);
1420 #else
1421  cv::rectangle(
1422  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1423  cv::Point(vpMath::round((topLeft.get_u() + w) / m_scale), vpMath::round((topLeft.get_v() + h) / m_scale)),
1424  cvcolor, filled);
1425 #endif
1426  }
1427  }
1428  } else {
1429  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1430  }
1431 }
1444 void vpDisplayOpenCV::displayRectangle(const vpImagePoint &topLeft, const vpImagePoint &bottomRight,
1445  const vpColor &color, bool fill, unsigned int thickness)
1446 {
1448  if (fill == false) {
1449  if (color.id < vpColor::id_unknown) {
1450 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1451  cvRectangle(m_background,
1452  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1453  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1454  col[color.id], (int)thickness);
1455 #else
1456  cv::rectangle(
1457  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1458  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1459  col[color.id], (int)thickness);
1460 #endif
1461  } else {
1462  cvcolor = CV_RGB(color.R, color.G, color.B);
1463 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1464  cvRectangle(m_background,
1465  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1466  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1467  cvcolor, (int)thickness);
1468 #else
1469  cv::rectangle(
1470  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1471  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1472  cvcolor, (int)thickness);
1473 #endif
1474  }
1475  } else {
1476 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1477  int filled = cv::FILLED;
1478 #else
1479  int filled = CV_FILLED;
1480 #endif
1481  if (color.id < vpColor::id_unknown) {
1482 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1483  cvRectangle(m_background,
1484  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1485  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1486  col[color.id], filled);
1487 #else
1488  cv::rectangle(
1489  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1490  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1491  col[color.id], filled);
1492 #endif
1493  } else {
1494  cvcolor = CV_RGB(color.R, color.G, color.B);
1495 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1496  cvRectangle(m_background,
1497  cvPoint(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1498  cvPoint(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1499  cvcolor, filled);
1500 #else
1501  cv::rectangle(
1502  m_background, cv::Point(vpMath::round(topLeft.get_u() / m_scale), vpMath::round(topLeft.get_v() / m_scale)),
1503  cv::Point(vpMath::round(bottomRight.get_u() / m_scale), vpMath::round(bottomRight.get_v() / m_scale)),
1504  cvcolor, filled);
1505 #endif
1506  }
1507  }
1508  } else {
1509  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1510  }
1511 }
1512 
1525 void vpDisplayOpenCV::displayRectangle(const vpRect &rectangle, const vpColor &color, bool fill, unsigned int thickness)
1526 {
1528  if (fill == false) {
1529  if (color.id < vpColor::id_unknown) {
1530 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1531  cvRectangle(
1532  m_background,
1533  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1534  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1535  col[color.id], (int)thickness);
1536 #else
1537  cv::rectangle(
1538  m_background,
1539  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1540  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1541  col[color.id], (int)thickness);
1542 #endif
1543  } else {
1544  cvcolor = CV_RGB(color.R, color.G, color.B);
1545 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1546  cvRectangle(
1547  m_background,
1548  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1549  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1550  cvcolor, (int)thickness);
1551 
1552 #else
1553  cv::rectangle(
1554  m_background,
1555  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1556  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1557  cvcolor, (int)thickness);
1558 
1559 #endif
1560  }
1561  } else {
1562 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1563  int filled = cv::FILLED;
1564 #else
1565  int filled = CV_FILLED;
1566 #endif
1567  if (color.id < vpColor::id_unknown) {
1568 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1569  cvRectangle(
1570  m_background,
1571  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1572  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1573  col[color.id], filled);
1574 #else
1575  cv::rectangle(
1576  m_background,
1577  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1578  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1579  col[color.id], filled);
1580 #endif
1581  } else {
1582  cvcolor = CV_RGB(color.R, color.G, color.B);
1583 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1584  cvRectangle(
1585  m_background,
1586  cvPoint(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1587  cvPoint(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1588  cvcolor, filled);
1589 #else
1590  cv::rectangle(
1591  m_background,
1592  cv::Point(vpMath::round(rectangle.getLeft() / m_scale), vpMath::round(rectangle.getBottom() / m_scale)),
1593  cv::Point(vpMath::round(rectangle.getRight() / m_scale), vpMath::round(rectangle.getTop() / m_scale)),
1594  cvcolor, filled);
1595 #endif
1596  }
1597  }
1598  } else {
1599  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1600  }
1601 }
1602 
1618 bool vpDisplayOpenCV::getClick(bool blocking)
1619 {
1620  bool ret = false;
1622  flushDisplay();
1623  if (blocking) {
1624  lbuttondown = false;
1625  mbuttondown = false;
1626  rbuttondown = false;
1627  }
1628  do {
1629  if (lbuttondown) {
1630  ret = true;
1631  lbuttondown = false;
1632  }
1633  if (mbuttondown) {
1634  ret = true;
1635  mbuttondown = false;
1636  }
1637  if (rbuttondown) {
1638  ret = true;
1639  rbuttondown = false;
1640  }
1641  if (blocking)
1642 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1643  cvWaitKey(10);
1644 #else
1645  cv::waitKey(10);
1646 #endif
1647  } while (ret == false && blocking == true);
1648  } else {
1649  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1650  }
1651  return ret;
1652 }
1653 
1671 bool vpDisplayOpenCV::getClick(vpImagePoint &ip, bool blocking)
1672 {
1673  bool ret = false;
1674 
1676  flushDisplay();
1677 
1678  double u, v;
1679 
1680  if (blocking) {
1681  lbuttondown = false;
1682  mbuttondown = false;
1683  rbuttondown = false;
1684  }
1685  do {
1686  if (lbuttondown) {
1687  ret = true;
1688  u = (unsigned int)x_lbuttondown * m_scale;
1689  v = (unsigned int)y_lbuttondown * m_scale;
1690  ip.set_u(u);
1691  ip.set_v(v);
1692  lbuttondown = false;
1693  }
1694  if (mbuttondown) {
1695  ret = true;
1696  u = (unsigned int)x_mbuttondown * m_scale;
1697  v = (unsigned int)y_mbuttondown * m_scale;
1698  ip.set_u(u);
1699  ip.set_v(v);
1700  mbuttondown = false;
1701  }
1702  if (rbuttondown) {
1703  ret = true;
1704  u = (unsigned int)x_rbuttondown * m_scale;
1705  v = (unsigned int)y_rbuttondown * m_scale;
1706  ip.set_u(u);
1707  ip.set_v(v);
1708  rbuttondown = false;
1709  }
1710  if (blocking)
1711 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1712  cvWaitKey(10);
1713 #else
1714  cv::waitKey(10);
1715 #endif
1716  } while (ret == false && blocking == true);
1717  } else {
1718  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1719  }
1720  return ret;
1721 }
1722 
1743 {
1744  bool ret = false;
1745 
1747  // flushDisplay() ;
1748  double u, v;
1749  if (blocking) {
1750  lbuttondown = false;
1751  mbuttondown = false;
1752  rbuttondown = false;
1753  }
1754  do {
1755  if (lbuttondown) {
1756  ret = true;
1757  u = (unsigned int)x_lbuttondown * m_scale;
1758  v = (unsigned int)y_lbuttondown * m_scale;
1759  ip.set_u(u);
1760  ip.set_v(v);
1761  button = vpMouseButton::button1;
1762  lbuttondown = false;
1763  }
1764  if (mbuttondown) {
1765  ret = true;
1766  u = (unsigned int)x_mbuttondown * m_scale;
1767  v = (unsigned int)y_mbuttondown * m_scale;
1768  ip.set_u(u);
1769  ip.set_v(v);
1770  button = vpMouseButton::button2;
1771  mbuttondown = false;
1772  }
1773  if (rbuttondown) {
1774  ret = true;
1775  u = (unsigned int)x_rbuttondown * m_scale;
1776  v = (unsigned int)y_rbuttondown * m_scale;
1777  ip.set_u(u);
1778  ip.set_v(v);
1779  button = vpMouseButton::button3;
1780  rbuttondown = false;
1781  }
1782  if (blocking)
1783 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1784  cvWaitKey(10);
1785 #else
1786  cv::waitKey(10);
1787 #endif
1788  } while (ret == false && blocking == true);
1789  } else {
1790  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1791  }
1792  return ret;
1793 }
1794 
1819 {
1820  bool ret = false;
1822  // flushDisplay() ;
1823  double u, v;
1824  if (blocking) {
1825  lbuttonup = false;
1826  mbuttonup = false;
1827  rbuttonup = false;
1828  }
1829  do {
1830  if (lbuttonup) {
1831  ret = true;
1832  u = (unsigned int)x_lbuttonup * m_scale;
1833  v = (unsigned int)y_lbuttonup * m_scale;
1834  ip.set_u(u);
1835  ip.set_v(v);
1836  button = vpMouseButton::button1;
1837  lbuttonup = false;
1838  }
1839  if (mbuttonup) {
1840  ret = true;
1841  u = (unsigned int)x_mbuttonup * m_scale;
1842  v = (unsigned int)y_mbuttonup * m_scale;
1843  ip.set_u(u);
1844  ip.set_v(v);
1845  button = vpMouseButton::button2;
1846  mbuttonup = false;
1847  }
1848  if (rbuttonup) {
1849  ret = true;
1850  u = (unsigned int)x_rbuttonup * m_scale;
1851  v = (unsigned int)y_rbuttonup * m_scale;
1852  ip.set_u(u);
1853  ip.set_v(v);
1854  button = vpMouseButton::button3;
1855  rbuttonup = false;
1856  }
1857  if (blocking)
1858 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1859  cvWaitKey(10);
1860 #else
1861  cv::waitKey(10);
1862 #endif
1863  } while (ret == false && blocking == true);
1864  } else {
1865  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
1866  }
1867  return ret;
1868 }
1869 
1870 /*
1871  Gets the displayed image (including the overlay plane)
1872  and returns an RGBa image.
1873 */
1875 {
1876  vpImageConvert::convert(m_background, I);
1877  // should certainly be optimized.
1878 }
1879 
1880 void vpDisplayOpenCV::on_mouse(int event, int x, int y, int /*flags*/, void *display)
1881 {
1882  vpDisplayOpenCV *disp = static_cast<vpDisplayOpenCV *>(display);
1883  switch (event) {
1884 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1885  case CV_EVENT_MOUSEMOVE:
1886 #else
1887  case cv::EVENT_MOUSEMOVE:
1888 #endif
1889  {
1890  disp->move = true;
1891  disp->x_move = x;
1892  disp->y_move = y;
1893  break;
1894  }
1895 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1896  case CV_EVENT_LBUTTONDOWN:
1897 #else
1898  case cv::EVENT_LBUTTONDOWN:
1899 #endif
1900  {
1901  disp->lbuttondown = true;
1902  disp->x_lbuttondown = x;
1903  disp->y_lbuttondown = y;
1904  break;
1905  }
1906 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1907  case CV_EVENT_MBUTTONDOWN:
1908 #else
1909  case cv::EVENT_MBUTTONDOWN:
1910 #endif
1911  {
1912  disp->mbuttondown = true;
1913  disp->x_mbuttondown = x;
1914  disp->y_mbuttondown = y;
1915  break;
1916  }
1917 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1918  case CV_EVENT_RBUTTONDOWN:
1919 #else
1920  case cv::EVENT_RBUTTONDOWN:
1921 #endif
1922  {
1923  disp->rbuttondown = true;
1924  disp->x_rbuttondown = x;
1925  disp->y_rbuttondown = y;
1926  break;
1927  }
1928 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1929  case CV_EVENT_LBUTTONUP:
1930 #else
1931  case cv::EVENT_LBUTTONUP:
1932 #endif
1933  {
1934  disp->lbuttonup = true;
1935  disp->x_lbuttonup = x;
1936  disp->y_lbuttonup = y;
1937  break;
1938  }
1939 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1940  case CV_EVENT_MBUTTONUP:
1941 #else
1942  case cv::EVENT_MBUTTONUP:
1943 #endif
1944  {
1945  disp->mbuttonup = true;
1946  disp->x_mbuttonup = x;
1947  disp->y_mbuttonup = y;
1948  break;
1949  }
1950 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1951  case CV_EVENT_RBUTTONUP:
1952 #else
1953  case cv::EVENT_RBUTTONUP:
1954 #endif
1955  {
1956  disp->rbuttonup = true;
1957  disp->x_rbuttonup = x;
1958  disp->y_rbuttonup = y;
1959  break;
1960  }
1961 
1962  default:
1963  break;
1964  }
1965 }
1966 
1984 {
1986  int delay;
1987  flushDisplay();
1988  if (blocking)
1989  delay = 0;
1990  else
1991  delay = 10;
1992 
1993 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1994  int key_pressed = cvWaitKey(delay);
1995 #else
1996  int key_pressed = cv::waitKey(delay);
1997 #endif
1998 
1999  if (key_pressed == -1)
2000  return false;
2001  return true;
2002  } else {
2003  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2004  }
2005  // return false; // Never reached after throw()
2006 }
2026 bool vpDisplayOpenCV::getKeyboardEvent(std::string &key, bool blocking)
2027 {
2029  int delay;
2030  flushDisplay();
2031  if (blocking)
2032  delay = 0;
2033  else
2034  delay = 10;
2035 
2036 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2037  int key_pressed = cvWaitKey(delay);
2038 #else
2039  int key_pressed = cv::waitKey(delay);
2040 #endif
2041  if (key_pressed == -1)
2042  return false;
2043  else {
2044  // std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl;
2045  std::stringstream ss;
2046  ss << key_pressed;
2047  key = ss.str();
2048  }
2049  return true;
2050  } else {
2051  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2052  }
2053  // return false; // Never reached after throw()
2054 }
2055 
2067 {
2068  bool ret = false;
2069 
2071  // flushDisplay() ;
2072  if (move) {
2073  ret = true;
2074  double u = (unsigned int)x_move / m_scale;
2075  double v = (unsigned int)y_move / m_scale;
2076  ip.set_u(u);
2077  ip.set_v(v);
2078  move = false;
2079  }
2080  }
2081 
2082  else {
2083  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2084  }
2085  return ret;
2086 }
2087 
2099 {
2101  bool moved = getPointerMotionEvent(ip);
2102  if (!moved) {
2103  double u, v;
2104  u = (unsigned int)x_move / m_scale;
2105  v = (unsigned int)y_move / m_scale;
2106  ip.set_u(u);
2107  ip.set_v(v);
2108  }
2109  return false;
2110  } else {
2111  throw(vpDisplayException(vpDisplayException::notInitializedError, "OpenCV not initialized"));
2112  }
2113 }
2114 
2119 void vpDisplayOpenCV::getScreenSize(unsigned int &w, unsigned int &h)
2120 {
2121  w = h = 0;
2122 
2123 #if defined(VISP_HAVE_X11)
2124  vpDisplayX d;
2125  d.getScreenSize(w, h);
2126 #elif defined(VISP_HAVE_XRANDR)
2127  std::string command = "xrandr | grep '*'";
2128  FILE *fpipe = (FILE *)popen(command.c_str(), "r");
2129  char line[256];
2130  while (fgets(line, sizeof(line), fpipe)) {
2131  std::string str(line);
2132  std::size_t found = str.find("Failed");
2133 
2134  if (found == std::string::npos) {
2135  std::vector<std::string> elm;
2136  elm = vpIoTools::splitChain(str, " ");
2137  for (size_t i = 0; i < elm.size(); i++) {
2138  if (!elm[i].empty()) {
2139  std::vector<std::string> resolution = vpIoTools::splitChain(elm[i], "x");
2140  if (resolution.size() == 2) {
2141  std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2142  sswidth >> w;
2143  ssheight >> h;
2144  break;
2145  }
2146  }
2147  }
2148  }
2149  }
2150  pclose(fpipe);
2151 #elif defined(_WIN32)
2152 #if !defined(WINRT)
2153  w = GetSystemMetrics(SM_CXSCREEN);
2154  h = GetSystemMetrics(SM_CYSCREEN);
2155 #else
2156  throw(vpException(vpException::functionNotImplementedError, "The function vpDisplayOpenCV::getScreenSize() is not "
2157  "implemented on winrt"));
2158 #endif
2159 #endif
2160 }
2161 
2166 {
2167  unsigned int width, height;
2168  getScreenSize(width, height);
2169  return width;
2170 }
2171 
2176 {
2177  unsigned int width, height;
2178  getScreenSize(width, height);
2179  return height;
2180 }
2181 
2182 #elif !defined(VISP_BUILD_SHARED_LIBS)
2183 // Work arround to avoid warning: libvisp_core.a(vpDisplayOpenCV.cpp.o) has no
2184 // symbols
2185 void dummy_vpDisplayOpenCV(){};
2186 #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:134
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:175
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)
unsigned char B
Blue component.
Definition: vpRGBa.h:150
static const vpColor black
Definition: vpColor.h:174
static const vpColor darkRed
Definition: vpColor.h:181
#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:120
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:151
error that can be emited by ViSP classes.
Definition: vpException.h:71
static const vpColor lightGray
Definition: vpColor.h:176
void setFont(const std::string &font)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
bool getPointerPosition(vpImagePoint &ip)
static const vpColor darkBlue
Definition: vpColor.h:187
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:183
static int round(const double x)
Definition: vpMath.h:235
double getRight() const
Definition: vpRect.h:162
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static const vpColor lightRed
Definition: vpColor.h:179
virtual ~vpDisplayOpenCV()
Definition: vpRGBa.h:66
void displayImage(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:180
static const vpColor orange
Definition: vpColor.h:190
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:169
void set_i(const double ii)
Definition: vpImagePoint.h:167
double get_u() const
Definition: vpImagePoint.h:263
int m_windowXPosition
display position
Definition: vpDisplay.h:206
static const vpColor cyan
Definition: vpColor.h:189
static const vpColor lightGreen
Definition: vpColor.h:182
unsigned int m_scale
Definition: vpDisplay.h:212
void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Definition: vpDisplay.cpp:260
void set_u(const double u)
Definition: vpImagePoint.h:226
#define vpTRACE
Definition: vpDebug.h:416
static double sqr(double x)
Definition: vpMath.h:108
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 set_v(const double v)
Definition: vpImagePoint.h:237
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
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)
static std::vector< std::string > splitChain(const std::string &chain, const std::string &sep)
Definition: vpIoTools.cpp:1665
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static const vpColor gray
Definition: vpColor.h:177
double getLeft() const
Definition: vpRect.h:156
static const vpColor darkGray
Definition: vpColor.h:178
void set_j(const double jj)
Definition: vpImagePoint.h:178
bool getPointerMotionEvent(vpImagePoint &ip)
Error that can be emited by the vpDisplay class and its derivates.
unsigned int getHeight() const
Definition: vpImage.h:178
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:184
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:188
static const vpColor lightBlue
Definition: vpColor.h:185
static const vpColor purple
Definition: vpColor.h:191
static const vpColor white
Definition: vpColor.h:175
unsigned int getWidth() const
Definition: vpImage.h:229
double getBottom() const
Definition: vpRect.h:94
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:186