|
|
|
@ -172,19 +172,7 @@ void YOLOv8::letterbox(const cv::Mat& image, cv::Mat& out, cv::Size& size) |
|
|
|
|
|
|
|
|
|
cv::copyMakeBorder(tmp, tmp, top, bottom, left, right, cv::BORDER_CONSTANT, {114, 114, 114}); |
|
|
|
|
|
|
|
|
|
out.create({1, 3, (int)inp_h, (int)inp_w}, CV_32F); |
|
|
|
|
|
|
|
|
|
std::vector<cv::Mat> channels; |
|
|
|
|
cv::split(tmp, channels); |
|
|
|
|
|
|
|
|
|
cv::Mat c0((int)inp_h, (int)inp_w, CV_32F, (float*)out.data); |
|
|
|
|
cv::Mat c1((int)inp_h, (int)inp_w, CV_32F, (float*)out.data + (int)inp_h * (int)inp_w); |
|
|
|
|
cv::Mat c2((int)inp_h, (int)inp_w, CV_32F, (float*)out.data + (int)inp_h * (int)inp_w * 2); |
|
|
|
|
|
|
|
|
|
channels[0].convertTo(c2, CV_32F, 1 / 255.f); |
|
|
|
|
channels[1].convertTo(c1, CV_32F, 1 / 255.f); |
|
|
|
|
channels[2].convertTo(c0, CV_32F, 1 / 255.f); |
|
|
|
|
|
|
|
|
|
cv::dnn::blobFromImage(tmp, out, 1 / 255.f, cv::Size(), cv::Scalar(0, 0, 0), true, false, CV_32F); |
|
|
|
|
this->pparam.ratio = 1 / r; |
|
|
|
|
this->pparam.dw = dw; |
|
|
|
|
this->pparam.dh = dh; |
|
|
|
@ -197,8 +185,8 @@ void YOLOv8::copy_from_Mat(const cv::Mat& image) |
|
|
|
|
{ |
|
|
|
|
cv::Mat nchw; |
|
|
|
|
auto& in_binding = this->input_bindings[0]; |
|
|
|
|
int width = in_binding.dims.d[3]; |
|
|
|
|
int height = in_binding.dims.d[2]; |
|
|
|
|
auto width = in_binding.dims.d[3]; |
|
|
|
|
auto height = in_binding.dims.d[2]; |
|
|
|
|
cv::Size size{width, height}; |
|
|
|
|
this->letterbox(image, nchw, size); |
|
|
|
|
|
|
|
|
@ -284,9 +272,8 @@ void YOLOv8::draw_objects(const cv::Mat& image, |
|
|
|
|
int x = (int)obj.rect.x; |
|
|
|
|
int y = (int)obj.rect.y + 1; |
|
|
|
|
|
|
|
|
|
if (y > res.rows) { |
|
|
|
|
if (y > res.rows) |
|
|
|
|
y = res.rows; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cv::rectangle(res, cv::Rect(x, y, label_size.width, label_size.height + baseLine), {0, 0, 255}, -1); |
|
|
|
|
|
|
|
|
|