【測試環境】
vs2019
net framework4.7.2
onnxruntime==1.16.3
opencvsharp
注意源碼運行在CPU上不支持GPU運行,由于net framework限制GPU會很慢因此沒有GPU版本提供。
【運行步驟】
打開sln項目
選擇x64 debug運行即可
如需要再x64 release運行可以將x64 debug文件夾里面所有文件復制到x64 release文件夾里面然后再vs2019切換到x64 release運行即可。
【效果展示】
【界面設計代碼】
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();Yolov8SegManager ym = new Yolov8SegManager();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(src,result);pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat轉Bitmap}private void Form1_Load(object sender, EventArgs e){ym.LoadWeights(Application.StartupPath+ "\\weights\\yolov8n-seg.onnx", Application.StartupPath + "\\weights\\labels.txt");}private void btn_video_Click(object sender, EventArgs e){var detector = new Yolov8SegManager();detector.LoadWeights(Application.StartupPath + "\\weights\\yolov8n-seg.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(frame,result);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();}}
}
【訓練數據集介紹】
注意數據集中有增強圖片
數據集格式:labelme格式(不包含mask文件,僅僅包含jpg圖片和對應的json文件)
圖片數量(jpg文件個數):9339
標注數量(json文件個數):9339
標注類別數:1
標注類別名稱:["Nail"]
每個類別標注的框數:
Nail count = 38632
使用標注工具:labelme=5.5.0
所在倉庫:firc-dataset
圖片分辨率:640x640
標注規則:對類別進行畫多邊形框polygon
重要說明:可以將數據集用labelme打開編輯,json數據集需自己轉成mask或者yolo格式或者coco格式作語義分割或者實例分割
特別聲明:本數據集不對訓練的模型或者權重文件精度作任何保證
圖片預覽:
標注例子:
【提供文件】
C#源碼+所有DLL文件
yolov8-seg.onnx模型文件(注意不提供pytorch模型)
測試圖片若干
不包含訓練的數據集
【源碼地址】
https://download.csdn.net/download/FL1623863129/89848653