行业知识
C# Onnx yolov8 竹签计数、一次性筷子计数
2026-11-18 21:19:31
来源:互联网转载
���录
效果
模型信息
项目
代码
数据集
下载
C# Onnx yolov8 竹签计数、一次性筷子计数
效果
模型信息
Model Properties
-------------------------
date:2024-01-03T08:55:22.768617
author:Ultralytics
task:detect
license:AGPL-3.0 https://ultralytics.com/license
version:8.0.172
stride:32
batch:1
imgsz:[640, 640]
names:{0: 'label'}
---------------------------------------------------------------
Inputs
-------------------------
name:images
tensor:Float[1, 3, 640, 640]
---------------------------------------------------------------
Outputs
-------------------------
name:output0
tensor:Float[1, 5, 8400]
---------------------------------------------------------------
项目
代码
using Microsoft.ML.OnnxRuntime;using Microsoft.ML.OnnxRuntime.Tensors;using OpenCvSharp;using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Imaging;using System.Linq;using System.Windows.Forms;namespace Onnx_Yolov8_Demo{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png"; string image_path = ""; string startupPath; string classer_path; DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; string model_path; Mat image; DetectionResult result_pro; Mat result_image; Result result; SessionOptions options; InferenceSession onnx_session; Tensor input_tensor; List input_container; IDisposableReadOnlyCollection result_infer; DisposableNamedOnnxValue[] results_onnxvalue; Tensor result_tensors; private void button1_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 = ""; image = new Mat(image_path); pictureBox2.Image = null; } private void button2_Click(object sender, EventArgs e) { if (image_path == "") { return; } button2.Enabled = false; pictureBox2.Image = null; textBox1.Text = ""; pictureBox2.Image = null; Application.DoEvents(); //图片缩放 image = new Mat(image_path); int max_image_length = image.Cols > image.Rows ? image.Cols : image.Rows; Mat max_image = Mat.Zeros(new OpenCvSharp.Size(max_image_length, max_image_length), MatType.CV_8UC3); Rect roi = new Rect(0, 0, image.Cols, image.Rows); image.CopyTo(new Mat(max_image, roi)); float[] result_array = new float[8400 * 84]; float[] factors = new float[2]; factors[0] = factors[1] = (float)(max_image_length / 640.0); // 将图片转为RGB通道 Mat image_rgb = new Mat(); Cv2.CvtColor(max_image, image_rgb, ColorConversionCodes.BGR2RGB); Mat resize_image = new Mat(); Cv2.Resize(image_rgb, resize_image, new OpenCvSharp.Size(640, 640)); // 输入Tensor for (int y = 0; y 数据集
下载
数据集(带标注)下载
源码下载