41#include <visp3/core/vpConfig.h>
43#if defined(HAVE_OPENCV_HIGHGUI)
52#include <visp3/core/vpDisplay.h>
53#include <visp3/core/vpImageTools.h>
54#include <visp3/core/vpIoTools.h>
55#include <visp3/core/vpMath.h>
56#include <visp3/gui/vpDisplayOpenCV.h>
59#include <visp3/core/vpDebug.h>
60#include <visp3/core/vpDisplayException.h>
62#include <opencv2/core/core_c.h>
64#if defined(HAVE_OPENCV_IMGPROC)
65#include <opencv2/imgproc/imgproc.hpp>
69#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)
73#include <visp3/gui/vpDisplayX.h>
78std::vector<std::string> vpDisplayOpenCV::m_listTitles = std::vector<std::string>();
79unsigned int vpDisplayOpenCV::m_nbWindows = 0;
104#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
105 m_background(NULL), col(NULL), cvcolor(), font(NULL),
107 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
109 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
110 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
111 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
112 y_rbuttonup(0), rbuttonup(false)
144#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
145 m_background(NULL), col(NULL), cvcolor(), font(NULL),
147 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
149 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
150 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
151 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
152 y_rbuttonup(0), rbuttonup(false)
155 init(I, x, y, title);
178#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
179 m_background(NULL), col(NULL), cvcolor(), font(NULL),
181 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
183 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
184 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
185 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
186 y_rbuttonup(0), rbuttonup(false)
214#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
215 m_background(NULL), col(NULL), cvcolor(), font(NULL),
217 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
219 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
220 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
221 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
222 y_rbuttonup(0), rbuttonup(false)
225 init(I, x, y, title);
252#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
253 m_background(NULL), col(NULL), cvcolor(), font(NULL),
255 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
257 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
258 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
259 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
260 y_rbuttonup(0), rbuttonup(false)
265 if (!title.empty()) {
268 std::ostringstream s;
270 m_title = std::string(
"Window ") + s.str();
276 for (size_t i = 0; i < m_listTitles.size(); i++) {
277 if (m_listTitles[i] == m_title) {
278 std::ostringstream s;
280 m_title = std::string(
"Window ") + s.str();
287 m_listTitles.push_back(m_title);
311#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
312 m_background(NULL), col(NULL), cvcolor(), font(NULL),
314 m_background(), col(NULL), cvcolor(), font(cv::FONT_HERSHEY_PLAIN), fontScale(0.8f),
316 fontHeight(10), x_move(0), y_move(0), move(false), x_lbuttondown(0), y_lbuttondown(0), lbuttondown(false),
317 x_mbuttondown(0), y_mbuttondown(0), mbuttondown(false), x_rbuttondown(0), y_rbuttondown(0), rbuttondown(false),
318 x_lbuttonup(0), y_lbuttonup(0), lbuttonup(false), x_mbuttonup(0), y_mbuttonup(0), mbuttonup(false), x_rbuttonup(0),
319 y_rbuttonup(0), rbuttonup(false)
329#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
330 cvReleaseImage(&m_background);
395#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
396 int flags = CV_WINDOW_AUTOSIZE;
398 int flags = cv::WINDOW_AUTOSIZE;
402 if (!title.empty()) {
406 std::ostringstream s;
408 m_title = std::string(
"Window ") + s.str();
414 for (
size_t i = 0; i < m_listTitles.size(); i++) {
415 if (m_listTitles[i] ==
m_title) {
416 std::ostringstream s;
418 m_title = std::string(
"Window ") + s.str();
425 m_listTitles.push_back(
m_title);
429#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
430 if (cvNamedWindow(this->
m_title.c_str(), flags) < 0) {
434 cv::namedWindow(this->
m_title, flags);
436#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
437 cvMoveWindow(this->
m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition);
439 cv::moveWindow(this->
m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition);
448#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
495#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
497 cvInitFont(font, CV_FONT_HERSHEY_PLAIN, 0.70f, 0.70f);
500 cvGetTextSize(
"A", font, &fontSize, &baseline);
505 fontSize = cv::getTextSize(
"A", font, fontScale, thickness, &baseline);
508 fontHeight = fontSize.height + baseline;
559#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
560 cvMoveWindow(this->
m_title.c_str(), winx, winy);
562 cv::moveWindow(this->
m_title.c_str(), winx, winy);
582#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
586 if (m_background != NULL) {
587 if (m_background->nChannels != channels || m_background->depth != depth ||
588 m_background->height != (
int)
m_height || m_background->width != (
int)
m_width) {
589 if (m_background->nChannels != 0)
590 cvReleaseImage(&m_background);
591 m_background = cvCreateImage(size, depth, channels);
594 m_background = cvCreateImage(size, depth, channels);
598 for (
unsigned int i = 0; i <
m_height; i++) {
599 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
600 for (
unsigned int j = 0; j <
m_width; j++) {
601 unsigned char val = I[i][j];
608 for (
unsigned int i = 0; i <
m_height; i++) {
609 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
610 for (
unsigned int j = 0; j <
m_width; j++) {
623 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (
int)
m_height ||
624 m_background.cols != (
int)
m_width) {
625 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
629 for (
unsigned int i = 0; i <
m_height; i++) {
630 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
631 for (
unsigned int j = 0; j <
m_width; j++) {
632 unsigned char val = I[i][j];
639 for (
unsigned int i = 0; i <
m_height; i++) {
640 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
641 for (
unsigned int j = 0; j <
m_width; j++) {
675#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
679 if (m_background != NULL) {
680 if (m_background->nChannels != channels || m_background->depth != depth ||
681 m_background->height != (
int)
m_height || m_background->width != (
int)
m_width) {
682 if (m_background->nChannels != 0)
683 cvReleaseImage(&m_background);
684 m_background = cvCreateImage(size, depth, channels);
687 m_background = cvCreateImage(size, depth, channels);
691 unsigned int i_min = (
unsigned int)iP.
get_i();
692 unsigned int j_min = (
unsigned int)iP.
get_j();
693 unsigned int i_max = (std::min)(i_min + h,
m_height);
694 unsigned int j_max = (std::min)(j_min + w,
m_width);
695 for (
unsigned int i = i_min; i < i_max; i++) {
696 unsigned char *dst_24 =
697 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
698 for (
unsigned int j = j_min; j < j_max; j++) {
699 unsigned char val = I[i][j];
706 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
707 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
710 for (
int i = i_min; i < i_max; i++) {
711 unsigned char *dst_24 =
712 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
713 for (
int j = j_min; j < j_max; j++) {
726 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (
int)
m_height ||
727 m_background.cols != (
int)
m_width) {
728 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
732 unsigned int i_min = (
unsigned int)iP.
get_i();
733 unsigned int j_min = (
unsigned int)iP.
get_j();
734 unsigned int i_max = (std::min)(i_min + h,
m_height);
735 unsigned int j_max = (std::min)(j_min + w,
m_width);
736 for (
unsigned int i = i_min; i < i_max; i++) {
737 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width + j_min * 3);
738 for (
unsigned int j = j_min; j < j_max; j++) {
739 unsigned char val = I[i][j];
746 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
747 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
750 for (
int i = i_min; i < i_max; i++) {
751 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width + j_min * 3);
752 for (
int j = j_min; j < j_max; j++) {
781#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
785 if (m_background != NULL) {
786 if (m_background->nChannels != channels || m_background->depth != depth ||
787 m_background->height != (
int)
m_height || m_background->width != (
int)
m_width) {
788 if (m_background->nChannels != 0)
789 cvReleaseImage(&m_background);
790 m_background = cvCreateImage(size, depth, channels);
793 m_background = cvCreateImage(size, depth, channels);
797 for (
unsigned int i = 0; i <
m_height; i++) {
798 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
799 for (
unsigned int j = 0; j <
m_width; j++) {
807 for (
unsigned int i = 0; i <
m_height; i++) {
808 unsigned char *dst_24 = (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep);
809 for (
unsigned int j = 0; j <
m_width; j++) {
820 cv::Size size((
int)this->m_width, (
int)this->m_height);
821 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (
int)
m_height ||
822 m_background.cols != (
int)
m_width) {
823 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
827 for (
unsigned int i = 0; i <
m_height; i++) {
828 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
829 for (
unsigned int j = 0; j <
m_width; j++) {
837 for (
unsigned int i = 0; i <
m_height; i++) {
838 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width);
839 for (
unsigned int j = 0; j <
m_width; j++) {
871#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
875 if (m_background != NULL) {
876 if (m_background->nChannels != channels || m_background->depth != depth ||
877 m_background->height != (
int)
m_height || m_background->width != (
int)
m_width) {
878 if (m_background->nChannels != 0)
879 cvReleaseImage(&m_background);
880 m_background = cvCreateImage(size, depth, channels);
883 m_background = cvCreateImage(size, depth, channels);
887 unsigned int i_min = (
unsigned int)iP.
get_i();
888 unsigned int j_min = (
unsigned int)iP.
get_j();
889 unsigned int i_max = (std::min)(i_min + h,
m_height);
890 unsigned int j_max = (std::min)(j_min + w,
m_width);
891 for (
unsigned int i = i_min; i < i_max; i++) {
892 unsigned char *dst_24 =
893 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
894 for (
unsigned int j = j_min; j < j_max; j++) {
902 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
903 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
906 for (
int i = i_min; i < i_max; i++) {
907 unsigned char *dst_24 =
908 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
909 for (
int j = j_min; j < j_max; j++) {
920 cv::Size size((
int)this->m_width, (
int)this->m_height);
921 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (
int)
m_height ||
922 m_background.cols != (
int)
m_width) {
923 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
927 unsigned int i_min = (
unsigned int)iP.
get_i();
928 unsigned int j_min = (
unsigned int)iP.
get_j();
929 unsigned int i_max = (std::min)(i_min + h,
m_height);
930 unsigned int j_max = (std::min)(j_min + w,
m_width);
931 for (
unsigned int i = i_min; i < i_max; i++) {
932 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width + j_min * 3);
933 for (
unsigned int j = j_min; j < j_max; j++) {
941 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
942 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
945 for (
int i = i_min; i < i_max; i++) {
946 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width + j_min * 3);
947 for (
int j = j_min; j < j_max; j++) {
981#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
988#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
989 cvDestroyWindow(this->
m_title.c_str());
991 cv::destroyWindow(this->
m_title);
994 for (
size_t i = 0; i < m_listTitles.size(); i++) {
995 if (
m_title == m_listTitles[i]) {
996 m_listTitles.erase(m_listTitles.begin() + (
long int)i);
1015#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1016 cvShowImage(this->
m_title.c_str(), m_background);
1019 cv::imshow(this->
m_title, m_background);
1033 const unsigned int )
1036#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1037 cvShowImage(this->
m_title.c_str(), m_background);
1040 cv::imshow(this->
m_title.c_str(), m_background);
1053 static bool warn_displayed =
false;
1054 if (!warn_displayed) {
1056 warn_displayed =
true;
1068 unsigned int w,
unsigned int h,
unsigned int thickness)
1076 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
1077 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
1122#if VISP_HAVE_OPENCV_VERSION < 0x020408
1123 cvPutText(m_background, text,
1127 cv::putText(m_background, text,
1129 font, fontScale, col[color.
id]);
1132 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1133#if VISP_HAVE_OPENCV_VERSION < 0x020408
1134 cvPutText(m_background, text,
1138 cv::putText(m_background, text,
1140 font, fontScale, cvcolor);
1160 unsigned int thickness)
1165 int r =
static_cast<int>(radius /
m_scale);
1166 cv::Scalar cv_color;
1168 cv_color = col[color.
id];
1170 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1173 if (fill ==
false) {
1174 int cv_thickness =
static_cast<int>(thickness);
1175#if VISP_HAVE_OPENCV_VERSION < 0x020408
1176 cvCircle(m_background, cvPoint(x, y), r, cv_color, cv_thickness);
1178 cv::circle(m_background, cv::Point(x, y), r, cv_color, cv_thickness);
1181#if VISP_HAVE_OPENCV_VERSION >= 0x030000
1182 int filled = cv::FILLED;
1184 int filled = CV_FILLED;
1186#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1187 double opacity =
static_cast<double>(color.
A) / 255.0;
1188#if VISP_HAVE_OPENCV_VERSION < 0x020408
1189 overlay([x, y, r, cv_color, filled](cv::Mat image) { cvCircle(image, cvPoint(x, y), r, cv_color, filled); },
1192 overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); },
1196#if VISP_HAVE_OPENCV_VERSION < 0x020408
1197 cvCircle(m_background, cvPoint(x, y), r, cv_color, filled);
1199 cv::circle(m_background, cv::Point(x, y), r, cv_color, filled);
1216 unsigned int thickness)
1220 top.set_i(ip.
get_i() - size / 2);
1221 top.set_j(ip.
get_j());
1243 unsigned int thickness)
1251 bool vertical_line = (int)ip2_.
get_j() == (int)ip1_.
get_j();
1252 if (vertical_line) {
1254 std::swap(ip1_, ip2_);
1257 std::swap(ip1_, ip2_);
1260 double diff_j = vertical_line ? 1 : ip2_.
get_j() - ip1_.
get_j();
1261 double deltaj = size / length * diff_j;
1262 double deltai = size / length * (ip2_.
get_i() - ip1_.
get_i());
1263 double slope = (ip2_.
get_i() - ip1_.
get_i()) / diff_j;
1264 double orig = ip1_.
get_i() - slope * ip1_.
get_j();
1266 if (vertical_line) {
1267 for (
unsigned int i = (
unsigned int)ip1_.
get_i(); i < ip2_.
get_i(); i += (
unsigned int)(2 * deltai)) {
1268 double j = ip1_.
get_j();
1272 for (
unsigned int j = (
unsigned int)ip1_.
get_j(); j < ip2_.
get_j(); j += (
unsigned int)(2 * deltaj)) {
1273 double i = slope * j + orig;
1289 unsigned int thickness)
1293#if VISP_HAVE_OPENCV_VERSION < 0x020408
1303 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1304#if VISP_HAVE_OPENCV_VERSION < 0x020408
1328 for (
unsigned int i = 0; i < thickness; i++) {
1330#if VISP_HAVE_OPENCV_VERSION < 0x020408
1333 col[color.
id], (
int)thickness);
1337 col[color.
id], (
int)thickness);
1340 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1341#if VISP_HAVE_OPENCV_VERSION < 0x020408
1344 cvcolor, (
int)thickness);
1348 cvcolor, (
int)thickness);
1373 const vpColor &color,
bool fill,
unsigned int thickness)
1380 cv::Scalar cv_color;
1382 cv_color = col[color.
id];
1384 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1387 if (fill ==
false) {
1388 int cv_thickness =
static_cast<int>(thickness);
1389#if VISP_HAVE_OPENCV_VERSION < 0x020408
1390 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1392 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1395#if VISP_HAVE_OPENCV_VERSION >= 0x030000
1396 int filled = cv::FILLED;
1398 int filled = CV_FILLED;
1400#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1401 double opacity =
static_cast<double>(color.
A) / 255.0;
1402#if VISP_HAVE_OPENCV_VERSION < 0x020408
1403 overlay([left, top, right, bottom, cv_color, filled](
1404 cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1408 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1409 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1414#if VISP_HAVE_OPENCV_VERSION < 0x020408
1415 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1417 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1440 const vpColor &color,
bool fill,
unsigned int thickness)
1447 cv::Scalar cv_color;
1449 cv_color = col[color.
id];
1451 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1454 if (fill ==
false) {
1455 int cv_thickness =
static_cast<int>(thickness);
1456#if VISP_HAVE_OPENCV_VERSION < 0x020408
1457 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1459 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1462#if VISP_HAVE_OPENCV_VERSION >= 0x030000
1463 int filled = cv::FILLED;
1465 int filled = CV_FILLED;
1467#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1468 double opacity =
static_cast<double>(color.
A) / 255.0;
1469#if VISP_HAVE_OPENCV_VERSION < 0x020408
1470 overlay([left, top, right, bottom, cv_color, filled](
1471 cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1475 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1476 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1481#if VISP_HAVE_OPENCV_VERSION < 0x020408
1482 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1484 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1513 cv::Scalar cv_color;
1515 cv_color = col[color.
id];
1517 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1520 if (fill ==
false) {
1521 int cv_thickness =
static_cast<int>(thickness);
1522#if VISP_HAVE_OPENCV_VERSION < 0x020408
1523 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1525 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1528#if VISP_HAVE_OPENCV_VERSION >= 0x030000
1529 int filled = cv::FILLED;
1531 int filled = CV_FILLED;
1533#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1534 double opacity =
static_cast<double>(color.
A) / 255.0;
1535#if VISP_HAVE_OPENCV_VERSION < 0x020408
1536 overlay([left, top, right, bottom, cv_color, filled](
1537 cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1541 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1542 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1547#if VISP_HAVE_OPENCV_VERSION < 0x020408
1548 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1550 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1580 lbuttondown =
false;
1581 mbuttondown =
false;
1582 rbuttondown =
false;
1587 lbuttondown =
false;
1591 mbuttondown =
false;
1595 rbuttondown =
false;
1598#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1603 }
while (ret ==
false && blocking ==
true);
1635 lbuttondown =
false;
1636 mbuttondown =
false;
1637 rbuttondown =
false;
1642 u = (
unsigned int)x_lbuttondown *
m_scale;
1643 v = (
unsigned int)y_lbuttondown *
m_scale;
1646 lbuttondown =
false;
1650 u = (
unsigned int)x_mbuttondown *
m_scale;
1651 v = (
unsigned int)y_mbuttondown *
m_scale;
1654 mbuttondown =
false;
1658 u = (
unsigned int)x_rbuttondown *
m_scale;
1659 v = (
unsigned int)y_rbuttondown *
m_scale;
1662 rbuttondown =
false;
1665#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1670 }
while (ret ==
false && blocking ==
true);
1703 lbuttondown =
false;
1704 mbuttondown =
false;
1705 rbuttondown =
false;
1710 u = (
unsigned int)x_lbuttondown *
m_scale;
1711 v = (
unsigned int)y_lbuttondown *
m_scale;
1715 lbuttondown =
false;
1719 u = (
unsigned int)x_mbuttondown *
m_scale;
1720 v = (
unsigned int)y_mbuttondown *
m_scale;
1724 mbuttondown =
false;
1728 u = (
unsigned int)x_rbuttondown *
m_scale;
1729 v = (
unsigned int)y_rbuttondown *
m_scale;
1733 rbuttondown =
false;
1736#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1741 }
while (ret ==
false && blocking ==
true);
1783 u = (
unsigned int)x_lbuttonup *
m_scale;
1784 v = (
unsigned int)y_lbuttonup *
m_scale;
1792 u = (
unsigned int)x_mbuttonup *
m_scale;
1793 v = (
unsigned int)y_mbuttonup *
m_scale;
1801 u = (
unsigned int)x_rbuttonup *
m_scale;
1802 v = (
unsigned int)y_rbuttonup *
m_scale;
1809#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1814 }
while (ret ==
false && blocking ==
true);
1835#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1836 case CV_EVENT_MOUSEMOVE:
1838 case cv::EVENT_MOUSEMOVE:
1846#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1847 case CV_EVENT_LBUTTONDOWN:
1849 case cv::EVENT_LBUTTONDOWN:
1852 disp->lbuttondown =
true;
1853 disp->x_lbuttondown = x;
1854 disp->y_lbuttondown = y;
1857#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1858 case CV_EVENT_MBUTTONDOWN:
1860 case cv::EVENT_MBUTTONDOWN:
1863 disp->mbuttondown =
true;
1864 disp->x_mbuttondown = x;
1865 disp->y_mbuttondown = y;
1868#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1869 case CV_EVENT_RBUTTONDOWN:
1871 case cv::EVENT_RBUTTONDOWN:
1874 disp->rbuttondown =
true;
1875 disp->x_rbuttondown = x;
1876 disp->y_rbuttondown = y;
1879#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1880 case CV_EVENT_LBUTTONUP:
1882 case cv::EVENT_LBUTTONUP:
1885 disp->lbuttonup =
true;
1886 disp->x_lbuttonup = x;
1887 disp->y_lbuttonup = y;
1890#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1891 case CV_EVENT_MBUTTONUP:
1893 case cv::EVENT_MBUTTONUP:
1896 disp->mbuttonup =
true;
1897 disp->x_mbuttonup = x;
1898 disp->y_mbuttonup = y;
1901#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1902 case CV_EVENT_RBUTTONUP:
1904 case cv::EVENT_RBUTTONUP:
1907 disp->rbuttonup =
true;
1908 disp->x_rbuttonup = x;
1909 disp->y_rbuttonup = y;
1943#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1944 int key_pressed = cvWaitKey(delay);
1946 int key_pressed = cv::waitKey(delay);
1949 if (key_pressed == -1)
1985#if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1986 int key_pressed = cvWaitKey(delay);
1988 int key_pressed = cv::waitKey(delay);
1990 if (key_pressed == -1)
1994 std::stringstream ss;
2023 double u = (
unsigned int)x_move /
m_scale;
2024 double v = (
unsigned int)y_move /
m_scale;
2053 u = (
unsigned int)x_move /
m_scale;
2054 v = (
unsigned int)y_move /
m_scale;
2072#if defined(VISP_HAVE_X11)
2075#elif defined(VISP_HAVE_XRANDR)
2076 std::string command =
"xrandr | grep '*'";
2077 FILE *fpipe = (FILE *)popen(command.c_str(),
"r");
2079 while (fgets(line,
sizeof(line), fpipe)) {
2080 std::string str(line);
2081 std::size_t found = str.find(
"Failed");
2083 if (found == std::string::npos) {
2084 std::vector<std::string> elm;
2086 for (
size_t i = 0; i < elm.size(); i++) {
2087 if (!elm[i].empty()) {
2089 if (resolution.size() == 2) {
2090 std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2100#elif defined(_WIN32)
2102 w = GetSystemMetrics(SM_CXSCREEN);
2103 h = GetSystemMetrics(SM_CYSCREEN);
2106 "implemented on winrt"));
2116 unsigned int width, height;
2126 unsigned int width, height;
2131#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
2141 if (opacity < 1.0) {
2143 overlay = m_background.clone();
2152 if (opacity < 1.0) {
2153 cv::addWeighted(
overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background);
2158#elif !defined(VISP_BUILD_SHARED_LIBS)
2161void dummy_vpDisplayOpenCV(){};
Class to define RGB colors available for display functionalities.
static const vpColor white
static const vpColor darkGray
static const vpColor black
static const vpColor cyan
static const vpColor orange
static const vpColor darkRed
static const vpColor blue
static const vpColor lightGray
static const vpColor lightBlue
static const vpColor darkGreen
static const vpColor darkBlue
static const vpColor purple
static const vpColor lightGreen
static const vpColor yellow
static const vpColor lightRed
static const vpColor green
static const vpColor gray
Error that can be emitted by the vpDisplay class and its derivatives.
@ notInitializedError
Display not initialized.
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void overlay(std::function< void(cv::Mat &)> overlay_function, double opacity)
void setWindowPosition(int winx, int winy)
void displayImage(const vpImage< unsigned char > &I)
unsigned int getScreenWidth()
void clearDisplay(const vpColor &color=vpColor::white)
bool getPointerMotionEvent(vpImagePoint &ip)
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height)
void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
bool getKeyboardEvent(bool blocking=true)
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void setFont(const std::string &font)
void setTitle(const std::string &title)
bool getClick(bool blocking=true)
virtual ~vpDisplayOpenCV()
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height)
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
void getScreenSize(unsigned int &width, unsigned int &height)
bool getPointerPosition(vpImagePoint &ip)
unsigned int getScreenHeight()
static void on_mouse(int event, int x, int y, int flags, void *param)
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
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)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void getScreenSize(unsigned int &width, unsigned int &height)
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
int m_windowXPosition
display position
int m_windowYPosition
display position
bool m_displayHasBeenInitialized
display has been initialized
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
error that can be emitted by ViSP classes.
@ functionNotImplementedError
Function not implemented.
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getHeight() const
static double sqr(double x)
static int round(double x)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additionnal component.
Defines a rectangle in the plane.