From c04750ab570e6d067748770a7cf43967f32caefd Mon Sep 17 00:00:00 2001 From: Dhanwanth1803 <147172285+Dhanwanth1803@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:40:52 +0530 Subject: [PATCH] Merge pull request #25091 from Dhanwanth1803:scoreThresh Fixes #25056 : Optimising postProcess(const std::vector& output_blobs) #25091 Like mentioned in the issue #25056 , I think checking the condition with `scoreThreshold` and then assigning the bounding boxes can optimize the function pretty well. By doing this, we prevent allocating boxes to faces with scores below the threshold. It also reduces the amount of data that needs to be processed during the subsequent NMS step. Builds and passed locally. - [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. - [ ] The feature is well documented and sample code can be built with the project CMake Co-authored-by: Dhanwanth1803 --- modules/objdetect/src/face_detect.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/objdetect/src/face_detect.cpp b/modules/objdetect/src/face_detect.cpp index bff7e0b13e..441c55e788 100644 --- a/modules/objdetect/src/face_detect.cpp +++ b/modules/objdetect/src/face_detect.cpp @@ -200,6 +200,9 @@ private: float score = std::sqrt(cls_score * obj_score); face.at(0, 14) = score; + // Checking if the score meets the threshold before adding the face + if (score < scoreThreshold) + continue; // Get bounding box float cx = ((c + bbox_v[idx * 4 + 0]) * strides[i]); float cy = ((r + bbox_v[idx * 4 + 1]) * strides[i]);