C# OpenVinoSharp PP-TinyPose 人体姿态识别
  yqdtHKhvd9Ja 2023年11月02日 127 0


效果

C# OpenVinoSharp PP-TinyPose 人体姿态识别_List

C# OpenVinoSharp PP-TinyPose 人体姿态识别_OpenVino_02

项目

C# OpenVinoSharp PP-TinyPose 人体姿态识别_List_03

部分代码

using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OpenVinoSharp_PP_TinyPose人体姿态识别
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        String startupPath;
        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;
        // 行人检测模型
        string mode_path_det;
        // 关键点检测模型
        string mode_path_pose;
        // 设备名称
        string device_name;
        //行人区域检测
        PicoDet pico_det;
        //人体姿势检测
        PPTinyPose tiny_pose;
        Mat image;

        private void button2_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 = "";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            startupPath = Application.StartupPath;

            //推理模型路径中不能不含中文,否则会报错
            mode_path_det = Application.StartupPath + @"\TinyPoseModel\picodet_v2_s_320_pedestrian\ir\picodet_s_320_lcnet_pedestrian.xml";
            mode_path_pose = Application.StartupPath + @"\TinyPoseModel\tinypose_256_192\tinypose_256_192.onnx";

            // 设备名称
            device_name = "CPU";
            //行人区域检测
            pico_det = new PicoDet(mode_path_det, device_name);
            //人体姿势检测
            tiny_pose = new PPTinyPose(mode_path_pose, device_name);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            tiny_pose_image();
        }


        public void tiny_pose_image()
        {
            if (image_path == "")
            {
                return;
            }

            image = Cv2.ImRead(image_path);

            OpenCvSharp.Size size_det = new OpenCvSharp.Size(320, 320);
            pico_det.set_shape(size_det, 2125);

            dt1 = DateTime.Now;
            List<Rect> result_rect = pico_det.predict(image);

            //人体姿势检测
            OpenCvSharp.Size size_pose = new OpenCvSharp.Size(256, 192);
            tiny_pose.set_shape(size_pose);

            List<Rect> point_rects;
            List<Mat> person_rois = tiny_pose.get_point_roi(image, result_rect, out point_rects);

            for (int p = 0; p < person_rois.Count; p++)
            {
                // 关键点识别
                float[,] person_point = tiny_pose.predict(person_rois[p]);
                tiny_pose.draw_poses(person_point, point_rects[p], ref image);
            }
            dt2 = DateTime.Now;

            for (int i = 0; i < result_rect.Count; i++)
            {
                Cv2.Rectangle(image, result_rect[i], new Scalar(255, 0, 0), 2);
            }
            pictureBox2.Image = BitmapConverter.ToBitmap(image);
            textBox1.Text = "耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
        }
    }
}

exe程序下载

完整Demo下载

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  DEdnwYVS9Z9b   2023年12月12日   24   0   0 ListredisredisList
  zT6CXotonQAP   2023年12月05日   34   0   0 SystemSystem
yqdtHKhvd9Ja