首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

C# OpenCvSharp Yolov11 Pose 手部关键点检测

  • 25-02-19 03:42
  • 3556
  • 8809
blog.csdn.net

目录

效果

模型信息

项目

代码

下载

参考


效果

模型信息

Model Properties
-------------------------
date:2024-12-04T17:34:08.564548
description:Ultralytics YOLO11n-pose model trained on data.yaml
author:Ultralytics
version:8.3.5
kpt_shape:[21, 3]
task:pose
license:AGPL-3.0 License (https://ultralytics.com/license)
docs:https://docs.ultralytics.com
stride:32
batch:1
imgsz:[640, 640]
names:{0: 'hand'}
---------------------------------------------------------------

Inputs
-------------------------
name:images
tensor:Float[1, 3, 640, 640]
---------------------------------------------------------------

Outputs
-------------------------
name:output0
tensor:Float[1, 68, 8400]
---------------------------------------------------------------

项目

代码

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace OpenCvSharp_Yolov8_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        string startupPath;
        string classer_path;

        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
        string model_path;
        Mat image;

        PoseResult result_pro;
        Mat result_mat;
        Mat result_image;
        Mat result_mat_to_float;

        Net opencv_net;
        Mat BN_image;

        float[] result_array;
        float[] factors;

        int max_image_length;
        Mat max_image;
        Rect roi;

        Result result;
        StringBuilder sb = new StringBuilder();

        private void Form1_Load(object sender, EventArgs e)
        {
            startupPath = System.Windows.Forms.Application.StartupPath;
            model_path = startupPath + "\\best.onnx";
            classer_path = startupPath + "\\lable.txt";

            //初始化网络类,读取本地模型
            opencv_net = CvDnn.ReadNetFromOnnx(model_path);

            result_array = new float[8400 * 68];
            factors = new float[2];

            result_pro = new PoseResult(factors);

            //test.jpg
            image_path = "test.jpg";
            pictureBox1.Image = new Bitmap(image_path);
            textBox1.Text = "";
            image = new Mat(image_path);
            pictureBox2.Image = null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            textBox1.Text = "";
            image = new Mat(image_path);
            pictureBox2.Image = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }

            //缩放图片
            max_image_length = image.Cols > image.Rows ? image.Cols : image.Rows;
            max_image = Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);
            roi = new Rect(0, 0, image.Cols, image.Rows);
            image.CopyTo(new Mat(max_image, roi));

            factors[0] = factors[1] = (float)(max_image_length / 640.0);

            //数据归一化处理
            BN_image = CvDnn.BlobFromImage(max_image, 1 / 255.0, new OpenCvSharp.Size(640, 640), new Scalar(0, 0, 0), true, false);

            //配置图片输入数据
            opencv_net.SetInput(BN_image);

            dt1 = DateTime.Now;
            //模型推理,读取推理结果
            result_mat = opencv_net.Forward();
            dt2 = DateTime.Now;

            //将推理结果转为float数据类型
            result_mat_to_float = new Mat(8400, 68, MatType.CV_32F, result_mat.Data);

            //将数据读取到数组中
            result_mat_to_float.GetArray(out result_array);

            result = result_pro.process_result(result_array);

            result_image = result_pro.draw_result(result, image.Clone());

            if (!result_image.Empty())
            {
                pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
                sb.Clear();
                sb.AppendLine("推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms");
                sb.AppendLine("------------------------------");
                textBox1.Text = sb.ToString();
            }
            else
            {
                textBox1.Text = "无信息";
            }

        }
    }
}
 

  1. using OpenCvSharp;
  2. using OpenCvSharp.Dnn;
  3. using System;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. namespace OpenCvSharp_Yolov8_Demo
  8. {
  9. public partial class Form1 : Form
  10. {
  11. public Form1()
  12. {
  13. InitializeComponent();
  14. }
  15. string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
  16. string image_path = "";
  17. string startupPath;
  18. string classer_path;
  19. DateTime dt1 = DateTime.Now;
  20. DateTime dt2 = DateTime.Now;
  21. string model_path;
  22. Mat image;
  23. PoseResult result_pro;
  24. Mat result_mat;
  25. Mat result_image;
  26. Mat result_mat_to_float;
  27. Net opencv_net;
  28. Mat BN_image;
  29. float[] result_array;
  30. float[] factors;
  31. int max_image_length;
  32. Mat max_image;
  33. Rect roi;
  34. Result result;
  35. StringBuilder sb = new StringBuilder();
  36. private void Form1_Load(object sender, EventArgs e)
  37. {
  38. startupPath = System.Windows.Forms.Application.StartupPath;
  39. model_path = startupPath + "\\best.onnx";
  40. classer_path = startupPath + "\\lable.txt";
  41. //初始化网络类,读取本地模型
  42. opencv_net = CvDnn.ReadNetFromOnnx(model_path);
  43. result_array = new float[8400 * 68];
  44. factors = new float[2];
  45. result_pro = new PoseResult(factors);
  46. //test.jpg
  47. image_path = "test.jpg";
  48. pictureBox1.Image = new Bitmap(image_path);
  49. textBox1.Text = "";
  50. image = new Mat(image_path);
  51. pictureBox2.Image = null;
  52. }
  53. private void button1_Click(object sender, EventArgs e)
  54. {
  55. OpenFileDialog ofd = new OpenFileDialog();
  56. ofd.Filter = fileFilter;
  57. if (ofd.ShowDialog() != DialogResult.OK) return;
  58. pictureBox1.Image = null;
  59. image_path = ofd.FileName;
  60. pictureBox1.Image = new Bitmap(image_path);
  61. textBox1.Text = "";
  62. image = new Mat(image_path);
  63. pictureBox2.Image = null;
  64. }
  65. private void button2_Click(object sender, EventArgs e)
  66. {
  67. if (image_path == "")
  68. {
  69. return;
  70. }
  71. //缩放图片
  72. max_image_length = image.Cols > image.Rows ? image.Cols : image.Rows;
  73. max_image = Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3);
  74. roi = new Rect(0, 0, image.Cols, image.Rows);
  75. image.CopyTo(new Mat(max_image, roi));
  76. factors[0] = factors[1] = (float)(max_image_length / 640.0);
  77. //数据归一化处理
  78. BN_image = CvDnn.BlobFromImage(max_image, 1 / 255.0, new OpenCvSharp.Size(640, 640), new Scalar(0, 0, 0), true, false);
  79. //配置图片输入数据
  80. opencv_net.SetInput(BN_image);
  81. dt1 = DateTime.Now;
  82. //模型推理,读取推理结果
  83. result_mat = opencv_net.Forward();
  84. dt2 = DateTime.Now;
  85. //将推理结果转为float数据类型
  86. result_mat_to_float = new Mat(8400, 68, MatType.CV_32F, result_mat.Data);
  87. //将数据读取到数组中
  88. result_mat_to_float.GetArray<float>(out result_array);
  89. result = result_pro.process_result(result_array);
  90. result_image = result_pro.draw_result(result, image.Clone());
  91. if (!result_image.Empty())
  92. {
  93. pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
  94. sb.Clear();
  95. sb.AppendLine("推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms");
  96. sb.AppendLine("------------------------------");
  97. textBox1.Text = sb.ToString();
  98. }
  99. else
  100. {
  101. textBox1.Text = "无信息";
  102. }
  103. }
  104. }
  105. }

下载

源码下载

参考

GitHub - chrismuntean/YOLO11n-pose-hands: Trained YOLO11n-pose model on hand keypoints

天天代码码天天
微信公众号
.NET 人工智能实践
注:本文转载自blog.csdn.net的天天代码码天天的文章"https://lw112190.blog.csdn.net/article/details/144256800"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top