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>
70 int vpDisplayOpenCV::count = 1;
91 init(I, x, y, title) ;
113 init(I, x, y, title) ;
145 init(0, 0, x, y, title) ;
169 windowXPosition = windowYPosition = -1 ;
190 cvReleaseImage(&background);
212 "Image not initialized")) ;
238 "Image not initialized")) ;
261 this->windowXPosition = x;
262 this->windowYPosition = y;
263 int flags = CV_WINDOW_AUTOSIZE;
266 if (this->title != NULL)
268 delete [] this->
title ;
271 this->title =
new char[strlen(title) + 1] ;
272 strcpy(this->title, title) ;
275 if (this->title != NULL)
277 delete [] this->
title ;
280 this->title =
new char[50] ;
281 sprintf(this->title,
"Unnamed ViSP display <%02d>",count) ;
285 window = cvNamedWindow( this->title, flags );
286 cvMoveWindow( this->title, x, y );
294 cvSetMouseCallback( this->title,
on_mouse,
this );
342 cvInitFont( font, CV_FONT_HERSHEY_PLAIN, 0.70f,0.70f);
346 cvGetTextSize(
"A", font, &fontSize, &baseline );
347 fontHeight = fontSize.height + baseline;
383 static bool warn_displayed =
false;
384 if (! warn_displayed) {
386 warn_displayed =
true;
391 if (this->
title != NULL) {
392 delete [] this->
title ;
396 this->
title =
new char[strlen(windowtitle) + 1] ;
397 strcpy(this->
title, windowtitle) ;
399 cvMoveWindow(windowtitle , windowXPosition, windowYPosition);
406 "OpenCV not initialized")) ;
423 this->windowXPosition = winx;
424 this->windowYPosition = winy;
425 cvMoveWindow( this->
title, winx, winy );
431 "OpenCV not initialized")) ;
465 "OpenCV not initialized")) ;
495 CvSize size = cvSize((
int)this->width, (
int)this->height);
498 if (background != NULL){
499 if(background->nChannels != channels || background->depth != depth
500 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
501 if(background->nChannels != 0) cvReleaseImage(&background);
502 background = cvCreateImage( size, depth, channels );
505 else background = cvCreateImage( size, depth, channels );
510 unsigned char * input = (
unsigned char*)Ip->imageData;
511 unsigned char * output = (
unsigned char*)background->imageData;
513 unsigned int iwidth = Ic.getWidth();
516 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
524 *(output+3*j) = *(input+j*3);
525 *(output+3*j+1) = *(input+j*3+1);
526 *(output+3*j+2) = *(input+j*3+2);
529 input = input + 3*iwidth;
530 output = output + 3*this->
width;
540 "OpenCV not initialized")) ;
573 "OpenCV not initialized")) ;
601 CvSize size = cvSize((
int)this->width, (
int)this->height);
604 if (background != NULL){
605 if(background->nChannels != channels || background->depth != depth
606 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
607 if(background->nChannels != 0) cvReleaseImage(&background);
608 background = cvCreateImage( size, depth, channels );
611 else background = cvCreateImage( size, depth, channels );
616 unsigned char * input = (
unsigned char*)Ip->imageData;
617 unsigned char * output = (
unsigned char*)background->imageData;
619 unsigned int iwidth = Ic.
getWidth();
622 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
630 *(output+3*j) = *(input+j*3);
631 *(output+3*j+1) = *(input+j*3+1);
632 *(output+3*j+2) = *(input+j*3+2);
635 input = input + 3*iwidth;
636 output = output + 3*this->
width;
646 "OpenCV not initialized")) ;
672 delete [] col ; col = NULL ;
682 cvDestroyWindow(
title );
705 cvShowImage(
title, background );
712 "OpenCV not initialized")) ;
725 cvShowImage(
title, background );
732 "OpenCV not initialized")) ;
742 static bool warn_displayed =
false;
743 if (! warn_displayed) {
745 warn_displayed =
true;
759 unsigned int w,
unsigned int h,
760 unsigned int thickness)
770 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon())
771 &&(std::fabs(b)<= std::numeric_limits<double>::epsilon()))
807 "OpenCV not initialized")) ;
829 cvPutText( background, text,
832 font, col[color.
id] );
835 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
836 cvPutText( background, text,
846 "OpenCV not initialized")) ;
862 unsigned int thickness)
868 cvCircle( background,
871 (int)radius, col[color.
id], (
int)thickness);
874 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
875 cvCircle( background,
878 (int)radius, cvcolor, (
int)thickness);
883 cvCircle( background,
886 (int)radius, col[color.
id], CV_FILLED);
889 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
890 cvCircle( background,
893 (int)radius, cvcolor, CV_FILLED);
901 "OpenCV not initialized")) ;
916 unsigned int thickness)
944 "OpenCV not initialized")) ;
963 unsigned int thickness)
968 vpTRACE(
"Dot lines are not yet implemented");
975 col[color.
id], (int) thickness);
978 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
984 cvcolor, (int) thickness);
991 "OpenCV not initialized")) ;
1006 unsigned int thickness)
1016 col[color.
id], (int) thickness);
1019 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1025 cvcolor, (int) thickness);
1032 "OpenCV not initialized")) ;
1080 "OpenCV not initialized")) ;
1099 unsigned int width,
unsigned int height,
1100 const vpColor &color,
bool fill,
1101 unsigned int thickness)
1105 if (fill ==
false) {
1107 cvRectangle( background,
1112 col[color.
id], (int)thickness);
1115 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1116 cvRectangle( background,
1121 cvcolor, (int)thickness);
1126 cvRectangle( background,
1131 col[color.
id], CV_FILLED);
1134 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1135 cvRectangle( background,
1140 cvcolor, CV_FILLED);
1149 "OpenCV not initialized")) ;
1167 const vpColor &color,
bool fill,
1168 unsigned int thickness )
1172 if (fill ==
false) {
1174 cvRectangle( background,
1179 col[color.
id], (int)thickness);
1182 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1183 cvRectangle( background,
1188 cvcolor, (int)thickness);
1193 cvRectangle( background,
1198 col[color.
id], CV_FILLED);
1201 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1202 cvRectangle( background,
1207 cvcolor, CV_FILLED);
1216 "OpenCV not initialized")) ;
1234 const vpColor &color,
bool fill,
1235 unsigned int thickness)
1239 if (fill ==
false) {
1241 cvRectangle( background,
1246 col[color.
id], (int)thickness);
1249 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1250 cvRectangle( background,
1255 cvcolor, (int)thickness);
1261 cvRectangle( background,
1266 col[color.
id], CV_FILLED);
1269 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1270 cvRectangle( background,
1275 cvcolor, CV_FILLED);
1283 "OpenCV not initialized")) ;
1311 lbuttondown =
false;
1312 mbuttondown =
false;
1313 rbuttondown =
false;
1318 lbuttondown =
false;
1322 mbuttondown =
false;
1326 rbuttondown =
false;
1328 if (blocking) cvWaitKey(10);
1329 }
while ( ret ==
false && blocking ==
true);
1334 "OpenCV not initialized")) ;
1367 lbuttondown =
false;
1368 mbuttondown =
false;
1369 rbuttondown =
false;
1374 u = (
unsigned int)x_lbuttondown;
1375 v = (
unsigned int)y_lbuttondown;
1378 lbuttondown =
false;
1382 u = (
unsigned int)x_mbuttondown;
1383 v = (
unsigned int)y_mbuttondown;
1386 mbuttondown =
false;
1390 u = (
unsigned int)x_rbuttondown;
1391 v = (
unsigned int)y_rbuttondown;
1394 rbuttondown =
false;
1396 if (blocking) cvWaitKey(10);
1397 }
while ( ret ==
false && blocking ==
true);
1402 "OpenCV not initialized")) ;
1438 lbuttondown =
false;
1439 mbuttondown =
false;
1440 rbuttondown =
false;
1445 u = (
unsigned int)x_lbuttondown;
1446 v = (
unsigned int)y_lbuttondown;
1450 lbuttondown =
false;
1454 u = (
unsigned int)x_mbuttondown;
1455 v = (
unsigned int)y_mbuttondown;
1459 mbuttondown =
false;
1463 u = (
unsigned int)x_rbuttondown;
1464 v = (
unsigned int)y_rbuttondown;
1468 rbuttondown =
false;
1470 if (blocking) cvWaitKey(10);
1471 }
while ( ret ==
false && blocking ==
true);
1476 "OpenCV not initialized")) ;
1521 u = (
unsigned int)x_lbuttonup;
1522 v = (
unsigned int)y_lbuttonup;
1530 u = (
unsigned int)x_mbuttonup;
1531 v = (
unsigned int)y_mbuttonup;
1539 u = (
unsigned int)x_rbuttonup;
1540 v = (
unsigned int)y_rbuttonup;
1546 if (blocking) cvWaitKey(10);
1547 }
while ( ret ==
false && blocking ==
true);
1552 "OpenCV not initialized" ) ) ;
1572 case CV_EVENT_MOUSEMOVE:
1579 case CV_EVENT_LBUTTONDOWN:
1581 disp->lbuttondown =
true;
1582 disp->x_lbuttondown = x;
1583 disp->y_lbuttondown = y;
1586 case CV_EVENT_MBUTTONDOWN:
1588 disp->mbuttondown =
true;
1589 disp->x_mbuttondown = x;
1590 disp->y_mbuttondown = y;
1593 case CV_EVENT_RBUTTONDOWN:
1595 disp->rbuttondown =
true;
1596 disp->x_rbuttondown = x;
1597 disp->y_rbuttondown = y;
1600 case CV_EVENT_LBUTTONUP:
1602 disp->lbuttonup =
true;
1603 disp->x_lbuttonup = x;
1604 disp->y_lbuttonup = y;
1607 case CV_EVENT_MBUTTONUP:
1609 disp->mbuttonup =
true;
1610 disp->x_mbuttonup = x;
1611 disp->y_mbuttonup = y;
1614 case CV_EVENT_RBUTTONUP:
1616 disp->rbuttonup =
true;
1617 disp->x_rbuttonup = x;
1618 disp->y_rbuttonup = y;
1655 key_pressed = cvWaitKey(delay);
1656 if (key_pressed == -1)
1663 "OpenCV not initialized")) ;
1698 key_pressed = cvWaitKey(delay);
1699 if (key_pressed == -1)
1703 sprintf(
string,
"%c", key_pressed);
1710 "OpenCV not initialized")) ;
1737 u = (
unsigned int)x_move;
1738 v = (
unsigned int)y_move;
1748 "OpenCV not initialized")) ;
1772 u = (
unsigned int)x_move;
1773 v = (
unsigned int)y_move;
1782 "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
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
static const vpColor purple
static const vpColor white
bool getKeyboardEvent(bool blocking=true)
void setWindowPosition(int winx, int winy)
static const vpColor blue