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)
442 cvMoveWindow(this->
m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition);
444 cv::moveWindow(this->
m_title.c_str(), this->m_windowXPosition, this->m_windowYPosition);
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++) {
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);
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++) {
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);
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++) {
876 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
880 if (m_background != NULL) {
881 if (m_background->nChannels != channels || m_background->depth != depth ||
882 m_background->height != (
int)
m_height || m_background->width != (
int)
m_width) {
883 if (m_background->nChannels != 0)
884 cvReleaseImage(&m_background);
885 m_background = cvCreateImage(size, depth, channels);
888 m_background = cvCreateImage(size, depth, channels);
892 unsigned int i_min = (
unsigned int)iP.
get_i();
893 unsigned int j_min = (
unsigned int)iP.
get_j();
894 unsigned int i_max = (std::min)(i_min + h,
m_height);
895 unsigned int j_max = (std::min)(j_min + w,
m_width);
896 for (
unsigned int i = i_min; i < i_max; i++) {
897 unsigned char *dst_24 =
898 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
899 for (
unsigned int j = j_min; j < j_max; j++) {
907 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
908 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
911 for (
int i = i_min; i < i_max; i++) {
912 unsigned char *dst_24 =
913 (
unsigned char *)m_background->imageData + (
int)(i * m_background->widthStep + j_min * 3);
914 for (
int j = j_min; j < j_max; j++) {
925 cv::Size size((
int)this->m_width, (
int)this->m_height);
926 if (m_background.channels() != channels || m_background.depth() != depth || m_background.rows != (
int)
m_height ||
927 m_background.cols != (
int)
m_width) {
928 m_background = cv::Mat(size, CV_MAKETYPE(depth, channels));
932 unsigned int i_min = (
unsigned int)iP.
get_i();
933 unsigned int j_min = (
unsigned int)iP.
get_j();
934 unsigned int i_max = (std::min)(i_min + h,
m_height);
935 unsigned int j_max = (std::min)(j_min + w,
m_width);
936 for (
unsigned int i = i_min; i < i_max; i++) {
937 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width + j_min * 3);
938 for (
unsigned int j = j_min; j < j_max; j++) {
946 int i_min = (std::max)((
int)ceil(iP.
get_i() /
m_scale), 0);
947 int j_min = (std::max)((
int)ceil(iP.
get_j() /
m_scale), 0);
950 for (
int i = i_min; i < i_max; i++) {
951 unsigned char *dst_24 = (
unsigned char *)m_background.data + (
int)(i * 3 *
m_width + j_min * 3);
952 for (
int j = j_min; j < j_max; j++) {
986 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
993 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
994 cvDestroyWindow(this->
m_title.c_str());
996 cv::destroyWindow(this->
m_title);
999 for (
size_t i = 0; i < m_listTitles.size(); i++) {
1000 if (
m_title == m_listTitles[i]) {
1001 m_listTitles.erase(m_listTitles.begin() + (
long int)i);
1020 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1021 cvShowImage(this->
m_title.c_str(), m_background);
1024 cv::imshow(this->
m_title, m_background);
1038 const unsigned int )
1041 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1042 cvShowImage(this->
m_title.c_str(), m_background);
1045 cv::imshow(this->
m_title.c_str(), m_background);
1058 static bool warn_displayed =
false;
1059 if (!warn_displayed) {
1061 warn_displayed =
true;
1073 unsigned int w,
unsigned int h,
unsigned int thickness)
1081 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
1082 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
1127 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1128 cvPutText(m_background, text,
1132 cv::putText(m_background, text,
1134 font, fontScale, col[color.
id]);
1137 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1138 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1139 cvPutText(m_background, text,
1143 cv::putText(m_background, text,
1145 font, fontScale, cvcolor);
1165 unsigned int thickness)
1170 int r =
static_cast<int>(radius /
m_scale);
1171 cv::Scalar cv_color;
1173 cv_color = col[color.
id];
1175 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1178 if (fill ==
false) {
1179 int cv_thickness =
static_cast<int>(thickness);
1180 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1181 cvCircle(m_background, cvPoint(x, y), r, cv_color, cv_thickness);
1183 cv::circle(m_background, cv::Point(x, y), r, cv_color, cv_thickness);
1186 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1187 int filled = cv::FILLED;
1189 int filled = CV_FILLED;
1191 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1192 double opacity =
static_cast<double>(color.
A) / 255.0;
1193 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1194 overlay([x, y, r, cv_color, filled](cv::Mat image) { cvCircle(image, cvPoint(x, y), r, cv_color, filled); },
1197 overlay([x, y, r, cv_color, filled](cv::Mat image) { cv::circle(image, cv::Point(x, y), r, cv_color, filled); },
1201 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1202 cvCircle(m_background, cvPoint(x, y), r, cv_color, filled);
1204 cv::circle(m_background, cv::Point(x, y), r, cv_color, filled);
1221 unsigned int thickness)
1225 top.set_i(ip.
get_i() - size / 2);
1226 top.set_j(ip.
get_j());
1248 unsigned int thickness)
1256 bool vertical_line = (int)ip2_.
get_j() == (int)ip1_.
get_j();
1257 if (vertical_line) {
1259 std::swap(ip1_, ip2_);
1262 std::swap(ip1_, ip2_);
1265 double diff_j = vertical_line ? 1 : ip2_.
get_j() - ip1_.
get_j();
1266 double deltaj = size / length * diff_j;
1267 double deltai = size / length * (ip2_.
get_i() - ip1_.
get_i());
1268 double slope = (ip2_.
get_i() - ip1_.
get_i()) / diff_j;
1269 double orig = ip1_.
get_i() - slope * ip1_.
get_j();
1271 if (vertical_line) {
1272 for (
unsigned int i = (
unsigned int)ip1_.
get_i(); i < ip2_.
get_i(); i += (
unsigned int)(2 * deltai)) {
1273 double j = ip1_.
get_j();
1277 for (
unsigned int j = (
unsigned int)ip1_.
get_j(); j < ip2_.
get_j(); j += (
unsigned int)(2 * deltaj)) {
1278 double i = slope * j + orig;
1294 unsigned int thickness)
1298 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1308 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1309 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1333 for (
unsigned int i = 0; i < thickness; i++) {
1335 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1338 col[color.
id], (
int)thickness);
1342 col[color.
id], (
int)thickness);
1345 cvcolor = CV_RGB(color.
R, color.
G, color.
B);
1346 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1349 cvcolor, (
int)thickness);
1353 cvcolor, (
int)thickness);
1378 const vpColor &color,
bool fill,
unsigned int thickness)
1385 cv::Scalar cv_color;
1387 cv_color = col[color.
id];
1389 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1392 if (fill ==
false) {
1393 int cv_thickness =
static_cast<int>(thickness);
1394 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1395 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1397 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1400 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1401 int filled = cv::FILLED;
1403 int filled = CV_FILLED;
1405 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1406 double opacity =
static_cast<double>(color.
A) / 255.0;
1407 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1408 overlay([left, top, right, bottom, cv_color, filled](
1409 cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1413 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1414 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1419 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1420 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1422 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1445 const vpColor &color,
bool fill,
unsigned int thickness)
1452 cv::Scalar cv_color;
1454 cv_color = col[color.
id];
1456 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1459 if (fill ==
false) {
1460 int cv_thickness =
static_cast<int>(thickness);
1461 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1462 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1464 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1467 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1468 int filled = cv::FILLED;
1470 int filled = CV_FILLED;
1472 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1473 double opacity =
static_cast<double>(color.
A) / 255.0;
1474 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1475 overlay([left, top, right, bottom, cv_color, filled](
1476 cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1480 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1481 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1486 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1487 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1489 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1518 cv::Scalar cv_color;
1520 cv_color = col[color.
id];
1522 cv_color = CV_RGB(color.
R, color.
G, color.
B);
1525 if (fill ==
false) {
1526 int cv_thickness =
static_cast<int>(thickness);
1527 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1528 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, cv_thickness);
1530 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, cv_thickness);
1533 #if VISP_HAVE_OPENCV_VERSION >= 0x030000
1534 int filled = cv::FILLED;
1536 int filled = CV_FILLED;
1538 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
1539 double opacity =
static_cast<double>(color.
A) / 255.0;
1540 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1541 overlay([left, top, right, bottom, cv_color, filled](
1542 cv::Mat image) { cvRectangle(image, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled); },
1546 [left, top, right, bottom, cv_color, filled](cv::Mat image) {
1547 cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1552 #if VISP_HAVE_OPENCV_VERSION < 0x020408
1553 cvRectangle(m_background, cvPoint(left, top), cvPoint(right, bottom), cv_color, filled);
1555 cv::rectangle(m_background, cv::Point(left, top), cv::Point(right, bottom), cv_color, filled);
1585 lbuttondown =
false;
1586 mbuttondown =
false;
1587 rbuttondown =
false;
1592 lbuttondown =
false;
1596 mbuttondown =
false;
1600 rbuttondown =
false;
1603 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1608 }
while (ret ==
false && blocking ==
true);
1640 lbuttondown =
false;
1641 mbuttondown =
false;
1642 rbuttondown =
false;
1647 u = (
unsigned int)x_lbuttondown *
m_scale;
1648 v = (
unsigned int)y_lbuttondown *
m_scale;
1651 lbuttondown =
false;
1655 u = (
unsigned int)x_mbuttondown *
m_scale;
1656 v = (
unsigned int)y_mbuttondown *
m_scale;
1659 mbuttondown =
false;
1663 u = (
unsigned int)x_rbuttondown *
m_scale;
1664 v = (
unsigned int)y_rbuttondown *
m_scale;
1667 rbuttondown =
false;
1670 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1675 }
while (ret ==
false && blocking ==
true);
1708 lbuttondown =
false;
1709 mbuttondown =
false;
1710 rbuttondown =
false;
1715 u = (
unsigned int)x_lbuttondown *
m_scale;
1716 v = (
unsigned int)y_lbuttondown *
m_scale;
1720 lbuttondown =
false;
1724 u = (
unsigned int)x_mbuttondown *
m_scale;
1725 v = (
unsigned int)y_mbuttondown *
m_scale;
1729 mbuttondown =
false;
1733 u = (
unsigned int)x_rbuttondown *
m_scale;
1734 v = (
unsigned int)y_rbuttondown *
m_scale;
1738 rbuttondown =
false;
1741 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1746 }
while (ret ==
false && blocking ==
true);
1788 u = (
unsigned int)x_lbuttonup *
m_scale;
1789 v = (
unsigned int)y_lbuttonup *
m_scale;
1797 u = (
unsigned int)x_mbuttonup *
m_scale;
1798 v = (
unsigned int)y_mbuttonup *
m_scale;
1806 u = (
unsigned int)x_rbuttonup *
m_scale;
1807 v = (
unsigned int)y_rbuttonup *
m_scale;
1814 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1819 }
while (ret ==
false && blocking ==
true);
1840 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1841 case CV_EVENT_MOUSEMOVE:
1843 case cv::EVENT_MOUSEMOVE:
1851 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1852 case CV_EVENT_LBUTTONDOWN:
1854 case cv::EVENT_LBUTTONDOWN:
1857 disp->lbuttondown =
true;
1858 disp->x_lbuttondown = x;
1859 disp->y_lbuttondown = y;
1862 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1863 case CV_EVENT_MBUTTONDOWN:
1865 case cv::EVENT_MBUTTONDOWN:
1868 disp->mbuttondown =
true;
1869 disp->x_mbuttondown = x;
1870 disp->y_mbuttondown = y;
1873 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1874 case CV_EVENT_RBUTTONDOWN:
1876 case cv::EVENT_RBUTTONDOWN:
1879 disp->rbuttondown =
true;
1880 disp->x_rbuttondown = x;
1881 disp->y_rbuttondown = y;
1884 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1885 case CV_EVENT_LBUTTONUP:
1887 case cv::EVENT_LBUTTONUP:
1890 disp->lbuttonup =
true;
1891 disp->x_lbuttonup = x;
1892 disp->y_lbuttonup = y;
1895 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1896 case CV_EVENT_MBUTTONUP:
1898 case cv::EVENT_MBUTTONUP:
1901 disp->mbuttonup =
true;
1902 disp->x_mbuttonup = x;
1903 disp->y_mbuttonup = y;
1906 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1907 case CV_EVENT_RBUTTONUP:
1909 case cv::EVENT_RBUTTONUP:
1912 disp->rbuttonup =
true;
1913 disp->x_rbuttonup = x;
1914 disp->y_rbuttonup = y;
1948 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1949 int key_pressed = cvWaitKey(delay);
1951 int key_pressed = cv::waitKey(delay);
1954 if (key_pressed == -1)
1990 #if (VISP_HAVE_OPENCV_VERSION < 0x020408)
1991 int key_pressed = cvWaitKey(delay);
1993 int key_pressed = cv::waitKey(delay);
1995 if (key_pressed == -1)
1999 std::stringstream ss;
2028 double u = (
unsigned int)x_move /
m_scale;
2029 double v = (
unsigned int)y_move /
m_scale;
2058 u = (
unsigned int)x_move /
m_scale;
2059 v = (
unsigned int)y_move /
m_scale;
2077 #if defined(VISP_HAVE_X11)
2080 #elif defined(VISP_HAVE_XRANDR)
2081 std::string command =
"xrandr | grep '*'";
2082 FILE *fpipe = (FILE *)popen(command.c_str(),
"r");
2084 while (fgets(line,
sizeof(line), fpipe)) {
2085 std::string str(line);
2086 std::size_t found = str.find(
"Failed");
2088 if (found == std::string::npos) {
2089 std::vector<std::string> elm;
2091 for (
size_t i = 0; i < elm.size(); i++) {
2092 if (!elm[i].empty()) {
2094 if (resolution.size() == 2) {
2095 std::istringstream sswidth(resolution[0]), ssheight(resolution[1]);
2105 #elif defined(_WIN32)
2107 w = GetSystemMetrics(SM_CXSCREEN);
2108 h = GetSystemMetrics(SM_CYSCREEN);
2111 "implemented on winrt"));
2121 unsigned int width, height;
2131 unsigned int width, height;
2136 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
2146 if (opacity < 1.0) {
2148 overlay = m_background.clone();
2157 if (opacity < 1.0) {
2158 cv::addWeighted(
overlay, opacity, m_background, 1.0 - opacity, 0.0, m_background);
2163 #elif !defined(VISP_BUILD_SHARED_LIBS)
2166 void dummy_vpDisplayOpenCV(){};
Class to define RGB colors available for display functionnalities.
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 emited by the vpDisplay class and its derivates.
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 functionnalities 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 emited 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)
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.