From 334b7146f5ebfc204557893a6757cec80146e907 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Wed, 10 Dec 2025 15:20:08 +0800 Subject: [PATCH] Merge pull request #28157 from dkurt:normalize_vec_qrdetect Remove floating point arithmetic from angle computation in QR codes #28157 ### Pull Request Readiness Checklist resolves https://github.com/opencv/opencv/issues/24646 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 - [ ] 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 --- modules/objdetect/src/qrcode.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index f79829eb7c..7160bbf720 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -83,8 +83,10 @@ static Point2f intersectionLines(Point2f a1, Point2f a2, Point2f b1, Point2f b2) // / | // a/ | c -static inline double getCosVectors(Point2f a, Point2f b, Point2f c) +static inline double getCosVectors(Point a, Point b, Point c) { + CV_DbgCheckNE(a, b, "Angle between vector and point is undetermined"); + CV_DbgCheckNE(b, c, "Angle between vector and point is undetermined"); return ((a - b).x * (c - b).x + (a - b).y * (c - b).y) / (norm(a - b) * norm(c - b)); } @@ -825,7 +827,11 @@ vector QRDetect::getQuadrilateral(vector angle_list) Point intrsc_line_hull = intersectionLines(hull[index_hull], hull[next_index_hull], angle_list[1], angle_list[2]); - double temp_norm = getCosVectors(hull[index_hull], intrsc_line_hull, angle_closest_pnt); + double temp_norm = min_norm; + if (intrsc_line_hull != angle_closest_pnt) + { + temp_norm = getCosVectors(hull[index_hull], intrsc_line_hull, angle_closest_pnt); + } if (min_norm > temp_norm && norm(hull[index_hull] - hull[next_index_hull]) > norm(angle_list[1] - angle_list[2]) * 0.1) @@ -863,7 +869,11 @@ vector QRDetect::getQuadrilateral(vector angle_list) Point intrsc_line_hull = intersectionLines(hull[index_hull], hull[next_index_hull], angle_list[0], angle_list[1]); - double temp_norm = getCosVectors(hull[index_hull], intrsc_line_hull, angle_closest_pnt); + double temp_norm = min_norm; + if (intrsc_line_hull != angle_closest_pnt) + { + temp_norm = getCosVectors(hull[index_hull], intrsc_line_hull, angle_closest_pnt); + } if (min_norm > temp_norm && norm(hull[index_hull] - hull[next_index_hull]) > norm(angle_list[0] - angle_list[1]) * 0.05)