From 971670826ef7cd66bd310b2ec4ce266862ac4fc7 Mon Sep 17 00:00:00 2001 From: fuyangchenghu <1015138540@qq.com> Date: Thu, 8 Feb 2024 12:03:40 +0800 Subject: [PATCH 1/2] commit change --- Samples/YOLOV5MultiInput/src/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Samples/YOLOV5MultiInput/src/main.cpp b/Samples/YOLOV5MultiInput/src/main.cpp index a85e23d..de9336a 100644 --- a/Samples/YOLOV5MultiInput/src/main.cpp +++ b/Samples/YOLOV5MultiInput/src/main.cpp @@ -141,6 +141,7 @@ void GetResult(std::vector& inferOutputs, int srcHeight = srcImage.rows; float widthScale = (float)(srcWidth) / modelWidth; float heightScale = (float)(srcHeight) / modelHeight; + float finalScale = (widthScale > heightScale) ? widthScale : heightScale; string textPrint = "["; for (uint32_t i = 0; i < totalBox; i++) { cv::Point p1, p2; @@ -148,10 +149,10 @@ void GetResult(std::vector& inferOutputs, if (score < 70) { continue; } - p1.x = detectData[totalBox * TOPLEFTX + i] * widthScale; - p1.y = detectData[totalBox * TOPLEFTY + i] * widthScale; - p2.x = detectData[totalBox * BOTTOMRIGHTX + i] * widthScale; - p2.y = detectData[totalBox * BOTTOMRIGHTY + i] * widthScale; + p1.x = detectData[totalBox * TOPLEFTX + i] * finalScale; + p1.y = detectData[totalBox * TOPLEFTY + i] * finalScale; + p2.x = detectData[totalBox * BOTTOMRIGHTX + i] * finalScale; + p2.y = detectData[totalBox * BOTTOMRIGHTY + i] * finalScale; uint32_t objIndex = (uint32_t)detectData[totalBox * LABEL + i]; string text = yolov3Label[objIndex] + std::to_string(score) + "\%"; textPrint = textPrint + text + " "; -- Gitee From 3dc015ea4f0450c8df37e1e9b77d70effdf2fead Mon Sep 17 00:00:00 2001 From: fuyangchenghu <1015138540@qq.com> Date: Thu, 8 Feb 2024 12:04:28 +0800 Subject: [PATCH 2/2] commit change --- Samples/YOLOV5USBCamera/src/main.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Samples/YOLOV5USBCamera/src/main.cpp b/Samples/YOLOV5USBCamera/src/main.cpp index 9d5d9c7..8347a9b 100644 --- a/Samples/YOLOV5USBCamera/src/main.cpp +++ b/Samples/YOLOV5USBCamera/src/main.cpp @@ -77,6 +77,9 @@ void GetResult(std::vector& inferOutputs, size_t widthIndex = 2; size_t heightIndex = 3; size_t classConfidenceIndex = 4; + float widthScale = (float)(srcWidth) / modelWidth; + float heightScale = (float)(srcHeight) / modelHeight; + float finalScale = (widthScale > heightScale) ? widthScale : heightScale; for (size_t i = 0; i < modelOutputBoxNum; ++i) { float maxValue = 0; float maxIndex = 0; @@ -92,10 +95,10 @@ void GetResult(std::vector& inferOutputs, size_t index = i * totalNumber + maxIndex + startIndex; float finalConfidence = classConfidence * classBuff[index]; BoundBox box; - box.x = classBuff[i * totalNumber] * srcWidth / modelWidth; - box.y = classBuff[i * totalNumber + yIndex] * srcWidth / modelWidth; - box.width = classBuff[i * totalNumber + widthIndex] * srcWidth/modelWidth; - box.height = classBuff[i * totalNumber + heightIndex] * srcWidth / modelWidth; + box.x = classBuff[i * totalNumber] * finalScale; + box.y = classBuff[i * totalNumber + yIndex] * finalScale; + box.width = classBuff[i * totalNumber + widthIndex] * finalScale; + box.height = classBuff[i * totalNumber + heightIndex] * finalScale; box.score = finalConfidence; box.classIndex = maxIndex; box.index = i; -- Gitee