【官方框架地址】
https://github.com/ultralytics/ultralytics
【算法介绍】
Yolov8-obb(You Only Look Once version 8 with Oriented Bounding Boxes)是一种先进的对象检测算法,它在传统的Yolov3和Yolov4基础上进行了优化,加入了OBB(Oriented Bounding Box)旋转框检测,能够更精确地检测并定位出目标物体的位置。
在传统的目标检测算法中,通常使用的是固定方向的边界框(Bounding Box),它假设所有物体在图像中的位置都是相对于图像中心来计算的。然而,这种假设并不总是成立,尤其在处理具有明显方向特征的物体时,固定方向的边界框就无法准确地定位物体的真实位置。
Yolov8-obb通过引入OBB旋转框检测,解决了这一问题。它允许边界框以任意角度存在,更能适应不同方向的目标物体。此外,Yolov8-obb还采用了一种称为“anchor”的机制,通过预设一系列不同大小和方向的锚点框,来逼近真实的物体位置。这种机制不仅提高了检测精度,还大大减少了需要训练的参数数量,提高了算法的效率。
除了旋转框检测,Yolov8-obb还在骨干网络、特征金字塔网络、分类器和回归器等方面进行了优化。例如,它采用了CSPDarknet53作为骨干网络,增强了特征提取能力;采用了多尺度特征融合策略,提高了对不同尺度目标的检测能力;采用了新的非极大值抑制算法,进一步筛选出最有可能的物体位置。
总的来说,Yolov8-obb通过引入旋转框检测和一系列优化策略,提高了目标检测的精度和效率,为计算机视觉领域带来了新的突破。
【效果展示】
【实现部分代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;namespace FIRC
{public partial class Form1 : Form{Bitmap src = null;Yolov8ObbManager detector = null;public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){OpenFileDialog openFileDialog = new OpenFileDialog();openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";openFileDialog.RestoreDirectory = true;openFileDialog.Multiselect = false;if (openFileDialog.ShowDialog() == DialogResult.OK){src = new Bitmap(openFileDialog.FileName);pictureBox1.Image = src;}}private void button2_Click(object sender, EventArgs e){if(pictureBox1.Image==null){return;}var result = detector.Inference(src);var resultImg = detector.DrawImage(src, result);pictureBox2.Image = resultImg;}private void Form1_Load(object sender, EventArgs e){detector = new Yolov8ObbManager(Application.StartupPath+"\\weights\\yolov8s-obb.onnx", Application.StartupPath + "\\weights\\labels.txt");}private void button3_Click(object sender, EventArgs e){VideoCapture capture = new VideoCapture(0);if (!capture.IsOpened()){Console.WriteLine("video not open!");return;}Mat frame = new Mat();var sw = new Stopwatch();int fps = 0;while (true){capture.Read(frame);if (frame.Empty()){Console.WriteLine("data is empty!");break;}sw.Start();var bmp = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(frame);var result = detector.Inference(bmp);var resultImg = detector.DrawImage(bmp, result);sw.Stop();fps = Convert.ToInt32(1 / sw.Elapsed.TotalSeconds);sw.Reset();frame = OpenCvSharp.Extensions.BitmapConverter.ToMat(new Bitmap(resultImg));Cv2.PutText(frame, "FPS=" + fps, new OpenCvSharp.Point(30, 30), HersheyFonts.HersheyComplex, 1.0, new Scalar(255, 0, 0), 3);//显示结果Cv2.ImShow("Result", frame);int key = Cv2.WaitKey(10);if (key == 27)break;}capture.Release();}}
}
【视频演示】
https://www.bilibili.com/video/BV1ki4y1i7up/?vd_source=989ae2b903ea1b5acebbe2c4c4a635ee
【测试环境】
vs2019,netframework4.7.2,onnxruntime1.16.3