opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
76.24k stars 55.63k forks source link

highgui: wayland: Exception when showing too small width image #25560

Closed Kumataro closed 2 weeks ago

Kumataro commented 3 weeks ago

System Information

OpenCV version: 4.x ( ba65d2eb0d83e6c9567a2534f8994cd4484a1635 ) Operating System / Platform: Ubuntu 24.04 Compiler & compiler version: GCC 13.2

Detailed description

When imshow() with small width image, exception is happen. Because window view width is too small enogh to show title bar. (In this case, roi is used to fill area. but it has negative position).

kmtr@kmtr-VMware-Virtual-Platform:~/work/build4-main$ ./bin/opencv_test_highgui --gtest_filter="*small*"
:
: 
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Highgui_GUI
[ RUN      ] Highgui_GUI.small_width_image
[ INFO:0@0.007] global registry.impl.hpp:114 UIBackendRegistry UI: Enabled backends(3, sorted by priority): GTK(1000); GTK3(990); GTK2(980) + BUILTIN(Wayland)
[*] DEBUG: handle_toplevel_configure: maximized=0 fullscreen=0 resizing=0 focused=0 size=[0 x 0]
Exception message: OpenCV(4.9.0-dev) /home/kmtr/work/opencv4/modules/core/src/matrix.cpp:808: error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'Mat'

/home/kmtr/work/opencv4/modules/highgui/test/test_gui.cpp:221: Failure
Expected: waitKey(1000) doesn't throw an exception.
  Actual: it throws.
[  FAILED  ] Highgui_GUI.small_width_image (59 ms)
[----------] 1 test from Highgui_GUI (59 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (59 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] Highgui_GUI.small_width_image

Steps to reproduce

diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp
index 8991e8072b..7821346a99 100644
--- a/modules/highgui/test/test_gui.cpp
+++ b/modules/highgui/test/test_gui.cpp
@@ -205,6 +205,22 @@ TEST(Highgui_GUI, trackbar)
     EXPECT_NO_THROW(destroyAllWindows());
 }

+// See XXXX
+#if (!defined(ENABLE_PLUGINS) \
+      && !defined HAVE_WAYLAND )
+TEST(Highgui_GUI, DISABLED_small_width_image)
+#else
+TEST(Highgui_GUI, small_width_image)
+#endif
+{
+    const std::string window_name("trackbar_test_window");
+    cv::Mat src(1,1,CV_8UC3,cv::Scalar(0));
+    EXPECT_NO_THROW(destroyAllWindows());
+    ASSERT_NO_THROW(namedWindow(window_name));
+    ASSERT_NO_THROW(imshow(window_name, src));
+    ASSERT_NO_THROW(waitKey(1000));
+    EXPECT_NO_THROW(destroyAllWindows());
+}

Issue submission checklist