50 #include <visp/vpConfig.h>
52 #if ( defined(VISP_HAVE_OPENCV) )
61 #include <visp/vpDisplay.h>
62 #include <visp/vpDisplayOpenCV.h>
63 #include <visp/vpMath.h>
64 #include <visp/vpImageTools.h>
67 #include <visp/vpDebug.h>
68 #include <visp/vpDisplayException.h>
88 init(I, x, y, title) ;
108 init(I, x, y, title) ;
142 title_ = std::string(title);
144 title_ = std::string(
" ");
148 x_move = y_move = 0; move =
false;
149 x_lbuttondown = y_lbuttondown = 0; lbuttondown =
false;
150 x_mbuttondown = y_mbuttondown = 0; mbuttondown =
false;
151 x_rbuttondown = y_rbuttondown = 0; rbuttondown =
false;
152 x_lbuttonup = y_lbuttonup = 0; lbuttonup =
false;
153 x_mbuttonup = y_mbuttonup = 0; mbuttonup =
false;
154 x_rbuttonup = y_rbuttonup = 0; rbuttonup =
false;
183 x_move = y_move = 0; move =
false;
184 x_lbuttondown = y_lbuttondown = 0; lbuttondown =
false;
185 x_mbuttondown = y_mbuttondown = 0; mbuttondown =
false;
186 x_rbuttondown = y_rbuttondown = 0; rbuttondown =
false;
187 x_lbuttonup = y_lbuttonup = 0; lbuttonup =
false;
188 x_mbuttonup = y_mbuttonup = 0; mbuttonup =
false;
189 x_rbuttonup = y_rbuttonup = 0; rbuttonup =
false;
198 cvReleaseImage(&background);
220 "Image not initialized")) ;
246 "Image not initialized")) ;
276 int flags = CV_WINDOW_AUTOSIZE;
279 title_ = std::string(title);
281 title_ = std::string(
" ");
284 if (cvNamedWindow( this->
title_.c_str(), flags ) < 0) {
287 "OpenCV was not built with a display device")) ;
345 cvInitFont( font, CV_FONT_HERSHEY_PLAIN, 0.70f,0.70f);
349 cvGetTextSize(
"A", font, &fontSize, &baseline );
350 fontHeight = fontSize.height + baseline;
386 static bool warn_displayed =
false;
387 if (! warn_displayed) {
389 warn_displayed =
true;
407 cvMoveWindow( this->
title_.c_str(), winx, winy );
413 "OpenCV not initialized")) ;
447 "OpenCV not initialized")) ;
467 const unsigned int w,
const unsigned int h )
476 CvSize size = cvSize((
int)this->
width, (
int)this->
height);
479 if (background != NULL){
480 if(background->nChannels != channels || background->depth != depth
481 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
482 if(background->nChannels != 0) cvReleaseImage(&background);
483 background = cvCreateImage( size, depth, channels );
486 else background = cvCreateImage( size, depth, channels );
491 unsigned char * input = (
unsigned char*)Ip->imageData;
492 unsigned char * output = (
unsigned char*)background->imageData;
494 unsigned int iwidth = Ic.getWidth();
496 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
504 *(output+3*j) = *(input+j*3);
505 *(output+3*j+1) = *(input+j*3+1);
506 *(output+3*j+2) = *(input+j*3+2);
509 input = input + 3*iwidth;
510 output = output + 3*this->
width;
520 "OpenCV not initialized")) ;
553 "OpenCV not initialized")) ;
573 const unsigned int w,
const unsigned int h )
580 CvSize size = cvSize((
int)this->
width, (
int)this->
height);
583 if (background != NULL){
584 if(background->nChannels != channels || background->depth != depth
585 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
586 if(background->nChannels != 0) cvReleaseImage(&background);
587 background = cvCreateImage( size, depth, channels );
590 else background = cvCreateImage( size, depth, channels );
595 unsigned char * input = (
unsigned char*)Ip->imageData;
596 unsigned char * output = (
unsigned char*)background->imageData;
598 unsigned int iwidth = Ic.
getWidth();
600 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
608 *(output+3*j) = *(input+j*3);
609 *(output+3*j+1) = *(input+j*3+1);
610 *(output+3*j+2) = *(input+j*3+2);
613 input = input + 3*iwidth;
614 output = output + 3*this->
width;
624 "OpenCV not initialized")) ;
650 delete [] col ; col = NULL ;
659 cvDestroyWindow( this->
title_.c_str() );
675 cvShowImage(this->
title_.c_str(), background );
682 "OpenCV not initialized")) ;
695 cvShowImage(this->
title_.c_str(), background );
702 "OpenCV not initialized")) ;
712 static bool warn_displayed =
false;
713 if (! warn_displayed) {
715 warn_displayed =
true;
729 unsigned int w,
unsigned int h,
730 unsigned int thickness)
740 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon())
741 &&(std::fabs(b)<= std::numeric_limits<double>::epsilon()))
777 "OpenCV not initialized")) ;
799 cvPutText( background, text,
802 font, col[color.
id] );
805 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
806 cvPutText( background, text,
816 "OpenCV not initialized")) ;
832 unsigned int thickness)
838 cvCircle( background,
841 (int)radius, col[color.
id], (
int)thickness);
844 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
845 cvCircle( background,
848 (int)radius, cvcolor, (
int)thickness);
853 cvCircle( background,
856 (int)radius, col[color.
id], CV_FILLED);
859 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
860 cvCircle( background,
863 (int)radius, cvcolor, CV_FILLED);
871 "OpenCV not initialized")) ;
886 unsigned int thickness)
914 "OpenCV not initialized")) ;
933 unsigned int thickness)
938 vpTRACE(
"Dot lines are not yet implemented");
945 col[color.
id], (int) thickness);
948 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
954 cvcolor, (int) thickness);
961 "OpenCV not initialized")) ;
976 unsigned int thickness)
986 col[color.
id], (int) thickness);
989 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
995 cvcolor, (int) thickness);
1002 "OpenCV not initialized")) ;
1050 "OpenCV not initialized")) ;
1069 unsigned int w,
unsigned int h,
1070 const vpColor &color,
bool fill,
1071 unsigned int thickness)
1075 if (fill ==
false) {
1077 cvRectangle( background,
1082 col[color.
id], (int)thickness);
1085 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1086 cvRectangle( background,
1091 cvcolor, (int)thickness);
1096 cvRectangle( background,
1101 col[color.
id], CV_FILLED);
1104 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1105 cvRectangle( background,
1110 cvcolor, CV_FILLED);
1118 "OpenCV not initialized")) ;
1136 const vpColor &color,
bool fill,
1137 unsigned int thickness )
1141 if (fill ==
false) {
1143 cvRectangle( background,
1148 col[color.
id], (int)thickness);
1151 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1152 cvRectangle( background,
1157 cvcolor, (int)thickness);
1162 cvRectangle( background,
1167 col[color.
id], CV_FILLED);
1170 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1171 cvRectangle( background,
1176 cvcolor, CV_FILLED);
1185 "OpenCV not initialized")) ;
1203 const vpColor &color,
bool fill,
1204 unsigned int thickness)
1208 if (fill ==
false) {
1210 cvRectangle( background,
1215 col[color.
id], (int)thickness);
1218 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1219 cvRectangle( background,
1224 cvcolor, (int)thickness);
1230 cvRectangle( background,
1235 col[color.
id], CV_FILLED);
1238 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1239 cvRectangle( background,
1244 cvcolor, CV_FILLED);
1252 "OpenCV not initialized")) ;
1280 lbuttondown =
false;
1281 mbuttondown =
false;
1282 rbuttondown =
false;
1287 lbuttondown =
false;
1291 mbuttondown =
false;
1295 rbuttondown =
false;
1297 if (blocking) cvWaitKey(10);
1298 }
while ( ret ==
false && blocking ==
true);
1303 "OpenCV not initialized")) ;
1336 lbuttondown =
false;
1337 mbuttondown =
false;
1338 rbuttondown =
false;
1343 u = (
unsigned int)x_lbuttondown;
1344 v = (
unsigned int)y_lbuttondown;
1347 lbuttondown =
false;
1351 u = (
unsigned int)x_mbuttondown;
1352 v = (
unsigned int)y_mbuttondown;
1355 mbuttondown =
false;
1359 u = (
unsigned int)x_rbuttondown;
1360 v = (
unsigned int)y_rbuttondown;
1363 rbuttondown =
false;
1365 if (blocking) cvWaitKey(10);
1366 }
while ( ret ==
false && blocking ==
true);
1371 "OpenCV not initialized")) ;
1407 lbuttondown =
false;
1408 mbuttondown =
false;
1409 rbuttondown =
false;
1414 u = (
unsigned int)x_lbuttondown;
1415 v = (
unsigned int)y_lbuttondown;
1419 lbuttondown =
false;
1423 u = (
unsigned int)x_mbuttondown;
1424 v = (
unsigned int)y_mbuttondown;
1428 mbuttondown =
false;
1432 u = (
unsigned int)x_rbuttondown;
1433 v = (
unsigned int)y_rbuttondown;
1437 rbuttondown =
false;
1439 if (blocking) cvWaitKey(10);
1440 }
while ( ret ==
false && blocking ==
true);
1445 "OpenCV not initialized")) ;
1490 u = (
unsigned int)x_lbuttonup;
1491 v = (
unsigned int)y_lbuttonup;
1499 u = (
unsigned int)x_mbuttonup;
1500 v = (
unsigned int)y_mbuttonup;
1508 u = (
unsigned int)x_rbuttonup;
1509 v = (
unsigned int)y_rbuttonup;
1515 if (blocking) cvWaitKey(10);
1516 }
while ( ret ==
false && blocking ==
true);
1521 "OpenCV not initialized" ) ) ;
1541 case CV_EVENT_MOUSEMOVE:
1548 case CV_EVENT_LBUTTONDOWN:
1550 disp->lbuttondown =
true;
1551 disp->x_lbuttondown = x;
1552 disp->y_lbuttondown = y;
1555 case CV_EVENT_MBUTTONDOWN:
1557 disp->mbuttondown =
true;
1558 disp->x_mbuttondown = x;
1559 disp->y_mbuttondown = y;
1562 case CV_EVENT_RBUTTONDOWN:
1564 disp->rbuttondown =
true;
1565 disp->x_rbuttondown = x;
1566 disp->y_rbuttondown = y;
1569 case CV_EVENT_LBUTTONUP:
1571 disp->lbuttonup =
true;
1572 disp->x_lbuttonup = x;
1573 disp->y_lbuttonup = y;
1576 case CV_EVENT_MBUTTONUP:
1578 disp->mbuttonup =
true;
1579 disp->x_mbuttonup = x;
1580 disp->y_mbuttonup = y;
1583 case CV_EVENT_RBUTTONUP:
1585 disp->rbuttonup =
true;
1586 disp->x_rbuttonup = x;
1587 disp->y_rbuttonup = y;
1624 key_pressed = cvWaitKey(delay);
1625 if (key_pressed == -1)
1632 "OpenCV not initialized")) ;
1667 key_pressed = cvWaitKey(delay);
1668 if (key_pressed == -1)
1672 sprintf(
string,
"%c", key_pressed);
1679 "OpenCV not initialized")) ;
1706 u = (
unsigned int)x_move;
1707 v = (
unsigned int)y_move;
1717 "OpenCV not initialized")) ;
1741 u = (
unsigned int)x_move;
1742 v = (
unsigned int)y_move;
1751 "OpenCV not initialized")) ;
void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void clearDisplay(const vpColor &color=vpColor::white)
unsigned int getWidth() const
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
void displayPoint(const vpImagePoint &ip, const vpColor &color)
unsigned char B
Blue component.
static const vpColor black
static const vpColor darkRed
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.
static const vpColor lightGray
bool getPointerPosition(vpImagePoint &ip)
static const vpColor darkBlue
bool displayHasBeenInitialized
display has been initialized
unsigned char G
Green component.
static const vpColor green
static int round(const double x)
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static const vpColor lightRed
virtual ~vpDisplayOpenCV()
static const vpColor orange
static void on_mouse(int event, int x, int y, int flags, void *param)
void set_i(const double ii)
static const vpColor cyan
static const vpColor lightGreen
void flushDisplayROI(const vpImagePoint &iP, const unsigned int width, const unsigned int height)
void set_u(const double u)
static double sqr(double x)
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
The vpDisplayOpenCV allows to display image using the opencv library.
void set_v(const double v)
void displayImage(const vpImage< vpRGBa > &I)
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 displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, const unsigned int width, const unsigned int height)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static const vpColor gray
static const vpColor darkGray
void set_j(const double jj)
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
int windowXPosition
display position
unsigned char R
Red component.
void setFont(const char *font)
unsigned int getHeight() const
Defines a rectangle in the plane.
static const vpColor darkGreen
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void setTitle(const char *title)
static const vpColor yellow
static const vpColor lightBlue
int windowYPosition
display position
static const vpColor purple
static const vpColor white
bool getKeyboardEvent(bool blocking=true)
void setWindowPosition(int winx, int winy)
static const vpColor blue