当前位置: 首页 > news >正文

[C#]C# winform部署yolov13目标检测的onnx模型

yolov13官方框架:github.com/iMoonLab/yolov13/releases/tag/yolov13

【测试环境】

vs2019

netframework4.7.2

opencvsharp4.8.0

onnxruntime==1.16.3

【效果展示】

【调用代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;namespace FIRC
{public partial class Form1 : Form{Mat src = new Mat();Yolov13Manager ym = new Yolov13Manager();public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){OpenFileDialog openFileDialog = new OpenFileDialog();openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";openFileDialog.RestoreDirectory = true;openFileDialog.Multiselect = false;if (openFileDialog.ShowDialog() == DialogResult.OK){src = Cv2.ImRead(openFileDialog.FileName);pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);}}private void button2_Click(object sender, EventArgs e){if(pictureBox1.Image==null){return;}Stopwatch sw = new Stopwatch();sw.Start();var result = ym.Inference(src);sw.Stop();this.Text = "耗时" + sw.Elapsed.TotalSeconds + "秒";var resultMat = ym.DrawImage(result,src);pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap}private void Form1_Load(object sender, EventArgs e){ym.LoadWeights(Application.StartupPath+ "\\weights\\yolov12n.onnx", Application.StartupPath + "\\weights\\labels.txt");}private void btn_video_Click(object sender, EventArgs e){var detector = new Yolov13Manager();detector.LoadWeights(Application.StartupPath + "\\weights\\yolov13n.onnx", Application.StartupPath + "\\weights\\labels.txt");VideoCapture capture = new VideoCapture(0);if (!capture.IsOpened()){Console.WriteLine("video not open!");return;}Mat frame = new Mat();var sw = new Stopwatch();int fps = 0;while (true){capture.Read(frame);if (frame.Empty()){Console.WriteLine("data is empty!");break;}sw.Start();var result = detector.Inference(frame);var resultImg = detector.DrawImage(result,frame);sw.Stop();fps = Convert.ToInt32(1 / sw.Elapsed.TotalSeconds);sw.Reset();Cv2.PutText(resultImg, "FPS=" + fps, new OpenCvSharp.Point(30, 30), HersheyFonts.HersheyComplex, 1.0, new Scalar(255, 0, 0), 3);//显示结果Cv2.ImShow("Result", resultImg);int key = Cv2.WaitKey(10);if (key == 27)break;}capture.Release();}}
}

【运行步骤】

(1)首先依据官方安装教程或者其他网站给的安装教程,安装好yolov13环境

(2)下载模型:yolov13n.pt
(3)导出onnx模型:yolo export model=yolov13n.pt format=onnx dynamic=False opset=12
(4)然后将yolov13.onnx模型放进FIRC\bin\x64\Debug\weights
最后运行项目选择x64 Debug即可,由于初次运行可能报错,如果报错请查看blog.csdn.net/FL1623863129/article/details/135424751
解决方法

【视频演示】

bilibili.com/video/BV1GaKRzrEC4/

http://www.dtcms.com/a/259918.html

相关文章:

  • VTK中的形态学处理
  • Pytest项目_day03(Postman使用)
  • # RK3588 Linux SDK 完整问题解决记录-编译内核头文件
  • React:利用计算属性名特点更新表单值
  • 鸿蒙边缘智能计算架构实战:从环境部署到分布式推理全流程
  • flutter的包管理#资源管理#调试Flutter应用#Flutter异常捕获
  • 龙蜥Confidential AI:开源机密计算AI解决方案,让云端模型安全运行
  • 推荐一个前端基于vue3.x,vite7.x,后端基于springboot3.4.x的完全开源的前后端分离的中后台管理系统基础项目(纯净版)
  • R语言使用nonrandom包进行倾向评分匹配
  • Golang中的map使用
  • Vue 2 项目中内嵌 md 文件
  • OpenCV计算机视觉实战(13)——轮廓检测详解
  • C++ - vector 的相关练习
  • AMS流媒体服务器-新版(h265-flv)
  • Spring--IOC容器的启动流程图解版
  • 大数据在UI前端的应用深化研究:用户行为模式的挖掘与分析
  • Axure版AntDesign 元件库-免费版
  • 使用Adobe Acrobat DC创建PDF表单域的完整指南
  • Linux网络协议栈的基石:深入剖析inet_hashtables.c的高效设计
  • 供应链管理:主要生产计划类型及其相关信息
  • 如果你在为理解RDA、PCA 和 PCoA而烦恼,不妨来看看丨TomatoSCI分析日记
  • MES与ERP深度融合:数据报表、可视化大屏及系统集成技术详解
  • 深入解析与修复 Linux 中的种种依赖项错误:Dependencies packages error solution
  • 分享一些实用的PHP函数(对比js/ts实现)
  • MySQL-主从复制分库分表
  • 超实用AI工具分享——ViiTor AI视频配音功能教程(附图文)
  • Java 大视界 -- 基于 Java 的大数据可视化在智慧城市能源消耗动态监测与优化决策中的应用(324)
  • 利用 YOLOv5-7.0 和 ByteTrack 实现多目标跟踪 — Python Demo 详解
  • 降低90%推理成本:腾讯混元+云函数动态扩缩容策略详解
  • c++面向对象编程