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


    目录

    效果

    模型信息

    项目

    代码

    下载 


    效果

    模型信息

    Inputs
    -------------------------
    name:image
    tensor:Float[1, 3, 256, 192]
    ---------------------------------------------------------------

    Outputs
    -------------------------
    name:conv2d_441.tmp_1
    tensor:Float[1, 17, 64, 48]
    name:argmax_0.tmp_0
    tensor:Int64[1, 17]
    ---------------------------------------------------------------

    项目

    VS2022

    .net framework 4.8

    OpenCvSharp 4.8

    openvino_2023.0.1.11005

    代码

    //推理模型路径中不能不含中文,否则会报错
    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);


    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 result_rect = pico_det.predict(image);

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

    List point_rects;
    List 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";

    1. using OpenCvSharp;
    2. using OpenCvSharp.Extensions;
    3. using System;
    4. using System.Collections.Generic;
    5. using System.ComponentModel;
    6. using System.Data;
    7. using System.Drawing;
    8. using System.Linq;
    9. using System.Text;
    10. using System.Windows.Forms;
    11. namespace OpenVinoSharp_PP_TinyPose人体姿态识别
    12. {
    13. public partial class Form1 : Form
    14. {
    15. public Form1()
    16. {
    17. InitializeComponent();
    18. }
    19. string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
    20. string image_path = "";
    21. String startupPath;
    22. DateTime dt1 = DateTime.Now;
    23. DateTime dt2 = DateTime.Now;
    24. // 行人检测模型
    25. string mode_path_det;
    26. // 关键点检测模型
    27. string mode_path_pose;
    28. // 设备名称
    29. string device_name;
    30. //行人区域检测
    31. PicoDet pico_det;
    32. //人体姿势检测
    33. PPTinyPose tiny_pose;
    34. Mat image;
    35. private void button2_Click(object sender, EventArgs e)
    36. {
    37. OpenFileDialog ofd = new OpenFileDialog();
    38. ofd.Filter = fileFilter;
    39. if (ofd.ShowDialog() != DialogResult.OK) return;
    40. pictureBox1.Image = null;
    41. image_path = ofd.FileName;
    42. pictureBox1.Image = new Bitmap(image_path);
    43. textBox1.Text = "";
    44. }
    45. private void Form1_Load(object sender, EventArgs e)
    46. {
    47. startupPath = Application.StartupPath;
    48. //推理模型路径中不能不含中文,否则会报错
    49. mode_path_det = Application.StartupPath + @"\TinyPoseModel\picodet_v2_s_320_pedestrian\ir\picodet_s_320_lcnet_pedestrian.xml";
    50. mode_path_pose = Application.StartupPath + @"\TinyPoseModel\tinypose_256_192\tinypose_256_192.onnx";
    51. // 设备名称
    52. device_name = "CPU";
    53. //行人区域检测
    54. pico_det = new PicoDet(mode_path_det, device_name);
    55. //人体姿势检测
    56. tiny_pose = new PPTinyPose(mode_path_pose, device_name);
    57. }
    58. private void button1_Click(object sender, EventArgs e)
    59. {
    60. tiny_pose_image();
    61. }
    62. public void tiny_pose_image()
    63. {
    64. if (image_path == "")
    65. {
    66. return;
    67. }
    68. image = Cv2.ImRead(image_path);
    69. OpenCvSharp.Size size_det = new OpenCvSharp.Size(320, 320);
    70. pico_det.set_shape(size_det, 2125);
    71. dt1 = DateTime.Now;
    72. List<Rect> result_rect = pico_det.predict(image);
    73. //人体姿势检测
    74. OpenCvSharp.Size size_pose = new OpenCvSharp.Size(256, 192);
    75. tiny_pose.set_shape(size_pose);
    76. List<Rect> point_rects;
    77. List<Mat> person_rois = tiny_pose.get_point_roi(image, result_rect, out point_rects);
    78. for (int p = 0; p < person_rois.Count; p++)
    79. {
    80. // 关键点识别
    81. float[,] person_point = tiny_pose.predict(person_rois[p]);
    82. tiny_pose.draw_poses(person_point, point_rects[p], ref image);
    83. }
    84. dt2 = DateTime.Now;
    85. for (int i = 0; i < result_rect.Count; i++)
    86. {
    87. Cv2.Rectangle(image, result_rect[i], new Scalar(255, 0, 0), 2);
    88. }
    89. pictureBox2.Image = BitmapConverter.ToBitmap(image);
    90. textBox1.Text = "耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
    91. }
    92. }
    93. }

    下载 

    exe程序下载

    完整Demo下载

  • 相关阅读:
    Python基础复习【第一弹】【黑马】
    Python并行计算库Joblib的技术原理解析
    程序单实例运行的一种实现
    【计算机毕业设计】基于SpringBoot+Vue记帐理财系统的设计与实现
    力扣刷题(122. 买卖股票的最佳时机 II)动规、贪心
    vue3—elementPlus如何单独修改页面中的某个下拉框样式
    有监督学习——高斯过程
    不同天气状况识别
    rpm包常用命令指南
    CAXA 3D实体设计2024:塑造未来的创新引擎
  • 原文地址:https://blog.csdn.net/lw112190/article/details/132720816