46 #include <visp3/core/vpConfig.h> 48 #if defined(VISP_HAVE_OPENCV) 57 #include <visp3/core/vpDisplay.h> 58 #include <visp3/core/vpImageTools.h> 59 #include <visp3/core/vpIoTools.h> 60 #include <visp3/core/vpMath.h> 61 #include <visp3/gui/vpDisplayOpenCV.h> 64 #include <visp3/core/vpDebug.h> 65 #include <visp3/core/vpDisplayException.h> 67 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408) 69 #include <opencv2/core/core_c.h> 70 #include <opencv2/imgproc/imgproc.hpp> 73 #define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0) 78 #include <visp3/gui/vpDisplayX.h> 83 std::vector<std::string> vpDisplayOpenCV::m_listTitles = std::vector<std::string>();
84 unsigned int vpDisplayOpenCV::m_nbWindows = 0;
109 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
110 m_background(NULL), col(NULL), cvcolor(), font(NULL),
112 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
114 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
115 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
116 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
117 y_rbuttonup(0), rbuttonup(false)
149 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
150 m_background(NULL), col(NULL), cvcolor(), font(NULL),
152 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
154 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
155 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
156 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
157 y_rbuttonup(0), rbuttonup(false)
160 init(I, x, y, title);
183 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
184 m_background(NULL), col(NULL), cvcolor(), font(NULL),
186 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
188 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
189 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
190 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
191 y_rbuttonup(0), rbuttonup(false)
219 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
220 m_background(NULL), col(NULL), cvcolor(), font(NULL),
222 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
224 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
225 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
226 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
227 y_rbuttonup(0), rbuttonup(false)
230 init(I, x, y, title);
257 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
258 m_background(NULL), col(NULL), cvcolor(), font(NULL),
260 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
262 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
263 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
264 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
265 y_rbuttonup(0), rbuttonup(false)
270 if (!title.empty()) {
273 std::ostringstream s;
275 m_title = std::string(
"Window ") + s.str();
281 for (
size_t i = 0; i < m_listTitles.size(); i++) {
282 if (m_listTitles[i] ==
m_title) {
283 std::ostringstream s;
285 m_title = std::string(
"Window ") + s.str();
292 m_listTitles.push_back(
m_title);
316 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
317 m_background(NULL), col(NULL), cvcolor(), font(NULL),
319 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
321 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
322 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
323 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
324 y_rbuttonup(0), rbuttonup(false)
334 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 335 cvReleaseImage(&m_background);
400 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 401 int flags = CV_WINDOW_AUTOSIZE;
403 int flags = cv::WINDOW_AUTOSIZE;
407 if (!title.empty()) {
411 std::ostringstream s;
413 m_title = std::string(
"Window ") + s.str();
419 for (
size_t i = 0; i < m_listTitles.size(); i++) {
420 if (m_listTitles[i] ==
m_title) {
421 std::ostringstream s;
423 m_title = std::string(
"Window ") + s.str();
430 m_listTitles.push_back(
m_title);
434 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 435 if (cvNamedWindow(this->
m_title.c_str(), flags) < 0) {
439 cv::namedWindow(this->
m_title, flags);
441 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 453 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 500 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 502 cvInitFont(font, CV_FONT_HERSHEY_PLAIN, 0.70f, 0.70f);
505 cvGetTextSize(
"A", font, &fontSize, &baseline);
510 fontSize = cv::getTextSize(
"A", font, fontScale, thickness, &baseline);
513 fontHeight = fontSize.height + baseline;
564 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 565 cvMoveWindow(this->
m_title.c_str(), winx, winy);
567 cv::moveWindow(this->
m_title.c_str(), winx, winy);
587 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 591 if (m_background != NULL) {
592 if (m_background->nChannels != channels || m_background->depth != depth ||
593 m_background->height != (
int)m_height || m_background->width != (
int)m_width) {
594 if (m_background->nChannels != 0)
595 cvReleaseImage(&m_background);
596 m_background = cvCreateImage(size, depth, channels);
599 m_background = cvCreateImage(size, depth, channels);
603 for (
unsigned int i = 0; i <
m_height; i++) {
604 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
605 for (
unsigned int j = 0; j <
m_width; j++) {
606 unsigned char val = I[i][j];
613 for (
unsigned int i = 0; i <
m_height; i++) {
614 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
615 for (
unsigned int j = 0; j <
m_width; j++) {
627 cv::Size size((
int)m_width, (
int)m_height);
628 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
629 m_background.cols != (
int)
m_width) {
630 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
634 for (
unsigned int i = 0; i <
m_height; i++) {
635 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
636 for (
unsigned int j = 0; j <
m_width; j++) {
637 unsigned char val = I[i][j];
644 for (
unsigned int i = 0; i <
m_height; i++) {
645 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
646 for (
unsigned int j = 0; j <
m_width; j++) {
680 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 684 if (m_background != NULL) {
685 if (m_background->nChannels != channels || m_background->depth != depth ||
686 m_background->height != (
int)m_height || m_background->width != (
int)m_width) {
687 if (m_background->nChannels != 0)
688 cvReleaseImage(&m_background);
689 m_background = cvCreateImage(size, depth, channels);
692 m_background = cvCreateImage(size, depth, channels);
696 unsigned int i_min = (
unsigned int)iP.
get_i();
697 unsigned int j_min = (
unsigned int)iP.
get_j();
698 unsigned int i_max = (std::min)(i_min + h, m_height);
699 unsigned int j_max = (std::min)(j_min + w, m_width);
700 for (
unsigned int i = i_min; i < i_max; i++) {
701 unsigned char *dst_24 =
702 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
703 for (
unsigned int j = j_min; j < j_max; j++) {
704 unsigned char val = I[i][j];
711 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
712 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
713 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) /
m_scale), (int)m_height);
714 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) /
m_scale), (int)m_width);
715 for (
int i = i_min; i < i_max; i++) {
716 unsigned char *dst_24 =
717 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
718 for (
int j = j_min; j < j_max; j++) {
730 cv::Size size((
int)m_width, (
int)m_height);
731 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
732 m_background.cols != (
int)
m_width) {
733 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
737 unsigned int i_min = (
unsigned int)iP.
get_i();
738 unsigned int j_min = (
unsigned int)iP.
get_j();
739 unsigned int i_max = (std::min)(i_min + h, m_height);
740 unsigned int j_max = (std::min)(j_min + w, m_width);
741 for (
unsigned int i = i_min; i < i_max; i++) {
742 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 * m_width + j_min * 3);
743 for (
unsigned int j = j_min; j < j_max; j++) {
744 unsigned char val = I[i][j];
751 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
752 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
753 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) /
m_scale), (int)m_height);
754 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) /
m_scale), (int)m_width);
755 for (
int i = i_min; i < i_max; i++) {
756 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 * m_width + j_min * 3);
757 for (
int j = j_min; j < j_max; j++) {
786 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 790 if (m_background != NULL) {
791 if (m_background->nChannels != channels || m_background->depth != depth ||
792 m_background->height != (
int)m_height || m_background->width != (
int)m_width) {
793 if (m_background->nChannels != 0)
794 cvReleaseImage(&m_background);
795 m_background = cvCreateImage(size, depth, channels);
798 m_background = cvCreateImage(size, depth, channels);
802 for (
unsigned int i = 0; i <
m_height; i++) {
803 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
804 for (
unsigned int j = 0; j <
m_width; j++) {
812 for (
unsigned int i = 0; i <
m_height; i++) {
813 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
814 for (
unsigned int j = 0; j <
m_width; j++) {
825 cv::Size size((
int)this->m_width, (
int)this->m_height);
826 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
827 m_background.cols != (
int)
m_width) {
828 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
832 for (
unsigned int i = 0; i <
m_height; i++) {
833 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
834 for (
unsigned int j = 0; j <
m_width; j++) {
842 for (
unsigned int i = 0; i <
m_height; i++) {
843 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
844 for (
unsigned int j = 0; j <
m_width; j++) {
877 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 881 if (m_background != NULL) {
882 if (m_background->nChannels != channels || m_background->depth != depth ||
883 m_background->height != (
int)m_height || m_background->width != (
int)m_width) {
884 if (m_background->nChannels != 0)
885 cvReleaseImage(&m_background);
886 m_background = cvCreateImage(size, depth, channels);
889 m_background = cvCreateImage(size, depth, channels);
893 unsigned int i_min = (
unsigned int)iP.
get_i();
894 unsigned int j_min = (
unsigned int)iP.
get_j();
895 unsigned int i_max = (std::min)(i_min + h, m_height);
896 unsigned int j_max = (std::min)(j_min + w, m_width);
897 for (
unsigned int i = i_min; i < i_max; i++) {
898 unsigned char *dst_24 =
899 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
900 for (
unsigned int j = j_min; j < j_max; j++) {
908 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
909 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
910 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) /
m_scale), (int)m_height);
911 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) /
m_scale), (int)m_width);
912 for (
int i = i_min; i < i_max; i++) {
913 unsigned char *dst_24 =
914 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
915 for (
int j = j_min; j < j_max; j++) {
926 cv::Size size((
int)this->m_width, (
int)this->m_height);
927 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (int)m_height ||
928 m_background.cols != (
int)
m_width) {
929 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
933 unsigned int i_min = (
unsigned int)iP.
get_i();
934 unsigned int j_min = (
unsigned int)iP.
get_j();
935 unsigned int i_max = (std::min)(i_min + h, m_height);
936 unsigned int j_max = (std::min)(j_min + w, m_width);
937 for (
unsigned int i = i_min; i < i_max; i++) {
938 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 * m_width + j_min * 3);
939 for (
unsigned int j = j_min; j < j_max; j++) {
947 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
948 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
949 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) /
m_scale), (int)m_height);
950 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) /
m_scale), (int)m_width);
951 for (
int i = i_min; i < i_max; i++) {
952 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 * m_width + j_min * 3);
953 for (
int j = j_min; j < j_max; j++) {
987 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 994 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 995 cvDestroyWindow(this->
m_title.c_str());
997 cv::destroyWindow(this->
m_title);
1000 for (
size_t i = 0; i < m_listTitles.size(); i++) {
1001 if (
m_title == m_listTitles[i]) {
1002 m_listTitles.erase(m_listTitles.begin() + (
long int)i);
1021 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1022 cvShowImage(this->
m_title.c_str(), m_background);
1025 cv::imshow(this->
m_title, m_background);
1039 const unsigned int )
1042 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1043 cvShowImage(this->
m_title.c_str(), m_background);
1046 cv::imshow(this->
m_title.c_str(), m_background);
1059 static bool warn_displayed =
false;
1060 if (!warn_displayed) {
1062 warn_displayed =
true;
1074 unsigned int w,
unsigned int h,
unsigned int thickness)
1082 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
1083 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
1128 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1129 cvPutText(m_background, text,
1133 cv::putText(m_background, text,
1135 font, fontScale, col[color.
id]);
1138 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1139 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1140 cvPutText(m_background, text,
1144 cv::putText(m_background, text,
1146 font, fontScale, cvcolor);
1166 unsigned int thickness)
1171 int r =
static_cast<int>(radius /
m_scale);
1172 cv::Scalar cv_color;
1174 cv_color = col[color.
id];
1177 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1180 if (fill ==
false) {
1181 int cv_thickness =
static_cast<int>(thickness);
1182 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1198 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 1199 int filled = cv::FILLED;
1201 int filled = CV_FILLED;
1203 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 1204 double opacity =
static_cast<double>(color.
A) / 255.0;
1205 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1207 [x, y, r, cv_color, filled](cv::Mat image) {
1218 [x, y, r, cv_color, filled](cv::Mat image) {
1229 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1259 unsigned int thickness)
1286 unsigned int thickness)
1294 bool vertical_line = (int)ip2_.
get_j() == (int)ip1_.
get_j();
1295 if (vertical_line) {
1297 std::swap(ip1_, ip2_);
1300 std::swap(ip1_, ip2_);
1303 double diff_j = vertical_line ? 1 : ip2_.
get_j() - ip1_.
get_j();
1304 double deltaj = size / length * diff_j;
1305 double deltai = size / length * (ip2_.
get_i() - ip1_.
get_i());
1306 double slope = (ip2_.
get_i() - ip1_.
get_i()) / diff_j;
1307 double orig = ip1_.
get_i() - slope * ip1_.
get_j();
1309 if (vertical_line) {
1310 for (
unsigned int i = (
unsigned int)ip1_.
get_i(); i < ip2_.
get_i(); i += (
unsigned int)(2 * deltai)) {
1311 double j = ip1_.
get_j();
1315 for (
unsigned int j = (
unsigned int)ip1_.
get_j(); j < ip2_.
get_j(); j += (
unsigned int)(2 * deltaj)) {
1316 double i = slope * j + orig;
1332 unsigned int thickness)
1336 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1346 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1347 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1371 for (
unsigned int i = 0; i < thickness; i++) {
1373 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1376 col[color.
id], (int)thickness);
1380 col[color.
id], (int)thickness);
1383 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1384 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1387 cvcolor, (int)thickness);
1391 cvcolor, (int)thickness);
1416 const vpColor &color,
bool fill,
unsigned int thickness)
1423 cv::Scalar cv_color;
1425 cv_color = col[color.
id];
1428 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1431 if (fill ==
false) {
1432 int cv_thickness =
static_cast<int>(thickness);
1433 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1437 cvPoint(right, bottom),
1443 cv::Point(left, top),
1444 cv::Point(right, bottom),
1449 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 1450 int filled = cv::FILLED;
1452 int filled = CV_FILLED;
1454 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 1455 double opacity =
static_cast<double>(color.
A) / 255.0;
1456 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1458 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1462 cvPoint(right, bottom),
1469 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1472 cv::Point(left, top),
1473 cv::Point(right, bottom),
1480 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1481 cvRectangle(m_background,
1483 cvPoint(right, bottom),
1487 cv::rectangle(m_background,
1488 cv::Point(left, top),
1489 cv::Point(right, bottom),
1514 const vpColor &color,
bool fill,
unsigned int thickness)
1521 cv::Scalar cv_color;
1523 cv_color = col[color.
id];
1526 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1529 if (fill ==
false) {
1530 int cv_thickness =
static_cast<int>(thickness);
1531 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1535 cvPoint(right, bottom),
1541 cv::Point(left, top),
1542 cv::Point(right, bottom),
1547 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 1548 int filled = cv::FILLED;
1550 int filled = CV_FILLED;
1552 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 1553 double opacity =
static_cast<double>(color.
A) / 255.0;
1554 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1556 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1560 cvPoint(right, bottom),
1567 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1570 cv::Point(left, top),
1571 cv::Point(right, bottom),
1578 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1579 cvRectangle(m_background,
1581 cvPoint(right, bottom),
1585 cv::rectangle(m_background,
1586 cv::Point(left, top),
1587 cv::Point(right, bottom),
1618 cv::Scalar cv_color;
1620 cv_color = col[color.
id];
1623 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1626 if (fill ==
false) {
1627 int cv_thickness =
static_cast<int>(thickness);
1628 #if VISP_HAVE_OPENCV_VERSION < 0x020408 1632 cvPoint(right, bottom),
1638 cv::Point(left, top),
1639 cv::Point(right, bottom),
1644 #if VISP_HAVE_OPENCV_VERSION >= 0x030000 1645 int filled = cv::FILLED;
1647 int filled = CV_FILLED;
1649 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 1650 double opacity =
static_cast<double>(color.
A) / 255.0;
1651 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1653 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1657 cvPoint(right, bottom),
1664 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1667 cv::Point(left, top),
1668 cv::Point(right, bottom),
1675 # if VISP_HAVE_OPENCV_VERSION < 0x020408 1676 cvRectangle(m_background,
1678 cvPoint(right, bottom),
1682 cv::rectangle(m_background,
1683 cv::Point(left, top),
1684 cv::Point(right, bottom),
1716 lbuttondown =
false;
1717 mbuttondown =
false;
1718 rbuttondown =
false;
1723 lbuttondown =
false;
1727 mbuttondown =
false;
1731 rbuttondown =
false;
1734 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1739 }
while (ret ==
false && blocking ==
true);
1771 lbuttondown =
false;
1772 mbuttondown =
false;
1773 rbuttondown =
false;
1778 u = (
unsigned int)x_lbuttondown *
m_scale;
1779 v = (
unsigned int)y_lbuttondown *
m_scale;
1782 lbuttondown =
false;
1786 u = (
unsigned int)x_mbuttondown *
m_scale;
1787 v = (
unsigned int)y_mbuttondown *
m_scale;
1790 mbuttondown =
false;
1794 u = (
unsigned int)x_rbuttondown *
m_scale;
1795 v = (
unsigned int)y_rbuttondown *
m_scale;
1798 rbuttondown =
false;
1801 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1806 }
while (ret ==
false && blocking ==
true);
1839 lbuttondown =
false;
1840 mbuttondown =
false;
1841 rbuttondown =
false;
1846 u = (
unsigned int)x_lbuttondown *
m_scale;
1847 v = (
unsigned int)y_lbuttondown *
m_scale;
1851 lbuttondown =
false;
1855 u = (
unsigned int)x_mbuttondown *
m_scale;
1856 v = (
unsigned int)y_mbuttondown *
m_scale;
1860 mbuttondown =
false;
1864 u = (
unsigned int)x_rbuttondown *
m_scale;
1865 v = (
unsigned int)y_rbuttondown *
m_scale;
1869 rbuttondown =
false;
1872 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1877 }
while (ret ==
false && blocking ==
true);
1919 u = (
unsigned int)x_lbuttonup *
m_scale;
1920 v = (
unsigned int)y_lbuttonup *
m_scale;
1928 u = (
unsigned int)x_mbuttonup *
m_scale;
1929 v = (
unsigned int)y_mbuttonup *
m_scale;
1937 u = (
unsigned int)x_rbuttonup *
m_scale;
1938 v = (
unsigned int)y_rbuttonup *
m_scale;
1945 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1950 }
while (ret ==
false && blocking ==
true);
1971 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1972 case CV_EVENT_MOUSEMOVE:
1974 case cv::EVENT_MOUSEMOVE:
1982 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1983 case CV_EVENT_LBUTTONDOWN:
1985 case cv::EVENT_LBUTTONDOWN:
1988 disp->lbuttondown =
true;
1989 disp->x_lbuttondown = x;
1990 disp->y_lbuttondown = y;
1993 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 1994 case CV_EVENT_MBUTTONDOWN:
1996 case cv::EVENT_MBUTTONDOWN:
1999 disp->mbuttondown =
true;
2000 disp->x_mbuttondown = x;
2001 disp->y_mbuttondown = y;
2004 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 2005 case CV_EVENT_RBUTTONDOWN:
2007 case cv::EVENT_RBUTTONDOWN:
2010 disp->rbuttondown =
true;
2011 disp->x_rbuttondown = x;
2012 disp->y_rbuttondown = y;
2015 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 2016 case CV_EVENT_LBUTTONUP:
2018 case cv::EVENT_LBUTTONUP:
2021 disp->lbuttonup =
true;
2022 disp->x_lbuttonup = x;
2023 disp->y_lbuttonup = y;
2026 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 2027 case CV_EVENT_MBUTTONUP:
2029 case cv::EVENT_MBUTTONUP:
2032 disp->mbuttonup =
true;
2033 disp->x_mbuttonup = x;
2034 disp->y_mbuttonup = y;
2037 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 2038 case CV_EVENT_RBUTTONUP:
2040 case cv::EVENT_RBUTTONUP:
2043 disp->rbuttonup =
true;
2044 disp->x_rbuttonup = x;
2045 disp->y_rbuttonup = y;
2079 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 2080 int key_pressed = cvWaitKey(delay);
2082 int key_pressed = cv::waitKey(delay);
2085 if (key_pressed == -1)
2121 #if (VISP_HAVE_OPENCV_VERSION < 0x020408) 2122 int key_pressed = cvWaitKey(delay);
2124 int key_pressed = cv::waitKey(delay);
2126 if (key_pressed == -1)
2130 std::stringstream ss;
2159 double u = (
unsigned int)x_move /
m_scale;
2160 double v = (
unsigned int)y_move /
m_scale;
2189 u = (
unsigned int)x_move /
m_scale;
2190 v = (
unsigned int)y_move /
m_scale;
2208 #if defined(VISP_HAVE_X11) 2211 #elif defined(VISP_HAVE_XRANDR) 2212 std::string command =
"xrandr | grep '*'";
2213 FILE *fpipe = (FILE *)popen(command.c_str(),
"r");
2215 while (fgets(line,
sizeof(line), fpipe)) {
2216 std::string str(line);
2217 std::size_t found = str.find(
"Failed");
2219 if (found == std::string::npos) {
2220 std::vector<std::string> elm;
2222 for (
size_t i = 0; i < elm.size(); i++) {
2223 if (!elm[i].empty()) {
2225 if (resolution.size() == 2) {
2226 std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2236 #elif defined(_WIN32) 2238 w = GetSystemMetrics(SM_CXSCREEN);
2239 h = GetSystemMetrics(SM_CYSCREEN);
2242 "implemented on winrt"));
2252 unsigned int width, height;
2262 unsigned int width, height;
2267 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) 2277 if (opacity < 1.0) {
2279 overlay = m_background.clone();
2283 overlay = m_background;
2286 overlay_function(overlay);
2289 if (opacity < 1.0) {
2290 cv::addWeighted(overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background);
2295 #elif !defined(VISP_BUILD_SHARED_LIBS) 2298 void dummy_vpDisplayOpenCV(){};
void getScreenSize(unsigned int &width, unsigned int &height)
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)
unsigned int getScreenHeight()
int m_windowYPosition
display position
Class that defines generic functionnalities for display.
void clearDisplay(const vpColor &color=vpColor::white)
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 flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height)
void overlay(std::function< void(cv::Mat &)> overlay_function, double opacity)
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 RGB colors available for display functionnalities.
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static const vpColor lightGray
void setFont(const std::string &font)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height)
bool getPointerPosition(vpImagePoint &ip)
static const vpColor darkBlue
unsigned char G
Green component.
bool m_displayHasBeenInitialized
display has been initialized
static const vpColor green
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static const vpColor lightRed
virtual ~vpDisplayOpenCV()
void displayImage(const vpImage< unsigned char > &I)
static const vpColor orange
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)
int m_windowXPosition
display position
static const vpColor cyan
static const vpColor lightGreen
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
static double sqr(double x)
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)
unsigned char A
Additionnal component.
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)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
static const vpColor gray
static const vpColor darkGray
static int round(double x)
bool getPointerMotionEvent(vpImagePoint &ip)
Error that can be emited by the vpDisplay class and its derivates.
unsigned int getHeight() const
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
unsigned int getScreenWidth()
unsigned char R
Red component.
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 ...
static const vpColor yellow
static const vpColor lightBlue
static const vpColor purple
static const vpColor white
unsigned int getWidth() const
Function not implemented.
bool getKeyboardEvent(bool blocking=true)
void setWindowPosition(int winx, int winy)
static const vpColor blue