From 120121891dc2312cf8a926bb36b4acfee6b460ca Mon Sep 17 00:00:00 2001 From: emptysoal <57931586+emptysoal@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:15:21 +0800 Subject: [PATCH] modify yolov8 cpu postprocess iou (#1390) --- yolov8/src/postprocess.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/yolov8/src/postprocess.cpp b/yolov8/src/postprocess.cpp index b9aa36e..d16762e 100644 --- a/yolov8/src/postprocess.cpp +++ b/yolov8/src/postprocess.cpp @@ -30,17 +30,18 @@ cv::Rect get_rect(cv::Mat &img, float bbox[4]) { static float iou(float lbox[4], float rbox[4]) { float interBox[] = { - (std::max)(lbox[0] - lbox[2] / 2.f, rbox[0] - rbox[2] / 2.f), //left - (std::min)(lbox[0] + lbox[2] / 2.f, rbox[0] + rbox[2] / 2.f), //right - (std::max)(lbox[1] - lbox[3] / 2.f, rbox[1] - rbox[3] / 2.f), //top - (std::min)(lbox[1] + lbox[3] / 2.f, rbox[1] + rbox[3] / 2.f), //bottom + (std::max)(lbox[0], rbox[0]), //left + (std::min)(lbox[2], rbox[2]), //right + (std::max)(lbox[1], rbox[1]), //top + (std::min)(lbox[3], rbox[3]), //bottom }; if (interBox[2] > interBox[3] || interBox[0] > interBox[1]) return 0.0f; float interBoxS = (interBox[1] - interBox[0]) * (interBox[3] - interBox[2]); - return interBoxS / (lbox[2] * lbox[3] + rbox[2] * rbox[3] - interBoxS); + float unionBoxS = (lbox[2] - lbox[0]) * (lbox[3] - lbox[1]) + (rbox[2] - rbox[0]) * (rbox[3] - rbox[1]) - interBoxS; + return interBoxS / unionBoxS; } static bool cmp(const Detection &a, const Detection &b) { @@ -184,4 +185,4 @@ void draw_mask_bbox(cv::Mat& img, std::vector& dets, std::vector