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
This commit is contained in:
Alexander Smorkalov 2025-10-16 12:06:35 +03:00 committed by GitHub
parent d0d9bd20ed
commit 703f0bb0f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,10 +11,9 @@ class aruco_objdetect_test(NewOpenCVTests):
def test_aruco_dicts(self): def test_aruco_dicts(self):
try: try:
from svglib.svglib import svg2rlg import cairosvg
from reportlab.graphics import renderPM
except: except:
raise self.skipTest("libraies svglib and reportlab not found") raise self.skipTest("cairosvg library was not found")
else: else:
cols = 3 cols = 3
rows = 5 rows = 5
@ -49,8 +48,7 @@ class aruco_objdetect_test(NewOpenCVTests):
os.path.join(basedir, aruco_type_str[aruco_type_i]+'.json.gz'), 0) os.path.join(basedir, aruco_type_str[aruco_type_i]+'.json.gz'), 0)
pm.make_charuco_board() pm.make_charuco_board()
pm.save() pm.save()
drawing = svg2rlg(filesvg) cairosvg.svg2png(url=filesvg, write_to=filepng, background_color="white")
renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=72)
from_svg_img = cv.imread(filepng) 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_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) _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): def test_aruco_marker_sizes(self):
try: try:
from svglib.svglib import svg2rlg import cairosvg
from reportlab.graphics import renderPM
except: except:
raise self.skipTest("libraies svglib and reportlab not found") raise self.skipTest("cairosvg library was not found")
else: else:
cols = 3 cols = 3
rows = 5 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) board_height, "charuco_checkboard", marker_size, os.path.join(basedir, aruco_type_str+'.json.gz'), 0)
pm.make_charuco_board() pm.make_charuco_board()
pm.save() pm.save()
drawing = svg2rlg(filesvg) cairosvg.svg2png(url=filesvg, write_to=filepng, background_color="white")
renderPM.drawToFile(drawing, filepng, fmt='PNG', dpi=72)
from_svg_img = cv.imread(filepng) from_svg_img = cv.imread(filepng)
#test #test