[C#]winform部署官方yolov8-obb旋转框检测的onnx模型

【官方框架地址】

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
 

相关推荐

  1. yolov8目标检测-onnx模型推理

    2024-01-20 14:38:01       24 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-20 14:38:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-20 14:38:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-20 14:38:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-20 14:38:01       18 阅读

热门阅读

  1. springboot 集成websocket

    2024-01-20 14:38:01       33 阅读
  2. 记录 | 修改.gitignore文件,如何重新生效

    2024-01-20 14:38:01       34 阅读
  3. 深度解析window.history.go()和history.back()

    2024-01-20 14:38:01       33 阅读
  4. windows 利用DDNS-GO解析IPV6

    2024-01-20 14:38:01       41 阅读
  5. Todo List 变成 Contribution List

    2024-01-20 14:38:01       30 阅读
  6. C++:史上最坑小游戏

    2024-01-20 14:38:01       32 阅读
  7. Unity音频管理器

    2024-01-20 14:38:01       31 阅读
  8. QML与C++交互详解

    2024-01-20 14:38:01       33 阅读
  9. excel 常用函数

    2024-01-20 14:38:01       35 阅读
  10. 2024 前端高频面试题之 Vue 篇

    2024-01-20 14:38:01       26 阅读
  11. 126 对称的二叉树

    2024-01-20 14:38:01       21 阅读
  12. Spring中的IOC与AOP的理解(1)

    2024-01-20 14:38:01       30 阅读
  13. Go 常见报错 - VsCode运行go:go.mod file not found

    2024-01-20 14:38:01       31 阅读