[C#]C# winform部署yolov11-pose姿态估计onnx模型

【算法介绍】

在C# WinForms应用中部署YOLOv11-Pose姿态估计ONNX模型是一项具有挑战性的任务。YOLOv11-Pose结合了YOLO(You Only Look Once)的高效物体检测算法和Pose Estimation(姿态估计)专注于识别人体关键点的能力,能在多种计算平台上实时处理人体姿态数据。

由于YOLOv11通常是用PyTorch等深度学习框架实现的,而OpenCV本身并不直接支持加载和运行PyTorch模型,因此需要先将PyTorch模型转换为ONNX格式,然后使用OpenCV的DNN模块加载ONNX模型。

部署过程中,需要确保开发环境已经安装了OpenCV 4.x(带有DNN模块)和必要的C#编译器。具体步骤包括加载ONNX模型、预处理输入图像、将预处理后的图像输入到模型中获取检测结果、对检测结果进行后处理等。由于YOLOv11是一个复杂的模型,其输出可能包含多个层的信息,因此需要仔细解析模型输出,并根据YOLOv11的具体实现进行后处理。

用户可以通过WinForms界面上传图像,应用程序则利用YOLOv11-Pose模型进行姿态估计,并在图像上标注出人体关键点的位置和类别。总的来说,虽然使用纯OpenCV部署YOLOv11-Pose ONNX模型需要深入理解相关领域的知识,但通过合理的步骤和优化,可以在C# WinForms应用中实现高效的人体姿态估计功能。

【效果展示】

 【实现部分代码】

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
    {
        Mat src = new Mat();
        Yolov11PoseManager ypm = new Yolov11PoseManager();
        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 = Cv2.ImRead(openFileDialog.FileName);
                pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);


            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(pictureBox1.Image==null)
            {
                return;
            }
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var result = ypm.Inference(src);
            sw.Stop();
            this.Text = "耗时" + sw.Elapsed.TotalSeconds + "秒";
            var resultMat = ypm.DrawImage(src,result);
            pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ypm.LoadWeights(Application.StartupPath+ "\\weights\\yolo11n-pose.onnx");

        }

        private void btn_video_Click(object sender, EventArgs e)
        {
            var detector = new Yolov11PoseManager();
            detector.LoadWeights(Application.StartupPath + "\\weights\\yolo11-pose.onnx");
            VideoCapture capture = new VideoCapture(Application.StartupPath+ "\\images\\test.mp4");
            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 result = detector.Inference(frame);
                var resultImg = detector.DrawImage(frame,result);
                sw.Stop();
                fps = Convert.ToInt32(1 / sw.Elapsed.TotalSeconds);
                sw.Reset();
                Cv2.PutText(resultImg, "FPS=" + fps, new OpenCvSharp.Point(30, 30), HersheyFonts.HersheyComplex, 1.0, new Scalar(255, 0, 0), 3);
                //显示结果
                Cv2.ImShow("Result", resultImg);
                int key = Cv2.WaitKey(10);
                if (key == 27)
                    break;
            }

            capture.Release();
  
        }
    }
}

【视频演示】

C# winform部署yolov11-pose姿态估计onnx模型_哔哩哔哩_bilibili测试环境:vs2019netframework4.7.2opencvsharp4.8.0onnxruntime1.16.3更多信息和源码下载参考博文:https://blog.csdn.net/FL1623863129/article/details/142729832, 视频播放量 1、弹幕量 0、点赞数 0、投硬币枚数 0、收藏人数 1、转发人数 0, 视频作者 未来自主研究中心, 作者简介 未来自主研究中心,相关视频:用C#部署yolov8的tensorrt模型进行目标检测winform最快检测速度,基于C#实现winform版yolov8-onnx+bytetrack目标追踪的算法结果演示,C# winform部署yolov11-obb旋转框检测onnx模型,C#使用纯opencvsharp部署yolov8-onnx图像分类模型,C# OpenCvSharp读取rtsp流录制mp4,C#部署官方yolov8-obb旋转框检测的onnx模型,C# winform使用纯opencvsharp部署yolox-onnx模型,C# winform基于opencvsharp实现15关键点人体姿态估计,为什么神经网络可以学习任何东西?首次使用动画讲解,带你吃透神经网络!(CNN卷积神经网络、RNN循环神经网络、GAN生成式对抗网络、人工智能、AI),使用C++部署yolov10目标检测的tensorrt模型支持图片视频推理windows测试通过icon-default.png?t=O83Ahttps://www.bilibili.com/video/BV1hG1iY6EQ5/
【源码下载】

https://download.csdn.net/download/FL1623863129/89852169
【测试环境】

vs2019

netframework4.7.2

opencvsharp4.8.0

onnxruntime1.16.3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FL1623863129

你的打赏是我写文章最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值