Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Image display.
32  *
33  * Authors:
34  * Christophe Collewet
35  * Eric Marchand
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 
46 #include <visp3/core/vpConfig.h>
47 
48 #if defined(VISP_HAVE_OPENCV)
49 
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <iostream>
53 #include <cmath> // std::fabs
54 #include <limits> // numeric_limits
55 
56 // Display stuff
57 #include <visp3/core/vpDisplay.h>
58 #include <visp3/gui/vpDisplayOpenCV.h>
59 #include <visp3/core/vpMath.h>
60 #include <visp3/core/vpImageTools.h>
61 #include <visp3/core/vpIoTools.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/imgproc/imgproc.hpp>
70 # include <opencv2/core/core_c.h> // for CV_FILLED versus cv::FILLED
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 
103  :
104  vpDisplay(),
105  #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
106  m_background(NULL), col(NULL), cvcolor(), font(NULL),
107  #else
108  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
109  #endif
110  fontHeight(10), x_move(0), y_move(0) , move(false),
111  x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
112  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
113  x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
114  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
115  x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
116  x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
117 {
118  setScale(scaleType, I.getWidth(), I.getHeight());
119  init(I) ;
120 }
121 
141  int x,
142  int y,
143  const std::string &title, vpScaleType scaleType)
144  :
145  vpDisplay(),
146  #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
147  m_background(NULL), col(NULL), cvcolor(), font(NULL),
148  #else
149  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
150  #endif
151  fontHeight(10), x_move(0), y_move(0) , move(false),
152  x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
153  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
154  x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
155  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
156  x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
157  x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
158 {
159  setScale(scaleType, I.getWidth(), I.getHeight());
160  init(I, x, y, title) ;
161 }
162 
163 
178  :
179  #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
180  m_background(NULL), col(NULL), cvcolor(), font(NULL),
181  #else
182  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
183  #endif
184  fontHeight(10), x_move(0), y_move(0) , move(false),
185  x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
186  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
187  x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
188  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
189  x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
190  x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
191 {
192  setScale(scaleType, I.getWidth(), I.getHeight());
193  init(I) ;
194 }
195 
212  int x,
213  int y,
214  const std::string &title, vpScaleType scaleType)
215  :
216  #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
217  m_background(NULL), col(NULL), cvcolor(), font(NULL),
218  #else
219  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
220  #endif
221  fontHeight(10), x_move(0), y_move(0) , move(false),
222  x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
223  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
224  x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
225  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
226  x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
227  x_rbuttonup(0), 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),
263  x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
264  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
265  x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
266  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
267  x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
268  x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
269 {
270  m_windowXPosition = x;
271  m_windowYPosition = y;
272 
273  if(! title.empty()){
274  m_title = title;
275  }
276  else{
277  std::ostringstream s;
278  s << m_nbWindows++;
279  m_title = std::string("Window ") + s.str();
280  }
281 
282  bool isInList;
283  do {
284  isInList = false;
285  for(size_t i = 0 ; i < m_listTitles.size() ; i++){
286  if(m_listTitles[i] == m_title){
287  std::ostringstream s;
288  s << m_nbWindows++;
289  m_title = std::string("Window ") + s.str();
290  isInList = true;
291  break;
292  }
293  }
294  }
295  while(isInList);
296 
297  m_listTitles.push_back(m_title);
298 }
299 
320  :
321  #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
322  m_background(NULL), col(NULL), cvcolor(), font(NULL),
323  #else
324  m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
325  #endif
326  fontHeight(10), x_move(0), y_move(0) , move(false),
327  x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
328  x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false),
329  x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
330  x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false),
331  x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false),
332  x_rbuttonup(0), y_rbuttonup(0), rbuttonup(false)
333 {
334 }
335 
340 {
341  closeDisplay() ;
342 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
343  cvReleaseImage(&m_background);
344 #endif
345 }
346 
355 void
357  int x,
358  int y,
359  const std::string &title)
360 {
361  if ((I.getHeight() == 0) || (I.getWidth()==0))
362  {
364  "Image not initialized")) ;
365  }
367  init (I.getWidth(), I.getHeight(), x, y, title) ;
368  I.display = this ;
370 }
371 
381 void
383  int x,
384  int y,
385  const std::string &title)
386 {
387  if ((I.getHeight() == 0) || (I.getWidth()==0))
388  {
390  "Image not initialized")) ;
391  }
392 
394  init (I.getWidth(), I.getHeight(), x, y, title) ;
395  I.display = this ;
397 }
398 
409 void
410 vpDisplayOpenCV::init(unsigned int w, unsigned int h,
411  int x, int y,
412  const std::string &title)
413 {
414  setScale(m_scaleType, w, h);
415 
416  this->m_width = w / m_scale;
417  this->m_height = h / m_scale;
418 
419  if (x != -1)
420  this->m_windowXPosition = x;
421  if (y != -1)
422  this->m_windowYPosition = y;
423 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
424  int flags = CV_WINDOW_AUTOSIZE;
425 #else
426  int flags = cv::WINDOW_AUTOSIZE;
427 #endif
428 
429  if(m_title.empty()){
430  if(!title.empty()){
431  m_title = std::string(title);
432  }
433  else{
434 
435  std::ostringstream s;
436  s << m_nbWindows++;
437  m_title = std::string("Window ") + s.str();
438  }
439 
440  bool isInList;
441  do{
442  isInList = false;
443  for(size_t i = 0 ; i < m_listTitles.size() ; i++){
444  if(m_listTitles[i] == m_title){
445  std::ostringstream s;
446  s << m_nbWindows++;
447  m_title = std::string("Window ") + s.str();
448  isInList = true;
449  break;
450  }
451  }
452  }
453  while(isInList);
454 
455  m_listTitles.push_back(m_title);
456  }
457 
458  /* Create the window*/
459 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
460  if (cvNamedWindow( this->m_title.c_str(), flags ) < 0) {
462  "OpenCV was not built with a display device")) ;
463  }
464 #else
465  cv::namedWindow( this->m_title, flags );
466 #endif
467 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
468  cvMoveWindow( this->m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition );
469 #else
470  cv::moveWindow( this->m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition );
471 #endif
472  move = false;
473  lbuttondown = false;
474  mbuttondown = false;
475  rbuttondown = false;
476  lbuttonup = false;
477  mbuttonup = false;
478  rbuttonup = false;
479 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
480  cvSetMouseCallback( this->m_title.c_str(), on_mouse, this );
481  col = new CvScalar[vpColor::id_unknown] ;
482 #else
483  cv::setMouseCallback( this->m_title, on_mouse, this );
484  col = new cv::Scalar[vpColor::id_unknown] ;
485 #endif
486 
487  /* Create color */
488  vpColor pcolor; // Predefined colors
489  pcolor = vpColor::lightBlue;
490  col[vpColor::id_lightBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
491  pcolor = vpColor::blue;
492  col[vpColor::id_blue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
493  pcolor = vpColor::darkBlue;
494  col[vpColor::id_darkBlue] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
495  pcolor = vpColor::lightRed;
496  col[vpColor::id_lightRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
497  pcolor = vpColor::red;
498  col[vpColor::id_red] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
499  pcolor = vpColor::darkRed;
500  col[vpColor::id_darkRed] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
501  pcolor = vpColor::lightGreen;
502  col[vpColor::id_lightGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
503  pcolor = vpColor::green;
504  col[vpColor::id_green] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
505  pcolor = vpColor::darkGreen;
506  col[vpColor::id_darkGreen] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
507  pcolor = vpColor::yellow;
508  col[vpColor::id_yellow] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
509  pcolor = vpColor::cyan;
510  col[vpColor::id_cyan] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
511  pcolor = vpColor::orange;
512  col[vpColor::id_orange] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
513  pcolor = vpColor::purple;
514  col[vpColor::id_purple] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
515  pcolor = vpColor::white;
516  col[vpColor::id_white] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
517  pcolor = vpColor::black;
518  col[vpColor::id_black] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
519  pcolor = vpColor::lightGray;
520  col[vpColor::id_lightGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
521  pcolor = vpColor::gray;
522  col[vpColor::id_gray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
523  pcolor = vpColor::darkGray;
524  col[vpColor::id_darkGray] = CV_RGB(pcolor.R, pcolor.G, pcolor.B) ;
525 
526 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
527  font = new CvFont;
528  cvInitFont( font, CV_FONT_HERSHEY_PLAIN, 0.70f,0.70f);
529  CvSize fontSize;
530  int baseline;
531  cvGetTextSize( "A", font, &fontSize, &baseline );
532 #else
533  int thickness = 1;
534  cv::Size fontSize;
535  int baseline;
536  fontSize = cv::getTextSize( "A", font, fontScale, thickness, &baseline );
537 #endif
538 
539  fontHeight = fontSize.height + baseline;
541 }
542 
543 
559 void
560 vpDisplayOpenCV::setFont(const std::string & /* font */)
561 {
562  vpERROR_TRACE("Not yet implemented" ) ;
563 }
564 
572 void
573 vpDisplayOpenCV::setTitle(const std::string & /* title */)
574 {
575 // static bool warn_displayed = false;
576 // if (! warn_displayed) {
577 // vpTRACE("Not implemented");
578 // warn_displayed = true;
579 // }
580 }
581 
582 
591 void vpDisplayOpenCV::setWindowPosition(int winx, int winy)
592 {
594  this->m_windowXPosition = winx;
595  this->m_windowYPosition = winy;
596 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
597  cvMoveWindow( this->m_title.c_str(), winx, winy );
598 #else
599  cv::moveWindow( this->m_title.c_str(), winx, winy );
600 #endif
601  }
602  else
603  {
605  "OpenCV not initialized")) ;
606  }
607 }
620 {
622  {
623 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
624  int depth = 8;
625  int channels = 3;
626  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
627  if (m_background != NULL){
628  if(m_background->nChannels != channels || m_background->depth != depth
629  || m_background->height != (int) m_height || m_background->width != (int) m_width){
630  if(m_background->nChannels != 0) cvReleaseImage(&m_background);
631  m_background = cvCreateImage( size, depth, channels );
632  }
633  }
634  else {
635  m_background = cvCreateImage( size, depth, channels );
636  }
637 
638  if (m_scale == 1) {
639  for (unsigned int i=0; i<m_height; i++) {
640  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep);
641  for (unsigned int j=0; j<m_width; j++) {
642  unsigned char val = I[i][j];
643  * ( dst_24 ++ ) = val;
644  * ( dst_24 ++ ) = val;
645  * ( dst_24 ++ ) = val;
646  }
647  }
648  }
649  else {
650  for (unsigned int i=0; i<m_height; i++) {
651  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep);
652  for (unsigned int j=0; j<m_width; j++) {
653  unsigned char val = I[i*m_scale][j*m_scale];
654  * ( dst_24 ++ ) = val;
655  * ( dst_24 ++ ) = val;
656  * ( dst_24 ++ ) = val;
657  }
658  }
659  }
660 
661 #else
662  int depth = CV_8U;
663  int channels = 3;
664  cv::Size size((int)m_width, (int)m_height);
665  if(m_background.channels() != channels || m_background.depth() != depth
666  || m_background.rows != (int) m_height || m_background.cols != (int) m_width){
667  m_background = cv::Mat( size, CV_MAKETYPE(depth, channels) );
668  }
669 
670  if (m_scale == 1) {
671  for (unsigned int i=0; i<m_height; i++) {
672  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width);
673  for (unsigned int j=0; j<m_width; j++) {
674  unsigned char val = I[i][j];
675  * ( dst_24 ++ ) = val;
676  * ( dst_24 ++ ) = val;
677  * ( dst_24 ++ ) = val;
678  }
679  }
680  }
681  else {
682  for (unsigned int i=0; i<m_height; i++) {
683  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width);
684  for (unsigned int j=0; j<m_width; j++) {
685  unsigned char val = I[i*m_scale][j*m_scale];
686  * ( dst_24 ++ ) = val;
687  * ( dst_24 ++ ) = val;
688  * ( dst_24 ++ ) = val;
689  }
690  }
691  }
692 #endif
693 
694  }
695  else
696  {
698  "OpenCV not initialized")) ;
699  }
700 }
701 
718  const unsigned int w, const unsigned int h )
719 {
721  {
722 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
723  int depth = 8;
724  int channels = 3;
725  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
726  if (m_background != NULL){
727  if(m_background->nChannels != channels || m_background->depth != depth
728  || m_background->height != (int) m_height || m_background->width != (int) m_width){
729  if(m_background->nChannels != 0) cvReleaseImage(&m_background);
730  m_background = cvCreateImage( size, depth, channels );
731  }
732  }
733  else {
734  m_background = cvCreateImage( size, depth, channels );
735  }
736 
737  if (m_scale == 1) {
738  unsigned int i_min = (unsigned int)iP.get_i();
739  unsigned int j_min = (unsigned int)iP.get_j();
740  unsigned int i_max = std::min(i_min + h, m_height);
741  unsigned int j_max = std::min(j_min + w, m_width);
742  for (unsigned int i=i_min; i<i_max; i++) {
743  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep + j_min*3);
744  for (unsigned int j=j_min; j<j_max; j++) {
745  unsigned char val = I[i][j];
746  * ( dst_24 ++ ) = val;
747  * ( dst_24 ++ ) = val;
748  * ( dst_24 ++ ) = val;
749  }
750  }
751  }
752  else {
753  int i_min = std::max((int)ceil(iP.get_i()/m_scale), 0);
754  int j_min = std::max((int)ceil(iP.get_j()/m_scale), 0);
755  int i_max = std::min((int)ceil((iP.get_i() + h)/m_scale), (int)m_height);
756  int j_max = std::min((int)ceil((iP.get_j() + w)/m_scale), (int)m_width);
757  for (int i=i_min; i<i_max; i++) {
758  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep + j_min*3);
759  for (int j=j_min; j<j_max; j++) {
760  unsigned char val = I[i*m_scale][j*m_scale];
761  * ( dst_24 ++ ) = val;
762  * ( dst_24 ++ ) = val;
763  * ( dst_24 ++ ) = val;
764  }
765  }
766  }
767 
768 #else
769  int depth = CV_8U;
770  int channels = 3;
771  cv::Size size((int)m_width, (int)m_height);
772  if(m_background.channels() != channels || m_background.depth() != depth
773  || m_background.rows != (int) m_height || m_background.cols != (int) m_width){
774  m_background = cv::Mat( size, CV_MAKETYPE(depth, channels) );
775  }
776 
777  if (m_scale == 1) {
778  unsigned int i_min = (unsigned int)iP.get_i();
779  unsigned int j_min = (unsigned int)iP.get_j();
780  unsigned int i_max = std::min(i_min + h, m_height);
781  unsigned int j_max = std::min(j_min + w, m_width);
782  for (unsigned int i=i_min; i<i_max; i++) {
783  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width + j_min*3);
784  for (unsigned int j=j_min; j<j_max; j++) {
785  unsigned char val = I[i][j];
786  * ( dst_24 ++ ) = val;
787  * ( dst_24 ++ ) = val;
788  * ( dst_24 ++ ) = val;
789  }
790  }
791  }
792  else {
793  int i_min = std::max((int)ceil(iP.get_i()/m_scale), 0);
794  int j_min = std::max((int)ceil(iP.get_j()/m_scale), 0);
795  int i_max = std::min((int)ceil((iP.get_i() + h)/m_scale), (int)m_height);
796  int j_max = std::min((int)ceil((iP.get_j() + w)/m_scale), (int)m_width);
797  for (int i=i_min; i<i_max; i++) {
798  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width + j_min*3);
799  for (int j=j_min; j<j_max; j++) {
800  unsigned char val = I[i*m_scale][j*m_scale];
801  * ( dst_24 ++ ) = val;
802  * ( dst_24 ++ ) = val;
803  * ( dst_24 ++ ) = val;
804  }
805  }
806  }
807 #endif
808  }
809  else
810  {
812  "OpenCV not initialized")) ;
813  }
814 }
815 
816 
829 {
830 
832  {
833 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
834  int depth = 8;
835  int channels = 3;
836  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
837  if (m_background != NULL){
838  if(m_background->nChannels != channels || m_background->depth != depth
839  || m_background->height != (int) m_height || m_background->width != (int) m_width){
840  if(m_background->nChannels != 0) cvReleaseImage(&m_background);
841  m_background = cvCreateImage( size, depth, channels );
842  }
843  }
844  else {
845  m_background = cvCreateImage( size, depth, channels );
846  }
847 
848  if (m_scale == 1) {
849  for (unsigned int i=0; i<m_height; i++) {
850  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep);
851  for (unsigned int j=0; j<m_width; j++) {
852  vpRGBa val = I[i][j];
853  * ( dst_24 ++ ) = val.B;
854  * ( dst_24 ++ ) = val.G;
855  * ( dst_24 ++ ) = val.R;
856  }
857  }
858  }
859  else {
860  for (unsigned int i=0; i<m_height; i++) {
861  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep);
862  for (unsigned int j=0; j<m_width; j++) {
863  vpRGBa val = I[i*m_scale][j*m_scale];
864  * ( dst_24 ++ ) = val.B;
865  * ( dst_24 ++ ) = val.G;
866  * ( dst_24 ++ ) = val.R;
867  }
868  }
869  }
870 #else
871  int depth = CV_8U;
872  int channels = 3;
873  cv::Size size((int)this->m_width, (int)this->m_height);
874  if(m_background.channels() != channels || m_background.depth() != depth
875  || m_background.rows != (int) m_height || m_background.cols != (int) m_width){
876  m_background = cv::Mat( size, CV_MAKETYPE(depth, channels) );
877  }
878 
879  if (m_scale == 1) {
880  for (unsigned int i=0; i<m_height; i++) {
881  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width);
882  for (unsigned int j=0; j<m_width; j++) {
883  vpRGBa val = I[i][j];
884  * ( dst_24 ++ ) = val.B;
885  * ( dst_24 ++ ) = val.G;
886  * ( dst_24 ++ ) = val.R;
887  }
888  }
889  }
890  else {
891  for (unsigned int i=0; i<m_height; i++) {
892  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width);
893  for (unsigned int j=0; j<m_width; j++) {
894  vpRGBa val = I[i*m_scale][j*m_scale];
895  * ( dst_24 ++ ) = val.B;
896  * ( dst_24 ++ ) = val.G;
897  * ( dst_24 ++ ) = val.R;
898  }
899  }
900  }
901 #endif
902  }
903  else
904  {
906  "OpenCV not initialized")) ;
907  }
908 }
909 
926  const unsigned int w, const unsigned int h )
927 {
929  {
930 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
931  int depth = 8;
932  int channels = 3;
933  CvSize size = cvSize((int)this->m_width, (int)this->m_height);
934  if (m_background != NULL){
935  if(m_background->nChannels != channels || m_background->depth != depth
936  || m_background->height != (int) m_height || m_background->width != (int) m_width){
937  if(m_background->nChannels != 0) cvReleaseImage(&m_background);
938  m_background = cvCreateImage( size, depth, channels );
939  }
940  }
941  else {
942  m_background = cvCreateImage( size, depth, channels );
943  }
944 
945  if (m_scale == 1) {
946  unsigned int i_min = (unsigned int)iP.get_i();
947  unsigned int j_min = (unsigned int)iP.get_j();
948  unsigned int i_max = std::min(i_min + h, m_height);
949  unsigned int j_max = std::min(j_min + w, m_width);
950  for (unsigned int i=i_min; i<i_max; i++) {
951  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep + j_min*3);
952  for (unsigned int j=j_min; j<j_max; j++) {
953  vpRGBa val = I[i][j];
954  * ( dst_24 ++ ) = val.B;
955  * ( dst_24 ++ ) = val.G;
956  * ( dst_24 ++ ) = val.R;
957  }
958  }
959  }
960  else {
961  int i_min = std::max((int)ceil(iP.get_i()/m_scale), 0);
962  int j_min = std::max((int)ceil(iP.get_j()/m_scale), 0);
963  int i_max = std::min((int)ceil((iP.get_i() + h)/m_scale), (int)m_height);
964  int j_max = std::min((int)ceil((iP.get_j() + w)/m_scale), (int)m_width);
965  for (int i=i_min; i<i_max; i++) {
966  unsigned char *dst_24 = ( unsigned char* ) m_background->imageData + (int)(i*m_background->widthStep + j_min*3);
967  for (int j=j_min; j<j_max; j++) {
968  vpRGBa val = I[i*m_scale][j*m_scale];
969  * ( dst_24 ++ ) = val.B;
970  * ( dst_24 ++ ) = val.G;
971  * ( dst_24 ++ ) = val.R;
972  }
973  }
974  }
975 #else
976  int depth = CV_8U;
977  int channels = 3;
978  cv::Size size((int)this->m_width, (int)this->m_height);
979  if(m_background.channels() != channels || m_background.depth() != depth
980  || m_background.rows != (int) m_height || m_background.cols != (int) m_width){
981  m_background = cv::Mat( size, CV_MAKETYPE(depth, channels) );
982  }
983 
984  if (m_scale == 1) {
985  unsigned int i_min = (unsigned int)iP.get_i();
986  unsigned int j_min = (unsigned int)iP.get_j();
987  unsigned int i_max = std::min(i_min + h, m_height);
988  unsigned int j_max = std::min(j_min + w, m_width);
989  for (unsigned int i=i_min; i<i_max; i++) {
990  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width + j_min*3);
991  for (unsigned int j=j_min; j<j_max; j++) {
992  vpRGBa val = I[i][j];
993  * ( dst_24 ++ ) = val.B;
994  * ( dst_24 ++ ) = val.G;
995  * ( dst_24 ++ ) = val.R;
996  }
997  }
998  }
999  else {
1000  int i_min = std::max((int)ceil(iP.get_i()/m_scale), 0);
1001  int j_min = std::max((int)ceil(iP.get_j()/m_scale), 0);
1002  int i_max = std::min((int)ceil((iP.get_i() + h)/m_scale), (int)m_height);
1003  int j_max = std::min((int)ceil((iP.get_j() + w)/m_scale), (int)m_width);
1004  for (int i=i_min; i<i_max; i++) {
1005  unsigned char *dst_24 = ( unsigned char* ) m_background.data + (int)(i*3*m_width + j_min*3);
1006  for (int j=j_min; j<j_max; j++) {
1007  vpRGBa val = I[i*m_scale][j*m_scale];
1008  * ( dst_24 ++ ) = val.B;
1009  * ( dst_24 ++ ) = val.G;
1010  * ( dst_24 ++ ) = val.R;
1011  }
1012  }
1013  }
1014 #endif
1015  }
1016  else
1017  {
1019  "OpenCV not initialized")) ;
1020  }
1021 }
1022 
1028 void vpDisplayOpenCV::displayImage(const unsigned char * /* I */)
1029 {
1030  vpTRACE(" not implemented ") ;
1031 }
1032 
1041 {
1042  if (col != NULL)
1043  {
1044  delete [] col ; col = NULL ;
1045  }
1046 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1047  if (font != NULL)
1048  {
1049  delete font ;
1050  font = NULL ;
1051  }
1052 #endif
1054 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1055  cvDestroyWindow( this->m_title.c_str() );
1056 #else
1057  cv::destroyWindow( this->m_title );
1058 #endif
1059 
1060  for(size_t i = 0 ; i < m_listTitles.size() ; i++){
1061  if(m_title == m_listTitles[i]){
1062  m_listTitles.erase(m_listTitles.begin()+(long int)i);
1063  break;
1064  }
1065  }
1066 
1067  m_title.clear();
1068 
1070  }
1071 }
1072 
1073 
1080 {
1082  {
1083 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1084  cvShowImage(this->m_title.c_str(), m_background );
1085  cvWaitKey(5);
1086 #else
1087  cv::imshow(this->m_title, m_background );
1088  cv::waitKey(5);
1089 #endif
1090  }
1091  else
1092  {
1094  "OpenCV not initialized")) ;
1095  }
1096 }
1097 
1103 void vpDisplayOpenCV::flushDisplayROI(const vpImagePoint &/*iP*/, const unsigned int /*width*/, const unsigned int /*height*/)
1104 {
1106  {
1107 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1108  cvShowImage(this->m_title.c_str(), m_background );
1109  cvWaitKey(5);
1110 #else
1111  cv::imshow(this->m_title.c_str(), m_background );
1112  cv::waitKey(5);
1113 #endif
1114  }
1115  else
1116  {
1118  "OpenCV not initialized")) ;
1119  }
1120 }
1121 
1122 
1126 void vpDisplayOpenCV::clearDisplay(const vpColor & /* color */)
1127 {
1128  static bool warn_displayed = false;
1129  if (! warn_displayed) {
1130  vpTRACE("Not implemented");
1131  warn_displayed = true;
1132  }
1133 }
1134 
1143  const vpImagePoint &ip2,
1144  const vpColor &color,
1145  unsigned int w, unsigned int h,
1146  unsigned int thickness)
1147 {
1149  {
1150  double a = ip2.get_i() - ip1.get_i() ;
1151  double b = ip2.get_j() - ip1.get_j() ;
1152  double lg = sqrt(vpMath::sqr(a)+vpMath::sqr(b)) ;
1153 
1154  //if ((a==0)&&(b==0))
1155  if ((std::fabs(a) <= std::numeric_limits<double>::epsilon())
1156  &&(std::fabs(b)<= std::numeric_limits<double>::epsilon()))
1157  {
1158  // DisplayCrossLarge(i1,j1,3,col) ;
1159  }
1160  else
1161  {
1162  a /= lg ;
1163  b /= lg ;
1164 
1165  vpImagePoint ip3;
1166  ip3.set_i(ip2.get_i() - w*a);
1167  ip3.set_j(ip2.get_j() - w*b);
1168 
1169  vpImagePoint ip4;
1170  ip4.set_i( ip3.get_i() - b*h );
1171  ip4.set_j( ip3.get_j() + a*h );
1172 
1173  if (lg > 2*vpImagePoint::distance(ip2, ip4) )
1174  displayLine ( ip2, ip4, color, thickness ) ;
1175 
1176  ip4.set_i( ip3.get_i() + b*h );
1177  ip4.set_j( ip3.get_j() - a*h );
1178 
1179  if (lg > 2*vpImagePoint::distance(ip2, ip4) )
1180  displayLine ( ip2, ip4, color, thickness ) ;
1181 
1182  displayLine ( ip1, ip2, color, thickness ) ;
1183  }
1184  }
1185  else
1186  {
1188  "OpenCV not initialized")) ;
1189  }
1190 }
1191 
1204  const char *text, const vpColor &color )
1205 {
1207  {
1208  if (color.id < vpColor::id_unknown) {
1209 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1210  cvPutText( m_background, text,
1211  cvPoint( vpMath::round( ip.get_u() / m_scale ),
1212  vpMath::round( ip.get_v() / m_scale + fontHeight ) ),
1213  font, col[color.id] );
1214 #else
1215  cv::putText( m_background, text,
1216  cv::Point( vpMath::round( ip.get_u() / m_scale ),
1217  vpMath::round( ip.get_v() / m_scale + fontHeight ) ),
1218  font, fontScale, col[color.id] );
1219 #endif
1220  }
1221  else {
1222  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1223 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1224  cvPutText( m_background, text,
1225  cvPoint( vpMath::round( ip.get_u() / m_scale ),
1226  vpMath::round( ip.get_v() / m_scale + fontHeight ) ),
1227  font, cvcolor );
1228 #else
1229  cv::putText( m_background, text,
1230  cv::Point( vpMath::round( ip.get_u() / m_scale ),
1231  vpMath::round( ip.get_v() / m_scale + fontHeight ) ),
1232  font, fontScale, cvcolor );
1233 #endif
1234  }
1235  }
1236  else
1237  {
1239  "OpenCV not initialized")) ;
1240  }
1241 }
1252  unsigned int radius,
1253  const vpColor &color,
1254  bool fill ,
1255  unsigned int thickness)
1256 {
1258  {
1259  if (fill == false) {
1260  if (color.id < vpColor::id_unknown) {
1261 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1262  cvCircle( m_background,
1263  cvPoint( vpMath::round( center.get_u() / m_scale ),
1264  vpMath::round( center.get_v() / m_scale ) ),
1265  (int)radius / m_scale, col[color.id], (int)thickness);
1266 #else
1267  cv::circle( m_background,
1268  cv::Point( vpMath::round( center.get_u() / m_scale ),
1269  vpMath::round( center.get_v() / m_scale ) ),
1270  (int)radius / m_scale, col[color.id], (int)thickness);
1271 #endif
1272  }
1273  else {
1274  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1275 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1276  cvCircle( m_background,
1277  cvPoint( vpMath::round( center.get_u() / m_scale ),
1278  vpMath::round( center.get_v() / m_scale ) ),
1279  (int)radius / m_scale, cvcolor, (int)thickness);
1280 #else
1281  cv::circle( m_background,
1282  cv::Point( vpMath::round( center.get_u() / m_scale ),
1283  vpMath::round( center.get_v() / m_scale ) ),
1284  (int)radius / m_scale, cvcolor, (int)thickness);
1285 #endif
1286  }
1287  }
1288  else {
1289 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1290  int filled = cv::FILLED;
1291 #else
1292  int filled = CV_FILLED;
1293 #endif
1294  if (color.id < vpColor::id_unknown) {
1295 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1296  cvCircle( m_background,
1297  cvPoint( vpMath::round( center.get_u() / m_scale ),
1298  vpMath::round( center.get_v() / m_scale ) ),
1299  (int)radius / m_scale, col[color.id], filled);
1300 #else
1301  cv::circle( m_background,
1302  cv::Point( vpMath::round( center.get_u() / m_scale ),
1303  vpMath::round( center.get_v() / m_scale ) ),
1304  (int)radius / m_scale, col[color.id], filled);
1305 #endif
1306  }
1307  else {
1308  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1309 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1310  cvCircle( m_background,
1311  cvPoint( vpMath::round( center.get_u() / m_scale ),
1312  vpMath::round( center.get_v() / m_scale ) ),
1313  (int)radius / m_scale, cvcolor, filled);
1314 #else
1315  cv::circle( m_background,
1316  cv::Point( vpMath::round( center.get_u() / m_scale ),
1317  vpMath::round( center.get_v() / m_scale ) ),
1318  (int)radius / m_scale, cvcolor, filled);
1319 #endif
1320  }
1321  }
1322  }
1323  else
1324  {
1326  "OpenCV not initialized")) ;
1327  }
1328 }
1329 
1337 void
1339  unsigned int size,
1340  const vpColor &color,
1341  unsigned int thickness)
1342 {
1344  {
1345  vpImagePoint top,bottom,left,right;
1346  top.set_i(ip.get_i()-size/2);
1347  top.set_j(ip.get_j());
1348  bottom.set_i(ip.get_i()+size/2);
1349  bottom.set_j(ip.get_j());
1350  left.set_i(ip.get_i());
1351  left.set_j(ip.get_j()-size/2);
1352  right.set_i(ip.get_i());
1353  right.set_j(ip.get_j()+size/2);
1354  displayLine(top, bottom, color, thickness) ;
1355  displayLine(left, right, color, thickness) ;
1356  }
1357  else
1358  {
1360  "OpenCV not initialized")) ;
1361  }
1362 
1363 }
1364 
1372 void
1374  const vpImagePoint &ip2,
1375  const vpColor &color,
1376  unsigned int thickness)
1377 {
1379  {
1380  double size = 10.*m_scale;
1381  double length = sqrt(vpMath::sqr(ip2.get_i() - ip1.get_i()) + vpMath::sqr(ip2.get_j() - ip1.get_j()));
1382  double deltaj = size/length*(ip2.get_j() - ip1.get_j());
1383  double deltai = size/length*(ip2.get_i() - ip1.get_i());
1384  double slope = (ip2.get_i() - ip1.get_i()) / (ip2.get_j() - ip1.get_j());
1385  double orig = ip1.get_i() - slope*ip1.get_j();
1386  for(unsigned int j=(unsigned int)ip1.get_j(); j< ip2.get_j(); j+=(unsigned int)(2*deltaj)) {
1387  double i = slope*j+orig;
1388  displayLine(vpImagePoint(i, j), vpImagePoint(i+deltai, j+deltaj), color, thickness);
1389  }
1390  }
1391  else
1392  {
1394  "OpenCV not initialized")) ;
1395  }
1396 }
1397 
1398 
1405 void
1407  const vpImagePoint &ip2,
1408  const vpColor &color,
1409  unsigned int thickness)
1410 {
1412  {
1413  if (color.id < vpColor::id_unknown) {
1414 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1415  cvLine( m_background,
1416  cvPoint( vpMath::round( ip1.get_u() / m_scale ),
1417  vpMath::round( ip1.get_v() / m_scale ) ),
1418  cvPoint( vpMath::round( ip2.get_u() / m_scale ),
1419  vpMath::round( ip2.get_v() / m_scale ) ),
1420  col[color.id], (int) thickness);
1421 #else
1422  cv::line( m_background,
1423  cv::Point( vpMath::round( ip1.get_u() / m_scale ),
1424  vpMath::round( ip1.get_v() / m_scale ) ),
1425  cv::Point( vpMath::round( ip2.get_u() / m_scale ),
1426  vpMath::round( ip2.get_v() / m_scale ) ),
1427  col[color.id], (int) thickness);
1428 #endif
1429  }
1430  else {
1431  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1432 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1433  cvLine( m_background,
1434  cvPoint( vpMath::round( ip1.get_u() / m_scale ),
1435  vpMath::round( ip1.get_v() / m_scale ) ),
1436  cvPoint( vpMath::round( ip2.get_u() / m_scale ),
1437  vpMath::round( ip2.get_v() / m_scale ) ),
1438  cvcolor, (int) thickness);
1439 #else
1440  cv::line( m_background,
1441  cv::Point( vpMath::round( ip1.get_u() / m_scale ),
1442  vpMath::round( ip1.get_v() / m_scale ) ),
1443  cv::Point( vpMath::round( ip2.get_u() / m_scale ),
1444  vpMath::round( ip2.get_v() / m_scale ) ),
1445  cvcolor, (int) thickness);
1446 #endif
1447  }
1448  }
1449  else
1450  {
1452  "OpenCV not initialized")) ;
1453  }
1454 }
1455 
1462 void vpDisplayOpenCV::displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness)
1463 {
1465  {
1466  for(unsigned int i=0; i<thickness; i++) {
1467  if (color.id < vpColor::id_unknown) {
1468  #if VISP_HAVE_OPENCV_VERSION < 0x020408
1469  cvLine( m_background,
1470  cvPoint( vpMath::round( ip.get_u() / m_scale ),
1471  vpMath::round( ip.get_v() / m_scale ) ),
1472  cvPoint( vpMath::round( ip.get_u() / m_scale + thickness-1),
1473  vpMath::round( ip.get_v() / m_scale ) ),
1474  col[color.id], (int) thickness);
1475  #else
1476  cv::line( m_background,
1477  cv::Point( vpMath::round( ip.get_u() / m_scale ),
1478  vpMath::round( ip.get_v() / m_scale ) ),
1479  cv::Point( vpMath::round( ip.get_u() / m_scale + thickness-1),
1480  vpMath::round( ip.get_v() / m_scale) ),
1481  col[color.id], (int) thickness);
1482  #endif
1483  }
1484  else {
1485  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1486  #if VISP_HAVE_OPENCV_VERSION < 0x020408
1487  cvLine( m_background,
1488  cvPoint( vpMath::round( ip.get_u() / m_scale ),
1489  vpMath::round( ip.get_v() / m_scale ) ),
1490  cvPoint( vpMath::round( ip.get_u() / m_scale + thickness-1),
1491  vpMath::round( ip.get_v() / m_scale ) ),
1492  cvcolor, (int) thickness);
1493  #else
1494  cv::line( m_background,
1495  cv::Point( vpMath::round( ip.get_u() / m_scale ),
1496  vpMath::round( ip.get_v() / m_scale ) ),
1497  cv::Point( vpMath::round( ip.get_u() / m_scale + thickness-1),
1498  vpMath::round( ip.get_v() / m_scale) ),
1499  cvcolor, (int) thickness);
1500  #endif
1501  }
1502  }
1503  }
1504  else
1505  {
1507  "OpenCV not initialized")) ;
1508  }
1509 }
1510 
1524 void
1526  unsigned int w, unsigned int h,
1527  const vpColor &color, bool fill,
1528  unsigned int thickness)
1529 {
1531  {
1532  if (fill == false) {
1533  if (color.id < vpColor::id_unknown) {
1534 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1535  cvRectangle( m_background,
1536  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1537  vpMath::round( topLeft.get_v() / m_scale) ),
1538  cvPoint( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1539  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1540  col[color.id], (int)thickness);
1541 #else
1542  cv::rectangle( m_background,
1543  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1544  vpMath::round( topLeft.get_v() / m_scale ) ),
1545  cv::Point( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1546  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1547  col[color.id], (int)thickness);
1548 #endif
1549  }
1550  else {
1551  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1552 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1553  cvRectangle( m_background,
1554  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1555  vpMath::round( topLeft.get_v() / m_scale ) ),
1556  cvPoint( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1557  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1558  cvcolor, (int)thickness);
1559 #else
1560  cv::rectangle( m_background,
1561  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1562  vpMath::round( topLeft.get_v() / m_scale ) ),
1563  cv::Point( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1564  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1565  cvcolor, (int)thickness);
1566 #endif
1567  }
1568  }
1569  else {
1570 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1571  int filled = cv::FILLED;
1572 #else
1573  int filled = CV_FILLED;
1574 #endif
1575  if (color.id < vpColor::id_unknown) {
1576 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1577  cvRectangle( m_background,
1578  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1579  vpMath::round( topLeft.get_v() / m_scale ) ),
1580  cvPoint( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1581  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1582  col[color.id], filled);
1583 #else
1584  cv::rectangle( m_background,
1585  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1586  vpMath::round( topLeft.get_v() / m_scale ) ),
1587  cv::Point( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1588  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1589  col[color.id], filled);
1590 #endif
1591  }
1592  else {
1593  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1594 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1595  cvRectangle( m_background,
1596  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1597  vpMath::round( topLeft.get_v() / m_scale ) ),
1598  cvPoint( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1599  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1600  cvcolor, filled);
1601 #else
1602  cv::rectangle( m_background,
1603  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1604  vpMath::round( topLeft.get_v() / m_scale ) ),
1605  cv::Point( vpMath::round( (topLeft.get_u()+w) / m_scale ),
1606  vpMath::round( (topLeft.get_v()+h) / m_scale ) ),
1607  cvcolor, filled);
1608 #endif
1609  }
1610  }
1611  }
1612  else
1613  {
1615  "OpenCV not initialized")) ;
1616  }
1617 }
1630 void
1632  const vpImagePoint &bottomRight,
1633  const vpColor &color, bool fill,
1634  unsigned int thickness )
1635 {
1637  {
1638  if (fill == false) {
1639  if (color.id < vpColor::id_unknown) {
1640 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1641  cvRectangle( m_background,
1642  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1643  vpMath::round( topLeft.get_v() / m_scale ) ),
1644  cvPoint( vpMath::round( bottomRight.get_u() / m_scale ),
1645  vpMath::round( bottomRight.get_v() / m_scale) ),
1646  col[color.id], (int)thickness);
1647 #else
1648  cv::rectangle( m_background,
1649  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1650  vpMath::round( topLeft.get_v() / m_scale ) ),
1651  cv::Point( vpMath::round( bottomRight.get_u() / m_scale ),
1652  vpMath::round( bottomRight.get_v() / m_scale ) ),
1653  col[color.id], (int)thickness);
1654 #endif
1655  }
1656  else {
1657  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1658 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1659  cvRectangle( m_background,
1660  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1661  vpMath::round( topLeft.get_v() / m_scale ) ),
1662  cvPoint( vpMath::round( bottomRight.get_u() / m_scale ),
1663  vpMath::round( bottomRight.get_v() / m_scale ) ),
1664  cvcolor, (int)thickness);
1665 #else
1666  cv::rectangle( m_background,
1667  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1668  vpMath::round( topLeft.get_v() / m_scale ) ),
1669  cv::Point( vpMath::round( bottomRight.get_u() / m_scale ),
1670  vpMath::round( bottomRight.get_v() / m_scale ) ),
1671  cvcolor, (int)thickness);
1672 #endif
1673  }
1674  }
1675  else {
1676 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1677  int filled = cv::FILLED;
1678 #else
1679  int filled = CV_FILLED;
1680 #endif
1681  if (color.id < vpColor::id_unknown) {
1682 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1683  cvRectangle( m_background,
1684  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1685  vpMath::round( topLeft.get_v() / m_scale ) ),
1686  cvPoint( vpMath::round( bottomRight.get_u() / m_scale ),
1687  vpMath::round( bottomRight.get_v() / m_scale ) ),
1688  col[color.id], filled);
1689 #else
1690  cv::rectangle( m_background,
1691  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1692  vpMath::round( topLeft.get_v() / m_scale ) ),
1693  cv::Point( vpMath::round( bottomRight.get_u() / m_scale ),
1694  vpMath::round( bottomRight.get_v() / m_scale ) ),
1695  col[color.id], filled);
1696 #endif
1697  }
1698  else {
1699  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1700 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1701  cvRectangle( m_background,
1702  cvPoint( vpMath::round( topLeft.get_u() / m_scale ),
1703  vpMath::round( topLeft.get_v() / m_scale ) ),
1704  cvPoint( vpMath::round( bottomRight.get_u() / m_scale ),
1705  vpMath::round( bottomRight.get_v() / m_scale ) ),
1706  cvcolor, filled);
1707 #else
1708  cv::rectangle( m_background,
1709  cv::Point( vpMath::round( topLeft.get_u() / m_scale ),
1710  vpMath::round( topLeft.get_v() / m_scale ) ),
1711  cv::Point( vpMath::round( bottomRight.get_u() / m_scale ),
1712  vpMath::round( bottomRight.get_v() / m_scale ) ),
1713  cvcolor, filled);
1714 #endif
1715  }
1716  }
1717  }
1718  else
1719  {
1721  "OpenCV not initialized")) ;
1722  }
1723 }
1724 
1737 void
1739  const vpColor &color, bool fill,
1740  unsigned int thickness)
1741 {
1743  {
1744  if (fill == false) {
1745  if (color.id < vpColor::id_unknown) {
1746 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1747  cvRectangle( m_background,
1748  cvPoint( vpMath::round( rectangle.getLeft() / m_scale ),
1749  vpMath::round( rectangle.getBottom() / m_scale ) ),
1750  cvPoint( vpMath::round( rectangle.getRight() / m_scale ),
1751  vpMath::round( rectangle.getTop() / m_scale ) ),
1752  col[color.id], (int)thickness);
1753 #else
1754  cv::rectangle( m_background,
1755  cv::Point( vpMath::round( rectangle.getLeft() / m_scale ),
1756  vpMath::round( rectangle.getBottom() / m_scale ) ),
1757  cv::Point( vpMath::round( rectangle.getRight() / m_scale ),
1758  vpMath::round( rectangle.getTop() / m_scale ) ),
1759  col[color.id], (int)thickness);
1760 #endif
1761  }
1762  else {
1763  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1764 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1765  cvRectangle( m_background,
1766  cvPoint( vpMath::round( rectangle.getLeft() / m_scale ),
1767  vpMath::round( rectangle.getBottom() / m_scale ) ),
1768  cvPoint( vpMath::round( rectangle.getRight() / m_scale ),
1769  vpMath::round( rectangle.getTop() / m_scale ) ),
1770  cvcolor, (int)thickness);
1771 
1772 #else
1773  cv::rectangle( m_background,
1774  cv::Point( vpMath::round( rectangle.getLeft() / m_scale ),
1775  vpMath::round( rectangle.getBottom() / m_scale ) ),
1776  cv::Point( vpMath::round( rectangle.getRight() / m_scale ),
1777  vpMath::round( rectangle.getTop() / m_scale ) ),
1778  cvcolor, (int)thickness);
1779 
1780 #endif
1781  }
1782  }
1783  else {
1784 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1785  int filled = cv::FILLED;
1786 #else
1787  int filled = CV_FILLED;
1788 #endif
1789  if (color.id < vpColor::id_unknown) {
1790 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1791  cvRectangle( m_background,
1792  cvPoint( vpMath::round( rectangle.getLeft() / m_scale ),
1793  vpMath::round( rectangle.getBottom() / m_scale ) ),
1794  cvPoint( vpMath::round( rectangle.getRight() / m_scale ),
1795  vpMath::round( rectangle.getTop() / m_scale ) ),
1796  col[color.id], filled);
1797 #else
1798  cv::rectangle( m_background,
1799  cv::Point( vpMath::round( rectangle.getLeft() / m_scale ),
1800  vpMath::round( rectangle.getBottom() / m_scale ) ),
1801  cv::Point( vpMath::round( rectangle.getRight() / m_scale ),
1802  vpMath::round( rectangle.getTop() / m_scale ) ),
1803  col[color.id], filled);
1804 #endif
1805  }
1806  else {
1807  cvcolor = CV_RGB(color.R, color.G, color.B) ;
1808 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1809  cvRectangle( m_background,
1810  cvPoint( vpMath::round( rectangle.getLeft() / m_scale ),
1811  vpMath::round( rectangle.getBottom() / m_scale ) ),
1812  cvPoint( vpMath::round( rectangle.getRight() / m_scale ),
1813  vpMath::round( rectangle.getTop() / m_scale ) ),
1814  cvcolor, filled);
1815 #else
1816  cv::rectangle( m_background,
1817  cv::Point( vpMath::round( rectangle.getLeft() / m_scale ),
1818  vpMath::round( rectangle.getBottom() / m_scale ) ),
1819  cv::Point( vpMath::round( rectangle.getRight() / m_scale ),
1820  vpMath::round( rectangle.getTop() / m_scale ) ),
1821  cvcolor, filled);
1822 #endif
1823  }
1824  }
1825  }
1826  else
1827  {
1829  "OpenCV not initialized")) ;
1830  }
1831 }
1832 
1833 
1834 
1850 bool
1852 {
1853  bool ret = false;
1855  flushDisplay() ;
1856  if (blocking){
1857  lbuttondown = false;
1858  mbuttondown = false;
1859  rbuttondown = false;
1860  }
1861  do {
1862  if (lbuttondown){
1863  ret = true ;
1864  lbuttondown = false;
1865  }
1866  if (mbuttondown){
1867  ret = true ;
1868  mbuttondown = false;
1869  }
1870  if (rbuttondown){
1871  ret = true ;
1872  rbuttondown = false;
1873  }
1874  if (blocking)
1875 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1876  cvWaitKey(10);
1877 #else
1878  cv::waitKey(10);
1879 #endif
1880  } while ( ret == false && blocking == true);
1881  }
1882  else {
1884  "OpenCV not initialized")) ;
1885  }
1886  return ret;
1887 }
1888 
1906 bool
1908 {
1909  bool ret = false;
1910 
1912  flushDisplay() ;
1913 
1914  double u, v;
1915 
1916  if (blocking){
1917  lbuttondown = false;
1918  mbuttondown = false;
1919  rbuttondown = false;
1920  }
1921  do {
1922  if (lbuttondown){
1923  ret = true ;
1924  u = (unsigned int)x_lbuttondown * m_scale;
1925  v = (unsigned int)y_lbuttondown * m_scale;
1926  ip.set_u( u );
1927  ip.set_v( v );
1928  lbuttondown = false;
1929  }
1930  if (mbuttondown){
1931  ret = true ;
1932  u = (unsigned int)x_mbuttondown * m_scale;
1933  v = (unsigned int)y_mbuttondown * m_scale;
1934  ip.set_u( u );
1935  ip.set_v( v );
1936  mbuttondown = false;
1937  }
1938  if (rbuttondown){
1939  ret = true ;
1940  u = (unsigned int)x_rbuttondown * m_scale;
1941  v = (unsigned int)y_rbuttondown * m_scale;
1942  ip.set_u( u );
1943  ip.set_v( v );
1944  rbuttondown = false;
1945  }
1946  if (blocking)
1947 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1948  cvWaitKey(10);
1949 #else
1950  cv::waitKey(10);
1951 #endif
1952  } while ( ret == false && blocking == true);
1953  }
1954  else {
1956  "OpenCV not initialized")) ;
1957  }
1958  return ret ;
1959 }
1960 
1961 
1981 bool
1984  bool blocking)
1985 {
1986  bool ret = false;
1987 
1989  //flushDisplay() ;
1990  double u, v;
1991  if (blocking){
1992  lbuttondown = false;
1993  mbuttondown = false;
1994  rbuttondown = false;
1995  }
1996  do {
1997  if (lbuttondown){
1998  ret = true ;
1999  u = (unsigned int)x_lbuttondown * m_scale;
2000  v = (unsigned int)y_lbuttondown * m_scale;
2001  ip.set_u( u );
2002  ip.set_v( v );
2003  button = vpMouseButton::button1;
2004  lbuttondown = false;
2005  }
2006  if (mbuttondown){
2007  ret = true ;
2008  u = (unsigned int)x_mbuttondown * m_scale;
2009  v = (unsigned int)y_mbuttondown * m_scale;
2010  ip.set_u( u );
2011  ip.set_v( v );
2012  button = vpMouseButton::button2;
2013  mbuttondown = false;
2014  }
2015  if (rbuttondown){
2016  ret = true ;
2017  u = (unsigned int)x_rbuttondown * m_scale;
2018  v = (unsigned int)y_rbuttondown * m_scale;
2019  ip.set_u( u );
2020  ip.set_v( v );
2021  button = vpMouseButton::button3;
2022  rbuttondown = false;
2023  }
2024  if (blocking)
2025 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2026  cvWaitKey(10);
2027 #else
2028  cv::waitKey(10);
2029 #endif
2030  } while ( ret == false && blocking == true);
2031  }
2032  else {
2034  "OpenCV not initialized")) ;
2035  }
2036  return ret;
2037 }
2038 
2062 bool
2065  bool blocking)
2066 {
2067  bool ret = false;
2069  //flushDisplay() ;
2070  double u, v;
2071  if (blocking){
2072  lbuttonup = false;
2073  mbuttonup = false;
2074  rbuttonup = false;
2075  }
2076  do {
2077  if (lbuttonup){
2078  ret = true ;
2079  u = (unsigned int)x_lbuttonup * m_scale;
2080  v = (unsigned int)y_lbuttonup * m_scale;
2081  ip.set_u( u );
2082  ip.set_v( v );
2083  button = vpMouseButton::button1;
2084  lbuttonup = false;
2085  }
2086  if (mbuttonup){
2087  ret = true ;
2088  u = (unsigned int)x_mbuttonup * m_scale;
2089  v = (unsigned int)y_mbuttonup * m_scale;
2090  ip.set_u( u );
2091  ip.set_v( v );
2092  button = vpMouseButton::button2;
2093  mbuttonup = false;
2094  }
2095  if (rbuttonup){
2096  ret = true ;
2097  u = (unsigned int)x_rbuttonup * m_scale;
2098  v = (unsigned int)y_rbuttonup * m_scale;
2099  ip.set_u( u );
2100  ip.set_v( v );
2101  button = vpMouseButton::button3;
2102  rbuttonup = false;
2103  }
2104  if (blocking)
2105 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2106  cvWaitKey(10);
2107 #else
2108  cv::waitKey(10);
2109 #endif
2110  } while ( ret == false && blocking == true);
2111  }
2112  else {
2114  "OpenCV not initialized" ) ) ;
2115  }
2116  return ret;
2117 }
2118 
2119 /*
2120  Gets the displayed image (including the overlay plane)
2121  and returns an RGBa image.
2122 */
2124 {
2125  vpImageConvert::convert(m_background, I);
2126  // should certainly be optimized.
2127 }
2128 
2129 void vpDisplayOpenCV::on_mouse( int event, int x, int y, int /*flags*/, void* display )
2130 {
2131  vpDisplayOpenCV* disp = (vpDisplayOpenCV*)display;
2132  switch ( event )
2133  {
2134 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2135  case CV_EVENT_MOUSEMOVE:
2136 #else
2137  case cv::EVENT_MOUSEMOVE:
2138 #endif
2139  {
2140  disp->move = true;
2141  disp->x_move = x;
2142  disp->y_move = y;
2143  break;
2144  }
2145 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2146  case CV_EVENT_LBUTTONDOWN:
2147 #else
2148  case cv::EVENT_LBUTTONDOWN:
2149 #endif
2150  {
2151  disp->lbuttondown = true;
2152  disp->x_lbuttondown = x;
2153  disp->y_lbuttondown = y;
2154  break;
2155  }
2156 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2157  case CV_EVENT_MBUTTONDOWN:
2158 #else
2159  case cv::EVENT_MBUTTONDOWN:
2160 #endif
2161  {
2162  disp->mbuttondown = true;
2163  disp->x_mbuttondown = x;
2164  disp->y_mbuttondown = y;
2165  break;
2166  }
2167 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2168  case CV_EVENT_RBUTTONDOWN:
2169 #else
2170  case cv::EVENT_RBUTTONDOWN:
2171 #endif
2172  {
2173  disp->rbuttondown = true;
2174  disp->x_rbuttondown = x;
2175  disp->y_rbuttondown = y;
2176  break;
2177  }
2178 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2179  case CV_EVENT_LBUTTONUP:
2180 #else
2181  case cv::EVENT_LBUTTONUP:
2182 #endif
2183  {
2184  disp->lbuttonup = true;
2185  disp->x_lbuttonup = x;
2186  disp->y_lbuttonup = y;
2187  break;
2188  }
2189 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2190  case CV_EVENT_MBUTTONUP:
2191 #else
2192  case cv::EVENT_MBUTTONUP:
2193 #endif
2194  {
2195  disp->mbuttonup = true;
2196  disp->x_mbuttonup = x;
2197  disp->y_mbuttonup = y;
2198  break;
2199  }
2200 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2201  case CV_EVENT_RBUTTONUP:
2202 #else
2203  case cv::EVENT_RBUTTONUP:
2204 #endif
2205  {
2206  disp->rbuttonup = true;
2207  disp->x_rbuttonup = x;
2208  disp->y_rbuttonup = y;
2209  break;
2210  }
2211 
2212  default :
2213  break;
2214  }
2215 }
2216 
2233 bool
2235 {
2237  int delay;
2238  flushDisplay() ;
2239  if (blocking)
2240  delay = 0;
2241  else
2242  delay = 10;
2243 
2244 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2245  int key_pressed = cvWaitKey(delay);
2246 #else
2247  int key_pressed = cv::waitKey(delay);
2248 #endif
2249 
2250  if (key_pressed == -1)
2251  return false;
2252  return true;
2253  }
2254  else {
2256  "OpenCV not initialized")) ;
2257  }
2258  //return false; // Never reached after throw()
2259 }
2279 bool
2280 vpDisplayOpenCV::getKeyboardEvent(std::string &key, bool blocking)
2281 {
2283  int delay;
2284  flushDisplay() ;
2285  if (blocking)
2286  delay = 0;
2287  else
2288  delay = 10;
2289 
2290 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
2291  int key_pressed = cvWaitKey(delay);
2292 #else
2293  int key_pressed = cv::waitKey(delay);
2294 #endif
2295  if (key_pressed == -1)
2296  return false;
2297  else {
2298  //std::cout << "Key pressed: \"" << key_pressed << "\"" << std::endl;
2299  std::stringstream ss;
2300  ss << key_pressed;
2301  key = ss.str();
2302  }
2303  return true;
2304  }
2305  else {
2307  "OpenCV not initialized")) ;
2308  }
2309  //return false; // Never reached after throw()
2310 }
2311 
2322 bool
2324 {
2325  bool ret = false;
2326 
2328  //flushDisplay() ;
2329  if (move){
2330  ret = true ;
2331  double u = (unsigned int)x_move / m_scale;
2332  double v = (unsigned int)y_move / m_scale;
2333  ip.set_u( u );
2334  ip.set_v( v );
2335  move = false;
2336  }
2337  }
2338 
2339  else {
2341  "OpenCV not initialized")) ;
2342  }
2343  return ret;
2344 }
2345 
2356 bool
2358 {
2360  bool moved = getPointerMotionEvent(ip);
2361  if (!moved)
2362  {
2363  double u, v;
2364  u = (unsigned int)x_move / m_scale;
2365  v = (unsigned int)y_move / m_scale;
2366  ip.set_u( u );
2367  ip.set_v( v );
2368  }
2369  return false;
2370  }
2371  else {
2373  "OpenCV not initialized")) ;
2374  }
2375 }
2376 
2381 void vpDisplayOpenCV::getScreenSize ( unsigned int &w, unsigned int &h )
2382 {
2383  w = h = 0;
2384 
2385 #if defined(VISP_HAVE_X11)
2386  vpDisplayX d;
2387  d.getScreenSize(w, h);
2388 #elif defined(VISP_HAVE_XRANDR)
2389  std::string command="xrandr | grep '*'";
2390  FILE *fpipe = (FILE*)popen(command.c_str(),"r");
2391  char line[256];
2392  while ( fgets( line, sizeof(line), fpipe))
2393  {
2394  std::string str(line);
2395  std::size_t found = str.find("Failed");
2396 
2397  if (found == std::string::npos) {
2398  std::vector<std::string> elm;
2399  elm = vpIoTools::splitChain(str, " ");
2400  for(size_t i=0; i<elm.size(); i++) {
2401  if (! elm[i].empty()) {
2402  std::vector<std::string> resolution = vpIoTools::splitChain(elm[i], "x");
2403  if (resolution.size() == 2) {
2404  std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2405  sswidth >> w;
2406  ssheight >> h;
2407  break;
2408  }
2409  }
2410  }
2411  }
2412  }
2413  pclose(fpipe);
2414 #elif defined(_WIN32)
2415 # if !defined(WINRT)
2416  w = GetSystemMetrics(SM_CXSCREEN);
2417  h = GetSystemMetrics(SM_CYSCREEN);
2418 # else
2419  throw(vpException(vpException::functionNotImplementedError, "The function vpDisplayOpenCV::getScreenSize() is not implemented on winrt"));
2420 # endif
2421 #endif
2422 }
2423 
2428 {
2429  unsigned int width, height;
2430  getScreenSize(width, height);
2431  return width;
2432 }
2433 
2438 {
2439  unsigned int width, height;
2440  getScreenSize(width, height);
2441  return height;
2442 }
2443 
2444 #elif !defined(VISP_BUILD_SHARED_LIBS)
2445 // Work arround to avoid warning: libvisp_core.a(vpDisplayOpenCV.cpp.o) has no symbols
2446 void dummy_vpDisplayOpenCV() {};
2447 #endif
void getScreenSize(unsigned int &width, unsigned int &height)
unsigned int m_height
Definition: vpDisplay.h:196
void displayCircle(const vpImagePoint &center, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
vpDisplay * display
Definition: vpImage.h:135
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
unsigned int getScreenHeight()
double getTop() const
Definition: vpRect.h:178
int m_windowYPosition
display position
Definition: vpDisplay.h:194
double get_v() const
Definition: vpImagePoint.h:268
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:169
void clearDisplay(const vpColor &color=vpColor::white)
double get_i() const
Definition: vpImagePoint.h:199
unsigned int getWidth() const
Definition: vpImage.h:226
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:155
static const vpColor black
Definition: vpColor.h:157
static const vpColor darkRed
Definition: vpColor.h:164
#define vpERROR_TRACE
Definition: vpDebug.h:391
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:121
double get_u() const
Definition: vpImagePoint.h:257
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:153
error that can be emited by ViSP classes.
Definition: vpException.h:73
static const vpColor lightGray
Definition: vpColor.h:159
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:170
unsigned char G
Green component.
Definition: vpRGBa.h:154
double getRight() const
Definition: vpRect.h:165
bool m_displayHasBeenInitialized
display has been initialized
Definition: vpDisplay.h:190
static const vpColor green
Definition: vpColor.h:166
static int round(const double x)
Definition: vpMath.h:249
double get_j() const
Definition: vpImagePoint.h:210
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static const vpColor lightRed
Definition: vpColor.h:162
virtual ~vpDisplayOpenCV()
Definition: vpRGBa.h:66
void displayImage(const vpImage< unsigned char > &I)
static const vpColor red
Definition: vpColor.h:163
static const vpColor orange
Definition: vpColor.h:173
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)
double getBottom() const
Definition: vpRect.h:100
vpColorIdentifier id
Definition: vpColor.h:152
void set_i(const double ii)
Definition: vpImagePoint.h:163
int m_windowXPosition
display position
Definition: vpDisplay.h:192
static const vpColor cyan
Definition: vpColor.h:172
static const vpColor lightGreen
Definition: vpColor.h:165
unsigned int m_scale
Definition: vpDisplay.h:198
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:276
void set_u(const double u)
Definition: vpImagePoint.h:221
#define vpTRACE
Definition: vpDebug.h:414
static double sqr(double x)
Definition: vpMath.h:110
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)
void set_v(const double v)
Definition: vpImagePoint.h:232
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:199
std::string m_title
Definition: vpDisplay.h:197
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:1596
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static const vpColor gray
Definition: vpColor.h:160
static const vpColor darkGray
Definition: vpColor.h:161
void set_j(const double jj)
Definition: vpImagePoint.h:174
bool getPointerMotionEvent(vpImagePoint &ip)
Error that can be emited by the vpDisplay class and its derivates.
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
unsigned int m_width
Definition: vpDisplay.h:195
vpScaleType
Values that could be applied to a display to down scale the size of the display.
Definition: vpDisplay.h:173
unsigned int getScreenWidth()
unsigned char R
Red component.
Definition: vpRGBa.h:153
unsigned int getHeight() const
Definition: vpImage.h:175
Defines a rectangle in the plane.
Definition: vpRect.h:82
static const vpColor darkGreen
Definition: vpColor.h:167
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:171
static const vpColor lightBlue
Definition: vpColor.h:168
static const vpColor purple
Definition: vpColor.h:174
static const vpColor white
Definition: vpColor.h:158
double getLeft() const
Definition: vpRect.h:159
bool getKeyboardEvent(bool blocking=true)
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition: vpImagePoint.h:279
void setWindowPosition(int winx, int winy)
static const vpColor blue
Definition: vpColor.h:169