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

相关文章

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

OpenCV实现实时颜色检测的示例

《OpenCV实现实时颜色检测的示例》本文主要介绍了OpenCV实现实时颜色检测的示例,通过HSV色彩空间转换和色调范围判断实现红黄绿蓝颜色检测,包含视频捕捉、区域标记、颜色分析等功能,具有一定的参考... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间

苹果macOS 26 Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色

《苹果macOS26Tahoe主题功能大升级:可定制图标/高亮文本/文件夹颜色》在整体系统设计方面,macOS26采用了全新的玻璃质感视觉风格,应用于Dock栏、应用图标以及桌面小部件等多个界面... 科技媒体 MACRumors 昨日(6 月 13 日)发布博文,报道称在 macOS 26 Tahoe 中

MyBatis Plus 中 update_time 字段自动填充失效的原因分析及解决方案(最新整理)

《MyBatisPlus中update_time字段自动填充失效的原因分析及解决方案(最新整理)》在使用MyBatisPlus时,通常我们会在数据库表中设置create_time和update... 目录前言一、问题现象二、原因分析三、总结:常见原因与解决方法对照表四、推荐写法前言在使用 MyBATis

Python主动抛出异常的各种用法和场景分析

《Python主动抛出异常的各种用法和场景分析》在Python中,我们不仅可以捕获和处理异常,还可以主动抛出异常,也就是以类的方式自定义错误的类型和提示信息,这在编程中非常有用,下面我将详细解释主动抛... 目录一、为什么要主动抛出异常?二、基本语法:raise关键字基本示例三、raise的多种用法1. 抛

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

C#如何去掉文件夹或文件名非法字符

《C#如何去掉文件夹或文件名非法字符》:本文主要介绍C#如何去掉文件夹或文件名非法字符的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C#去掉文件夹或文件名非法字符net类库提供了非法字符的数组这里还有个小窍门总结C#去掉文件夹或文件名非法字符实现有输入字

C#之List集合去重复对象的实现方法

《C#之List集合去重复对象的实现方法》:本文主要介绍C#之List集合去重复对象的实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C# List集合去重复对象方法1、测试数据2、测试数据3、知识点补充总结C# List集合去重复对象方法1、测试数据

github打不开的问题分析及解决

《github打不开的问题分析及解决》:本文主要介绍github打不开的问题分析及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、找到github.com域名解析的ip地址二、找到github.global.ssl.fastly.net网址解析的ip地址三

C#实现将Office文档(Word/Excel/PDF/PPT)转为Markdown格式

《C#实现将Office文档(Word/Excel/PDF/PPT)转为Markdown格式》Markdown凭借简洁的语法、优良的可读性,以及对版本控制系统的高度兼容性,逐渐成为最受欢迎的文档格式... 目录为什么要将文档转换为 Markdown 格式使用工具将 Word 文档转换为 Markdown(.