From 703f0bb0f2bc64abd24a26a05971751f43ede0ff Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov <2536374+asmorkalov@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:06:35 +0300 Subject: [PATCH] Merge pull request #27906 from asmorkalov:as/cairosvg Use cairosvg for pattern rendering to get rid of double resize. #27906 Depends on https://github.com/opencv/ci-gha-workflow/pull/269 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- apps/pattern-tools/test_charuco_board.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/pattern-tools/test_charuco_board.py b/apps/pattern-tools/test_charuco_board.py index 7d5602705b..e92a38a216 100644 --- a/apps/pattern-tools/test_charuco_board.py +++ b/apps/pattern-tools/test_charuco_board.py @@ -11,10 +11,9 @@ class aruco_objdetect_test(NewOpenCVTests): def test_aruco_dicts(self): try: - from svglib.svglib import svg2rlg - from reportlab.graphics import renderPM + import cairosvg except: - raise self.skipTest("libraies svglib and reportlab not found") + raise self.skipTest("cairosvg library was not found") else: cols = 3 rows = 5 @@ -49,8 +48,7 @@ class aruco_objdetect_test(NewOpenCVTests): os.path.join(basedir, aruco_type_str[aruco_type_i]+'.json.gz'), 0) pm.make_charuco_board() pm.save() - drawing = svg2rlg(filesvg) - renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=72) + cairosvg.svg2png(url=filesvg, write_to=filepng, background_color="white") from_svg_img = cv.imread(filepng) _charucoCorners, _charuco_ids_svg, marker_corners_svg, marker_ids_svg = charuco_detector.detectBoard(from_svg_img) _charucoCorners, _charuco_ids_cv, marker_corners_cv, marker_ids_cv = charuco_detector.detectBoard(from_cv_img) @@ -72,10 +70,9 @@ class aruco_objdetect_test(NewOpenCVTests): def test_aruco_marker_sizes(self): try: - from svglib.svglib import svg2rlg - from reportlab.graphics import renderPM + import cairosvg except: - raise self.skipTest("libraies svglib and reportlab not found") + raise self.skipTest("cairosvg library was not found") else: cols = 3 rows = 5 @@ -106,8 +103,7 @@ class aruco_objdetect_test(NewOpenCVTests): board_height, "charuco_checkboard", marker_size, os.path.join(basedir, aruco_type_str+'.json.gz'), 0) pm.make_charuco_board() pm.save() - drawing = svg2rlg(filesvg) - renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=72) + cairosvg.svg2png(url=filesvg, write_to=filepng, background_color="white") from_svg_img = cv.imread(filepng) #test