11#pragma once
22
33#include " YoloONNX.hpp"
4+ #include " ../../common/defines.h"
45
56// /
67// / \brief The YOLOv8_instance_onnx class
@@ -140,6 +141,9 @@ class YOLOv8_instance_onnx : public YoloONNX
140141 }
141142 }
142143
144+ // if (objectConf > 0.1)
145+ // std::cout << i << ": objectConf = " << objectConf << ", classId = " << classId << std::endl;
146+
143147 // if (i == 0)
144148 // {
145149 // std::cout << "without nms: mem" << i << ": ";
@@ -163,10 +167,10 @@ class YOLOv8_instance_onnx : public YoloONNX
163167 if (objectConf >= m_params.confThreshold )
164168 {
165169 // (center x, center y, width, height) to (x, y, w, h)
166- float x = fw * ( output[k] - output[k + 2 ] / 2 - m_resizedROI. x ) ;
167- float y = fh * ( output[k + 1 ] - output[k + 3 ] / 2 - m_resizedROI. y ) ;
168- float width = fw * output[k + 2 ];
169- float height = fh * output[k + 3 ];
170+ float x = output[k] - output[k + 2 ] / 2 ;
171+ float y = output[k + 1 ] - output[k + 3 ] / 2 ;
172+ float width = output[k + 2 ];
173+ float height = output[k + 3 ];
170174
171175 // auto ClampToFrame = [](float& v, float& size, int hi) -> int
172176 // {
@@ -198,9 +202,6 @@ class YOLOv8_instance_onnx : public YoloONNX
198202 // ClampToFrame(x, width, frameSize.width);
199203 // ClampToFrame(y, height, frameSize.height);
200204
201- // if (i == 0)
202- // std::cout << i << ": object_conf = " << object_conf << ", class_conf = " << class_conf << ", classId = " << classId << ", rect = " << cv::Rect(cvRound(x), cvRound(y), cvRound(width), cvRound(height)) << std::endl;
203-
204205 if (width > 4 && height > 4 )
205206 {
206207 classIds.push_back (classId);
@@ -213,6 +214,8 @@ class YOLOv8_instance_onnx : public YoloONNX
213214 }
214215 }
215216
217+ // std::cout << "rectBoxes.size = " << rectBoxes.size() << std::endl;
218+
216219 // Non-maximum suppression to eliminate redudant overlapping boxes
217220 std::vector<int > indices;
218221 cv::dnn::NMSBoxes (rectBoxes, confidences, m_params.confThreshold , m_params.nmsThreshold , indices);
@@ -254,7 +257,7 @@ class YOLOv8_instance_onnx : public YoloONNX
254257 cv::Rect roi (int ((float )padw / INPUT_W * segWidth), int ((float )padh / INPUT_H * segHeight), int (segWidth - padw / 2 ), int (segHeight - padh / 2 ));
255258 dest = dest (roi);
256259
257- cv::resize (dest, mask, frameSize , cv::INTER_NEAREST);
260+ cv::resize (dest, mask, cv::Size (INPUT_W, INPUT_H) , cv::INTER_NEAREST);
258261
259262 resBoxes[i].m_boxMask = mask (resBoxes[i].m_brect ) > MASK_THRESHOLD;
260263
@@ -274,31 +277,30 @@ class YOLOv8_instance_onnx : public YoloONNX
274277 {
275278 cv::Rect br = cv::boundingRect (contour);
276279
280+ // std::cout << "contour br: " << br << std::endl;
281+
277282 if (br.width >= 4 &&
278283 br.height >= 4 )
279284 {
280- cv::RotatedRect rr = (contour.size () < 5 ) ? cv::minAreaRect (contour) : cv::fitEllipse (contour);
281-
282- br.x += resBoxes[i].m_brect .x ;
283- br.y += resBoxes[i].m_brect .y ;
284- rr.center .x += resBoxes[i].m_brect .x ;
285- rr.center .y += resBoxes[i].m_brect .y ;
285+ int dx = resBoxes[i].m_brect .x ;
286+ int dy = resBoxes[i].m_brect .y ;
286287
287- // std::cout << "rr: " << rr.center << ", " << rr.angle << ", " << rr.size << std::endl;
288+ cv::RotatedRect rr = (contour.size () < 5 ) ? cv::minAreaRect (contour) : cv::fitEllipse (contour);
289+ rr.center .x = (rr.center .x + dx - m_resizedROI.x ) * fw;
290+ rr.center .y = (rr.center .y + dy - m_resizedROI.y ) * fw;
291+ rr.size .width *= fw;
292+ rr.size .height *= fh;
288293
289- if (resBoxes[i].m_boxMask .size () != br.size ())
290- {
291- br.width = resBoxes[i].m_boxMask .cols ;
292- br.height = resBoxes[i].m_boxMask .rows ;
293- if (br.x + br.width >= frameSize.width )
294- br.x = frameSize.width - br.width ;
295- if (br.y + br.height >= frameSize.height )
296- br.y = frameSize.height - br.height ;
297- }
294+ br.x = cvRound ((dx + br.x - m_resizedROI.x ) * fw);
295+ br.y = cvRound ((dy + br.y - m_resizedROI.y ) * fh);
296+ br.width = cvRound (br.width * fw);
297+ br.height = cvRound (br.height * fh);
298298
299299 resBoxes[i].m_brect = br;
300300 resBoxes[i].m_rrect = rr;
301301
302+ // std::cout << "resBoxes[" << i << "] br: " << br << ", rr: (" << rr.size << " from " << rr.center << ", " << rr.angle << ")" << std::endl;
303+
302304 break ;
303305 }
304306 }
0 commit comments