C# Onnx PP-Vehicle 车辆分析(包含:车辆检测,识别车型和车辆颜色)

2023-11-23 16:28

本文主要是介绍C# Onnx PP-Vehicle 车辆分析(包含:车辆检测,识别车型和车辆颜色),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

效果

模型信息

mot_ppyoloe_s_36e_ppvehicle.onnx 

vehicle_attribute_model.onnx

项目

代码

下载


C# Onnx PP-Vehicle 车辆分析(包含:车辆检测,识别车型和车辆颜色)

效果

模型信息

mot_ppyoloe_s_36e_ppvehicle.onnx 

Inputs
-------------------------
name:image
tensor:Float[-1, 3, 640, 640]
name:scale_factor
tensor:Float[-1, 2]
---------------------------------------------------------------

Outputs
-------------------------
name:multiclass_nms3_0.tmp_0
tensor:Float[-1, 6]
name:multiclass_nms3_0.tmp_2
tensor:Int32[1]
---------------------------------------------------------------

vehicle_attribute_model.onnx

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

Outputs
-------------------------
name:sigmoid_2.tmp_0
tensor:Float[-1, 19]
---------------------------------------------------------------

项目

VS2022

.net framework 4.8

OpenCvSharp 4.8

Microsoft.ML.OnnxRuntime 1.16.2

代码

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Text;

namespace Onnx_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

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

        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;

        Mat image;

        PP_YOLOE pp_yoloe;
        VehicleAttr vehicleAttr;

        StringBuilder sb = new StringBuilder();

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;

            pictureBox1.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";

            image_path = ofd.FileName;
            pictureBox1.Image = new System.Drawing.Bitmap(image_path);
            image = new Mat(image_path);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pp_yoloe = new PP_YOLOE("model/mot_ppyoloe_s_36e_ppvehicle.onnx", 0.6f);

            vehicleAttr = new VehicleAttr("model/vehicle_attribute_model.onnx");

            image_path = "test_img/1.jpg";
            pictureBox1.Image = new Bitmap(image_path);

        }

        private unsafe void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "检测中,请稍等……";
            pictureBox2.Image = null;
            sb.Clear();
            System.Windows.Forms.Application.DoEvents();

            image = new Mat(image_path);

            dt1 = DateTime.Now;
            List<BoxInfo> ltBoxInfo = pp_yoloe.Detect(image);
            dt2 = DateTime.Now;

            Mat result_image = image.Clone();
            //pp_yoloe.DrawPred(result_image, ltBoxInfo);

            sb.AppendLine("耗时:" + (dt2 - dt1).TotalMilliseconds + "ms");
            sb.AppendLine("------------------------------");

            for (int n = 0; n < ltBoxInfo.Count; n++)
            {

                Rect rect = new Rect();
                rect.X = (int)ltBoxInfo[n].xmin;
                rect.Y = (int)ltBoxInfo[n].ymin;
                rect.Width = (int)(ltBoxInfo[n].xmax - ltBoxInfo[n].xmin);
                rect.Height = (int)(ltBoxInfo[n].ymax - ltBoxInfo[n].ymin);
                Mat crop_img = new Mat(image, rect);

                string color_res_str = "color:";
                string type_res_str = "type:";

                vehicleAttr.Detect(crop_img, out color_res_str, out type_res_str);

                Cv2.Rectangle(result_image, new OpenCvSharp.Point(ltBoxInfo[n].xmin, ltBoxInfo[n].ymin), new OpenCvSharp.Point(ltBoxInfo[n].xmax, ltBoxInfo[n].ymax), new Scalar(0, 0, 255), 2);
                Cv2.PutText(result_image
                    , type_res_str + "," + color_res_str
                    , new OpenCvSharp.Point(ltBoxInfo[n].xmin, ltBoxInfo[n].ymin - 10)
                    , HersheyFonts.HersheySimplex
                    , 1
                    , new Scalar(0, 255, 0)
                    , 2);

                sb.AppendLine("vehicle:" + ltBoxInfo[n].score.ToString("0.00") + " " + type_res_str + "," + color_res_str);
            }


            if (pictureBox2.Image != null)
            {
                pictureBox2.Image.Dispose();
            }

            pictureBox2.Image = new System.Drawing.Bitmap(result_image.ToMemoryStream());
            textBox1.Text = sb.ToString();
        }

        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}
 

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Text;namespace Onnx_Demo
{public partial class frmMain : Form{public frmMain(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";DateTime dt1 = DateTime.Now;DateTime dt2 = DateTime.Now;Mat image;PP_YOLOE pp_yoloe;VehicleAttr vehicleAttr;StringBuilder sb = new StringBuilder();private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;pictureBox2.Image = null;textBox1.Text = "";image_path = ofd.FileName;pictureBox1.Image = new System.Drawing.Bitmap(image_path);image = new Mat(image_path);}private void Form1_Load(object sender, EventArgs e){pp_yoloe = new PP_YOLOE("model/mot_ppyoloe_s_36e_ppvehicle.onnx", 0.6f);vehicleAttr = new VehicleAttr("model/vehicle_attribute_model.onnx");image_path = "test_img/1.jpg";pictureBox1.Image = new Bitmap(image_path);}private unsafe void button2_Click(object sender, EventArgs e){if (image_path == ""){return;}textBox1.Text = "检测中,请稍等……";pictureBox2.Image = null;sb.Clear();System.Windows.Forms.Application.DoEvents();image = new Mat(image_path);dt1 = DateTime.Now;List<BoxInfo> ltBoxInfo = pp_yoloe.Detect(image);dt2 = DateTime.Now;Mat result_image = image.Clone();//pp_yoloe.DrawPred(result_image, ltBoxInfo);sb.AppendLine("耗时:" + (dt2 - dt1).TotalMilliseconds + "ms");sb.AppendLine("------------------------------");for (int n = 0; n < ltBoxInfo.Count; n++){Rect rect = new Rect();rect.X = (int)ltBoxInfo[n].xmin;rect.Y = (int)ltBoxInfo[n].ymin;rect.Width = (int)(ltBoxInfo[n].xmax - ltBoxInfo[n].xmin);rect.Height = (int)(ltBoxInfo[n].ymax - ltBoxInfo[n].ymin);Mat crop_img = new Mat(image, rect);string color_res_str = "color:";string type_res_str = "type:";vehicleAttr.Detect(crop_img, out color_res_str, out type_res_str);Cv2.Rectangle(result_image, new OpenCvSharp.Point(ltBoxInfo[n].xmin, ltBoxInfo[n].ymin), new OpenCvSharp.Point(ltBoxInfo[n].xmax, ltBoxInfo[n].ymax), new Scalar(0, 0, 255), 2);Cv2.PutText(result_image, type_res_str + "," + color_res_str, new OpenCvSharp.Point(ltBoxInfo[n].xmin, ltBoxInfo[n].ymin - 10), HersheyFonts.HersheySimplex, 1, new Scalar(0, 255, 0), 2);sb.AppendLine("vehicle:" + ltBoxInfo[n].score.ToString("0.00") + " " + type_res_str + "," + color_res_str);}if (pictureBox2.Image != null){pictureBox2.Image.Dispose();}pictureBox2.Image = new System.Drawing.Bitmap(result_image.ToMemoryStream());textBox1.Text = sb.ToString();}private void pictureBox2_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox2.Image);}private void pictureBox1_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox1.Image);}}
}

下载

源码下载

这篇关于C# Onnx PP-Vehicle 车辆分析(包含:车辆检测,识别车型和车辆颜色)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/419213

相关文章

C#中读取XML文件的四种常用方法

《C#中读取XML文件的四种常用方法》Xml是Internet环境中跨平台的,依赖于内容的技术,是当前处理结构化文档信息的有力工具,下面我们就来看看C#中读取XML文件的方法都有哪些吧... 目录XML简介格式C#读取XML文件方法使用XmlDocument使用XmlTextReader/XmlTextWr

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

Python如何实现PDF隐私信息检测

《Python如何实现PDF隐私信息检测》随着越来越多的个人信息以电子形式存储和传输,确保这些信息的安全至关重要,本文将介绍如何使用Python检测PDF文件中的隐私信息,需要的可以参考下... 目录项目背景技术栈代码解析功能说明运行结php果在当今,数据隐私保护变得尤为重要。随着越来越多的个人信息以电子形

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

C#比较两个List集合内容是否相同的几种方法

《C#比较两个List集合内容是否相同的几种方法》本文详细介绍了在C#中比较两个List集合内容是否相同的方法,包括非自定义类和自定义类的元素比较,对于非自定义类,可以使用SequenceEqual、... 目录 一、非自定义类的元素比较1. 使用 SequenceEqual 方法(顺序和内容都相等)2.

C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep

C#从XmlDocument提取完整字符串的方法

《C#从XmlDocument提取完整字符串的方法》文章介绍了两种生成格式化XML字符串的方法,方法一使用`XmlDocument`的`OuterXml`属性,但输出的XML字符串不带格式,可读性差,... 方法1:通过XMLDocument的OuterXml属性,见XmlDocument类该方法获得的xm

C#多线程编程中导致死锁的常见陷阱和避免方法

《C#多线程编程中导致死锁的常见陷阱和避免方法》在C#多线程编程中,死锁(Deadlock)是一种常见的、令人头疼的错误,死锁通常发生在多个线程试图获取多个资源的锁时,导致相互等待对方释放资源,最终形... 目录引言1. 什么是死锁?死锁的典型条件:2. 导致死锁的常见原因2.1 锁的顺序问题错误示例:不同

C#提取PDF表单数据的实现流程

《C#提取PDF表单数据的实现流程》PDF表单是一种常见的数据收集工具,广泛应用于调查问卷、业务合同等场景,凭借出色的跨平台兼容性和标准化特点,PDF表单在各行各业中得到了广泛应用,本文将探讨如何使用... 目录引言使用工具C# 提取多个PDF表单域的数据C# 提取特定PDF表单域的数据引言PDF表单是一