mirror of
https://github.com/opencv/opencv.git
synced 2026-11-15 05:47:57 -06:00
objdetect: handle unsupported QR modes gracefully - #30123 ### 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 - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake ### Description Resolves #30110. This PR addresses two related defects in `QRCodeDetector` and Python string conversion bindings: 1. **`objdetect`**: In `QRCodeDecoderImpl::decodeSymbols` (`qrcode_encoder.cpp`), encountering unsupported or unhandled QR mode indicators (such as Hanzi mode 13 or FNC1) previously called `CV_Error(Error::StsNotImplemented, format("mode %d", currMode))`, throwing an unhandled `cv2.error` exception out of high-level detector calls like `detectAndDecodeMulti()`. Replaced `CV_Error` with `return false;` to report symbol decode failure gracefully. 2. **`python`**: In `pyopencv_from(const String& value)` (`cv2_convert.cpp`), converting C++ string payloads to Python `str` previously called `PyString_FromString` (`PyUnicode_FromString`), which raises a `UnicodeDecodeError` when decoding non-UTF-8 payload bytes (e.g. GB2312 or Shift-JIS lead bytes). Updated string conversion to use `PyUnicode_DecodeUTF8(..., "surrogateescape")` with fallback to `PyBytes_FromStringAndSize`. ### Testing - Added `TEST(Objdetect_QRCode, unsupported_mode_graceful)` in `modules/objdetect/test/test_qrcode.cpp`.