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();
515 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
523 *(output+3*j) = *(input+j*3);
524 *(output+3*j+1) = *(input+j*3+1);
525 *(output+3*j+2) = *(input+j*3+2);
528 input = input + 3*iwidth;
529 output = output + 3*this->
width;
539 "OpenCV not initialized")) ;
572 "OpenCV not initialized")) ;
600 CvSize size = cvSize((
int)this->width, (
int)this->height);
603 if (background != NULL){
604 if(background->nChannels != channels || background->depth != depth
605 || background->height != (
int) I.
getHeight() || background->width != (int) I.
getWidth()){
606 if(background->nChannels != 0) cvReleaseImage(&background);
607 background = cvCreateImage( size, depth, channels );
610 else background = cvCreateImage( size, depth, channels );
615 unsigned char * input = (
unsigned char*)Ip->imageData;
616 unsigned char * output = (
unsigned char*)background->imageData;
618 unsigned int iwidth = Ic.
getWidth();
620 output = output + (int)(iP.
get_i()*3*this->width+ iP.
get_j()*3);
628 *(output+3*j) = *(input+j*3);
629 *(output+3*j+1) = *(input+j*3+1);
630 *(output+3*j+2) = *(input+j*3+2);
633 input = input + 3*iwidth;
634 output = output + 3*this->
width;
644 "OpenCV not initialized")) ;
670 delete [] col ; col = NULL ;
680 cvDestroyWindow(
title );
703 cvShowImage(
title, background );
710 "OpenCV not initialized")) ;
723 cvShowImage(
title, background );
730 "OpenCV not initialized")) ;
740 static bool warn_displayed =
false;
741 if (! warn_displayed) {
743 warn_displayed =
true;
757 unsigned int w,
unsigned int h,
758 unsigned int thickness)
768 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon())
769 &&(std::fabs(b)<= std::numeric_limits<double>::epsilon()))
805 "OpenCV not initialized")) ;
827 cvPutText( background, text,
830 font, col[color.
id] );
833 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
834 cvPutText( background, text,
844 "OpenCV not initialized")) ;
860 unsigned int thickness)
866 cvCircle( background,
869 (int)radius, col[color.
id], (
int)thickness);
872 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
873 cvCircle( background,
876 (int)radius, cvcolor, (
int)thickness);
881 cvCircle( background,
884 (int)radius, col[color.
id], CV_FILLED);
887 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
888 cvCircle( background,
891 (int)radius, cvcolor, CV_FILLED);
899 "OpenCV not initialized")) ;
914 unsigned int thickness)
942 "OpenCV not initialized")) ;
961 unsigned int thickness)
966 vpTRACE(
"Dot lines are not yet implemented");
973 col[color.
id], (int) thickness);
976 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
982 cvcolor, (int) thickness);
989 "OpenCV not initialized")) ;
1004 unsigned int thickness)
1014 col[color.
id], (int) thickness);
1017 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1023 cvcolor, (int) thickness);
1030 "OpenCV not initialized")) ;
1078 "OpenCV not initialized")) ;
1097 unsigned int width,
unsigned int height,
1098 const vpColor &color,
bool fill,
1099 unsigned int thickness)
1103 if (fill ==
false) {
1105 cvRectangle( background,
1110 col[color.
id], (int)thickness);
1113 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1114 cvRectangle( background,
1119 cvcolor, (int)thickness);
1124 cvRectangle( background,
1129 col[color.
id], CV_FILLED);
1132 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1133 cvRectangle( background,
1138 cvcolor, CV_FILLED);
1147 "OpenCV not initialized")) ;
1165 const vpColor &color,
bool fill,
1166 unsigned int thickness )
1170 if (fill ==
false) {
1172 cvRectangle( background,
1177 col[color.
id], (int)thickness);
1180 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1181 cvRectangle( background,
1186 cvcolor, (int)thickness);
1191 cvRectangle( background,
1196 col[color.
id], CV_FILLED);
1199 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1200 cvRectangle( background,
1205 cvcolor, CV_FILLED);
1214 "OpenCV not initialized")) ;
1232 const vpColor &color,
bool fill,
1233 unsigned int thickness)
1237 if (fill ==
false) {
1239 cvRectangle( background,
1244 col[color.
id], (int)thickness);
1247 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1248 cvRectangle( background,
1253 cvcolor, (int)thickness);
1259 cvRectangle( background,
1264 col[color.
id], CV_FILLED);
1267 cvcolor = CV_RGB(color.
R, color.
G, color.
B) ;
1268 cvRectangle( background,
1273 cvcolor, CV_FILLED);
1281 "OpenCV not initialized")) ;
1309 lbuttondown =
false;
1310 mbuttondown =
false;
1311 rbuttondown =
false;
1316 lbuttondown =
false;
1320 mbuttondown =
false;
1324 rbuttondown =
false;
1326 if (blocking) cvWaitKey(10);
1327 }
while ( ret ==
false && blocking ==
true);
1332 "OpenCV not initialized")) ;
1365 lbuttondown =
false;
1366 mbuttondown =
false;
1367 rbuttondown =
false;
1372 u = (
unsigned int)x_lbuttondown;
1373 v = (
unsigned int)y_lbuttondown;
1376 lbuttondown =
false;
1380 u = (
unsigned int)x_mbuttondown;
1381 v = (
unsigned int)y_mbuttondown;
1384 mbuttondown =
false;
1388 u = (
unsigned int)x_rbuttondown;
1389 v = (
unsigned int)y_rbuttondown;
1392 rbuttondown =
false;
1394 if (blocking) cvWaitKey(10);
1395 }
while ( ret ==
false && blocking ==
true);
1400 "OpenCV not initialized")) ;
1436 lbuttondown =
false;
1437 mbuttondown =
false;
1438 rbuttondown =
false;
1443 u = (
unsigned int)x_lbuttondown;
1444 v = (
unsigned int)y_lbuttondown;
1448 lbuttondown =
false;
1452 u = (
unsigned int)x_mbuttondown;
1453 v = (
unsigned int)y_mbuttondown;
1457 mbuttondown =
false;
1461 u = (
unsigned int)x_rbuttondown;
1462 v = (
unsigned int)y_rbuttondown;
1466 rbuttondown =
false;
1468 if (blocking) cvWaitKey(10);
1469 }
while ( ret ==
false && blocking ==
true);
1474 "OpenCV not initialized")) ;
1519 u = (
unsigned int)x_lbuttonup;
1520 v = (
unsigned int)y_lbuttonup;
1528 u = (
unsigned int)x_mbuttonup;
1529 v = (
unsigned int)y_mbuttonup;
1537 u = (
unsigned int)x_rbuttonup;
1538 v = (
unsigned int)y_rbuttonup;
1544 if (blocking) cvWaitKey(10);
1545 }
while ( ret ==
false && blocking ==
true);
1550 "OpenCV not initialized" ) ) ;
1570 case CV_EVENT_MOUSEMOVE:
1577 case CV_EVENT_LBUTTONDOWN:
1579 disp->lbuttondown =
true;
1580 disp->x_lbuttondown = x;
1581 disp->y_lbuttondown = y;
1584 case CV_EVENT_MBUTTONDOWN:
1586 disp->mbuttondown =
true;
1587 disp->x_mbuttondown = x;
1588 disp->y_mbuttondown = y;
1591 case CV_EVENT_RBUTTONDOWN:
1593 disp->rbuttondown =
true;
1594 disp->x_rbuttondown = x;
1595 disp->y_rbuttondown = y;
1598 case CV_EVENT_LBUTTONUP:
1600 disp->lbuttonup =
true;
1601 disp->x_lbuttonup = x;
1602 disp->y_lbuttonup = y;
1605 case CV_EVENT_MBUTTONUP:
1607 disp->mbuttonup =
true;
1608 disp->x_mbuttonup = x;
1609 disp->y_mbuttonup = y;
1612 case CV_EVENT_RBUTTONUP:
1614 disp->rbuttonup =
true;
1615 disp->x_rbuttonup = x;
1616 disp->y_rbuttonup = y;
1653 key_pressed = cvWaitKey(delay);
1654 if (key_pressed == -1)
1661 "OpenCV not initialized")) ;
1696 key_pressed = cvWaitKey(delay);
1697 if (key_pressed == -1)
1701 sprintf(
string,
"%c", key_pressed);
1708 "OpenCV not initialized")) ;
1735 u = (
unsigned int)x_move;
1736 v = (
unsigned int)y_move;
1746 "OpenCV not initialized")) ;
1770 u = (
unsigned int)x_move;
1771 v = (
unsigned int)y_move;
1780 "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