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 strcpy (this->title, title);
177 cvReleaseImage(&background);
199 "Image not initialized")) ;
225 "Image not initialized")) ;
255 int flags = CV_WINDOW_AUTOSIZE;
258 strcpy(this->title, title) ;
261 if (cvNamedWindow( this->title, flags ) < 0) {
264 "OpenCV was not built with a display device")) ;
274 cvSetMouseCallback( this->title,
on_mouse,
this );
322 cvInitFont( font, CV_FONT_HERSHEY_PLAIN, 0.70f,0.70f);
326 cvGetTextSize(
"A", font, &fontSize, &baseline );
327 fontHeight = fontSize.height + baseline;
363 static bool warn_displayed =
false;
364 if (! warn_displayed) {
366 warn_displayed =
true;
384 cvMoveWindow( this->
title, winx, winy );
390 "OpenCV not initialized")) ;
424 "OpenCV not initialized")) ;
454 CvSize size = cvSize((
int)this->width, (
int)this->height);
457 if (background != NULL){
458 if(background->nChannels != channels || background->depth != depth
459 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
460 if(background->nChannels != 0) cvReleaseImage(&background);
461 background = cvCreateImage( size, depth, channels );
464 else background = cvCreateImage( size, depth, channels );
469 unsigned char * input = (
unsigned char*)Ip->imageData;
470 unsigned char * output = (
unsigned char*)background->imageData;
472 unsigned int iwidth = Ic.getWidth();
474 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
482 *(output+3*j) = *(input+j*3);
483 *(output+3*j+1) = *(input+j*3+1);
484 *(output+3*j+2) = *(input+j*3+2);
487 input = input + 3*iwidth;
488 output = output + 3*this->
width;
498 "OpenCV not initialized")) ;
531 "OpenCV not initialized")) ;
559 CvSize size = cvSize((
int)this->width, (
int)this->height);
562 if (background != NULL){
563 if(background->nChannels != channels || background->depth != depth
564 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
565 if(background->nChannels != 0) cvReleaseImage(&background);
566 background = cvCreateImage( size, depth, channels );
569 else background = cvCreateImage( size, depth, channels );
574 unsigned char * input = (
unsigned char*)Ip->imageData;
575 unsigned char * output = (
unsigned char*)background->imageData;
577 unsigned int iwidth = Ic.
getWidth();
579 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
587 *(output+3*j) = *(input+j*3);
588 *(output+3*j+1) = *(input+j*3+1);
589 *(output+3*j+2) = *(input+j*3+2);
592 input = input + 3*iwidth;
593 output = output + 3*this->
width;
603 "OpenCV not initialized")) ;
629 delete [] col ; col = NULL ;
638 cvDestroyWindow( this->
title );
654 cvShowImage(this->
title, background );
661 "OpenCV not initialized")) ;
674 cvShowImage(this->
title, background );
681 "OpenCV not initialized")) ;
691 static bool warn_displayed =
false;
692 if (! warn_displayed) {
694 warn_displayed =
true;
708 unsigned int w,
unsigned int h,
709 unsigned int thickness)
719 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon())
720 &&(std::fabs(b)<= std::numeric_limits<double>::epsilon()))
756 "OpenCV not initialized")) ;
778 cvPutText( background, text,
781 font, col[color.
id] );
784 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
785 cvPutText( background, text,
795 "OpenCV not initialized")) ;
811 unsigned int thickness)
817 cvCircle( background,
820 (int)radius, col[color.
id], (
int)thickness);
823 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
824 cvCircle( background,
827 (int)radius, cvcolor, (
int)thickness);
832 cvCircle( background,
835 (int)radius, col[color.
id], CV_FILLED);
838 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
839 cvCircle( background,
842 (int)radius, cvcolor, CV_FILLED);
850 "OpenCV not initialized")) ;
865 unsigned int thickness)
893 "OpenCV not initialized")) ;
912 unsigned int thickness)
917 vpTRACE(
"Dot lines are not yet implemented");
924 col[color.
id], (int) thickness);
927 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
933 cvcolor, (int) thickness);
940 "OpenCV not initialized")) ;
955 unsigned int thickness)
965 col[color.
id], (int) thickness);
968 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
974 cvcolor, (int) thickness);
981 "OpenCV not initialized")) ;
1029 "OpenCV not initialized")) ;
1048 unsigned int width,
unsigned int height,
1049 const vpColor &color,
bool fill,
1050 unsigned int thickness)
1054 if (fill ==
false) {
1056 cvRectangle( background,
1061 col[color.
id], (int)thickness);
1064 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1065 cvRectangle( background,
1070 cvcolor, (int)thickness);
1075 cvRectangle( background,
1080 col[color.
id], CV_FILLED);
1083 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1084 cvRectangle( background,
1089 cvcolor, CV_FILLED);
1098 "OpenCV not initialized")) ;
1116 const vpColor &color,
bool fill,
1117 unsigned int thickness )
1121 if (fill ==
false) {
1123 cvRectangle( background,
1128 col[color.
id], (int)thickness);
1131 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1132 cvRectangle( background,
1137 cvcolor, (int)thickness);
1142 cvRectangle( background,
1147 col[color.
id], CV_FILLED);
1150 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1151 cvRectangle( background,
1156 cvcolor, CV_FILLED);
1165 "OpenCV not initialized")) ;
1183 const vpColor &color,
bool fill,
1184 unsigned int thickness)
1188 if (fill ==
false) {
1190 cvRectangle( background,
1195 col[color.
id], (int)thickness);
1198 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1199 cvRectangle( background,
1204 cvcolor, (int)thickness);
1210 cvRectangle( background,
1215 col[color.
id], CV_FILLED);
1218 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1219 cvRectangle( background,
1224 cvcolor, CV_FILLED);
1232 "OpenCV not initialized")) ;
1260 lbuttondown =
false;
1261 mbuttondown =
false;
1262 rbuttondown =
false;
1267 lbuttondown =
false;
1271 mbuttondown =
false;
1275 rbuttondown =
false;
1277 if (blocking) cvWaitKey(10);
1278 }
while ( ret ==
false && blocking ==
true);
1283 "OpenCV not initialized")) ;
1316 lbuttondown =
false;
1317 mbuttondown =
false;
1318 rbuttondown =
false;
1323 u = (
unsigned int)x_lbuttondown;
1324 v = (
unsigned int)y_lbuttondown;
1327 lbuttondown =
false;
1331 u = (
unsigned int)x_mbuttondown;
1332 v = (
unsigned int)y_mbuttondown;
1335 mbuttondown =
false;
1339 u = (
unsigned int)x_rbuttondown;
1340 v = (
unsigned int)y_rbuttondown;
1343 rbuttondown =
false;
1345 if (blocking) cvWaitKey(10);
1346 }
while ( ret ==
false && blocking ==
true);
1351 "OpenCV not initialized")) ;
1387 lbuttondown =
false;
1388 mbuttondown =
false;
1389 rbuttondown =
false;
1394 u = (
unsigned int)x_lbuttondown;
1395 v = (
unsigned int)y_lbuttondown;
1399 lbuttondown =
false;
1403 u = (
unsigned int)x_mbuttondown;
1404 v = (
unsigned int)y_mbuttondown;
1408 mbuttondown =
false;
1412 u = (
unsigned int)x_rbuttondown;
1413 v = (
unsigned int)y_rbuttondown;
1417 rbuttondown =
false;
1419 if (blocking) cvWaitKey(10);
1420 }
while ( ret ==
false && blocking ==
true);
1425 "OpenCV not initialized")) ;
1470 u = (
unsigned int)x_lbuttonup;
1471 v = (
unsigned int)y_lbuttonup;
1479 u = (
unsigned int)x_mbuttonup;
1480 v = (
unsigned int)y_mbuttonup;
1488 u = (
unsigned int)x_rbuttonup;
1489 v = (
unsigned int)y_rbuttonup;
1495 if (blocking) cvWaitKey(10);
1496 }
while ( ret ==
false && blocking ==
true);
1501 "OpenCV not initialized" ) ) ;
1521 case CV_EVENT_MOUSEMOVE:
1528 case CV_EVENT_LBUTTONDOWN:
1530 disp->lbuttondown =
true;
1531 disp->x_lbuttondown = x;
1532 disp->y_lbuttondown = y;
1535 case CV_EVENT_MBUTTONDOWN:
1537 disp->mbuttondown =
true;
1538 disp->x_mbuttondown = x;
1539 disp->y_mbuttondown = y;
1542 case CV_EVENT_RBUTTONDOWN:
1544 disp->rbuttondown =
true;
1545 disp->x_rbuttondown = x;
1546 disp->y_rbuttondown = y;
1549 case CV_EVENT_LBUTTONUP:
1551 disp->lbuttonup =
true;
1552 disp->x_lbuttonup = x;
1553 disp->y_lbuttonup = y;
1556 case CV_EVENT_MBUTTONUP:
1558 disp->mbuttonup =
true;
1559 disp->x_mbuttonup = x;
1560 disp->y_mbuttonup = y;
1563 case CV_EVENT_RBUTTONUP:
1565 disp->rbuttonup =
true;
1566 disp->x_rbuttonup = x;
1567 disp->y_rbuttonup = y;
1604 key_pressed = cvWaitKey(delay);
1605 if (key_pressed == -1)
1612 "OpenCV not initialized")) ;
1647 key_pressed = cvWaitKey(delay);
1648 if (key_pressed == -1)
1652 sprintf(
string,
"%c", key_pressed);
1659 "OpenCV not initialized")) ;
1686 u = (
unsigned int)x_move;
1687 v = (
unsigned int)y_move;
1697 "OpenCV not initialized")) ;
1721 u = (
unsigned int)x_move;
1722 v = (
unsigned int)y_move;
1731 "OpenCV not initialized")) ;
void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
void set_j(const double j)
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)
Class that defines generic functionnalities for display.
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.
void set_i(const double i)
static const vpColor lightGray
bool getPointerPosition(vpImagePoint &ip)
char * title
display title
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)
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
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