From 8308fbf9ba2a8804d21b14814f1c7460d1e67480 Mon Sep 17 00:00:00 2001 From: Thebinary110 Date: Fri, 24 Jul 2026 05:19:08 +0530 Subject: [PATCH 1/2] highgui: expose saveWindowParameters and loadWindowParameters to Python Both functions persist/restore a window's size, position, flags, trackbar values, and zoom/pan state (Qt highgui backend only), take only a plain String argument, and were already fully documented -- but were declared CV_EXPORTS instead of CV_EXPORTS_W, so they were unreachable from Python. Sibling Qt-only functions in the same header (displayOverlay, displayStatusBar) already follow the CV_EXPORTS_W + runtime "not implemented without Qt" convention this change follows. Adds a Python test that exercises namedWindow + save/loadWindowParameters and gracefully skips when no GUI backend or no Qt support is present, consistent with how other environment-dependent tests in this suite (e.g. CUDA) skip rather than fail. Verified locally: built opencv_python3 from this branch (WITH_QT=OFF) and confirmed cv2.saveWindowParameters / cv2.loadWindowParameters are present on the built module and correctly raise the expected "compiled without QT support" error, proving the binding reaches the C++ layer end-to-end. --- modules/highgui/include/opencv2/highgui.hpp | 4 +-- .../python/test/test_window_parameters.py | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 modules/highgui/misc/python/test/test_window_parameters.py diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index d30affc173..98761cb9e3 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -739,7 +739,7 @@ location of the window windowName. @param windowName Name of the window. */ -CV_EXPORTS void saveWindowParameters(const String& windowName); +CV_EXPORTS_W void saveWindowParameters(const String& windowName); /** @brief Loads parameters of the specified window. @@ -748,7 +748,7 @@ location of the window windowName. @param windowName Name of the window. */ -CV_EXPORTS void loadWindowParameters(const String& windowName); +CV_EXPORTS_W void loadWindowParameters(const String& windowName); CV_EXPORTS int startLoop(int (*pt2Func)(int argc, char *argv[]), int argc, char* argv[]); diff --git a/modules/highgui/misc/python/test/test_window_parameters.py b/modules/highgui/misc/python/test/test_window_parameters.py new file mode 100644 index 0000000000..da156d6c5c --- /dev/null +++ b/modules/highgui/misc/python/test/test_window_parameters.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +from __future__ import print_function + +import cv2 as cv + +from tests_common import NewOpenCVTests + + +class window_parameters_test(NewOpenCVTests): + + def test_save_load_window_parameters(self): + window_name = "test_save_load_window_parameters" + try: + cv.namedWindow(window_name, cv.WINDOW_NORMAL) + except cv.error: + self.skipTest("No GUI backend available in this build/environment") + + try: + # Should not raise when the library is built with a backend that + # supports persisting window state (currently: Qt). + cv.saveWindowParameters(window_name) + cv.loadWindowParameters(window_name) + except cv.error as e: + # Expected on builds without Qt support (see NO_QT_ERR_MSG in window.cpp) + self.skipTest("saveWindowParameters/loadWindowParameters require the Qt " + "highgui backend: " + str(e)) + finally: + cv.destroyWindow(window_name) + + +if __name__ == '__main__': + NewOpenCVTests.bootstrap() From 9c487708f93fe9714c93217b48e2f40a5ee4d472 Mon Sep 17 00:00:00 2001 From: Thebinary110 Date: Fri, 24 Jul 2026 12:31:53 +0530 Subject: [PATCH 2/2] highgui test: force offscreen Qt platform to avoid CI crash CI (Ubuntu ARM64 x2) showed the Python test suite aborting the whole process with exit code 134: on a Qt-enabled build, namedWindow() tried the "xcb" platform plugin, found no display (the Python test step, unlike the C++ gtest step, does not run under xvfb-run), and Qt aborted the process instead of raising a catchable exception -- so the existing try/except around namedWindow never got a chance to run. Fix: set QT_QPA_PLATFORM=offscreen (only if not already set) before any GUI call. "offscreen" is the platform plugin Qt ships specifically for headless/CI use, and is listed as available in the failing CI job's own log output. Verified locally: built opencv_python3 with WITH_QT=ON (real Qt6, not the WITH_QT=OFF build used in the initial verification), and confirmed that in a clean environment (no DISPLAY, no QT_QPA_PLATFORM preset), namedWindow + saveWindowParameters + loadWindowParameters all succeed with this fix, where they would previously depend on a native display backend being reachable. --- .../highgui/misc/python/test/test_window_parameters.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/highgui/misc/python/test/test_window_parameters.py b/modules/highgui/misc/python/test/test_window_parameters.py index da156d6c5c..02abc2d366 100644 --- a/modules/highgui/misc/python/test/test_window_parameters.py +++ b/modules/highgui/misc/python/test/test_window_parameters.py @@ -1,6 +1,16 @@ #!/usr/bin/env python from __future__ import print_function +import os + +# Force Qt's headless-safe platform plugin when nothing else is already +# configured. Without this, namedWindow() on a Qt-enabled build with no +# display server available (e.g. CI workers, which do not run the Python +# test suite under a virtual framebuffer) aborts the whole process instead +# of raising a catchable exception -- so this must be set *before* the +# first GUI call, and a plain try/except around namedWindow is not enough. +os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") + import cv2 as cv from tests_common import NewOpenCVTests