From 35f0b6ecc39ed985033076b87e93c9a1cc8b8a1e Mon Sep 17 00:00:00 2001 From: Evgeny Latkin Date: Wed, 20 Mar 2024 11:01:25 +0700 Subject: [PATCH 1/2] Fix data corruption in WeChatQRCode::impl::decode (it may lead to incorrect results if multiple QR found at image) --- modules/wechat_qrcode/src/wechat_qrcode.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/wechat_qrcode/src/wechat_qrcode.cpp b/modules/wechat_qrcode/src/wechat_qrcode.cpp index f4bec7c2b36..637827a7f5d 100644 --- a/modules/wechat_qrcode/src/wechat_qrcode.cpp +++ b/modules/wechat_qrcode/src/wechat_qrcode.cpp @@ -155,9 +155,11 @@ vector WeChatQRCode::Impl::decode(const Mat& img, vector& candidate if (use_nn_detector_) points_qr = aligner.warpBack(points_qr); + + auto point_to_save = Mat(4, 2, CV_32FC1); for (int j = 0; j < 4; ++j) { - point.at(j, 0) = points_qr[j].x; - point.at(j, 1) = points_qr[j].y; + point_to_save.at(j, 0) = points_qr[j].x; + point_to_save.at(j, 1) = points_qr[j].y; } // try to find duplicate qr corners bool isDuplicate = false; @@ -175,7 +177,7 @@ vector WeChatQRCode::Impl::decode(const Mat& img, vector& candidate } } if (isDuplicate == false) { - points.push_back(point); + points.push_back(point_to_save); check_points.push_back(points_qr); } else { @@ -244,4 +246,4 @@ vector WeChatQRCode::Impl::getScaleList(const int width, const int height return {0.5, 1.0}; } } // namespace wechat_qrcode -} // namespace cv \ No newline at end of file +} // namespace cv From db093afc1fbc7e0c159bf9915c69c9284b273ac1 Mon Sep 17 00:00:00 2001 From: Evgeny Latkin Date: Thu, 21 Mar 2024 20:29:05 +0700 Subject: [PATCH 2/2] Add `const` qualifier to `candidate_points` at WeChatQRCode::impl::decode --- modules/wechat_qrcode/src/wechat_qrcode.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/wechat_qrcode/src/wechat_qrcode.cpp b/modules/wechat_qrcode/src/wechat_qrcode.cpp index 637827a7f5d..64aad73610b 100644 --- a/modules/wechat_qrcode/src/wechat_qrcode.cpp +++ b/modules/wechat_qrcode/src/wechat_qrcode.cpp @@ -35,7 +35,8 @@ class WeChatQRCode::Impl { * @param points succussfully decoded qrcode with bounding box points. * @return vector */ - std::vector decode(const Mat& img, std::vector& candidate_points, + std::vector decode(const Mat& img, + const std::vector& candidate_points, std::vector& points); int applyDetector(const Mat& img, std::vector& points); Mat cropObj(const Mat& img, const Mat& point, Align& aligner); @@ -123,13 +124,14 @@ float WeChatQRCode::getScaleFactor() { return p->scaleFactor; }; -vector WeChatQRCode::Impl::decode(const Mat& img, vector& candidate_points, +vector WeChatQRCode::Impl::decode(const Mat& img, + const vector& candidate_points, vector& points) { if (candidate_points.size() == 0) { return vector(); } vector decode_results; - for (auto& point : candidate_points) { + for (const auto& point : candidate_points) { Mat cropped_img; Align aligner; if (use_nn_detector_) {