C# PaddleDetection yolo實現(xiàn)印章檢測
更新時間:2023年11月10日 09:11:35 作者:天天代碼碼天天
這篇文章主要為大家詳細(xì)介紹了C#如何結(jié)合PaddleDetection yolo實現(xiàn)印章檢測,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
效果
項目
代碼
using OpenCvSharp; using OpenCvSharp.Extensions; using Sdcb.PaddleDetection; using Sdcb.PaddleInference; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace PaddleDetection印章檢測 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Bitmap bmp; string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png"; string img = ""; double fontScale = 4D; int thickness = 4; LineTypes lineType = LineTypes.Link4; PaddleConfig paddleConfig; PaddleDetector d; String startupPath; float confidence = 0.90f; DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; StringBuilder sb = new StringBuilder(); private void Form1_Load(object sender, EventArgs e) { startupPath = Application.StartupPath; paddleConfig = PaddleConfig.FromModelDir(startupPath + "\\model\\"); string configYmlPath = startupPath + "\\model\\infer_cfg.yml"; d = new PaddleDetector(paddleConfig, configYmlPath, PaddleDevice.Mkldnn()); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = fileFilter; if (ofd.ShowDialog() != DialogResult.OK) return; pictureBox1.Image = null; img = ofd.FileName; bmp = new Bitmap(img); pictureBox1.Image = new Bitmap(img); textBox1.Text = ""; } private void button2_Click(object sender, EventArgs e) { if (img == "") { return; } sb.Clear(); Mat src = Cv2.ImRead(img); dt1 = DateTime.Now; DetectionResult[] r = d.Run(src); dt2 = DateTime.Now; Scalar scalar; for (int i = 0; i < r.Length; i++) { if (r[i].Confidence > confidence) { scalar = Scalar.RandomColor(); Cv2.Rectangle(src, r[i].Rect, scalar, 4, LineTypes.Link8, 0); Cv2.PutText(src, r[i].LabelName + "(" + r[i].Confidence + ")", new OpenCvSharp.Point(r[i].Rect.X + r[i].Rect.Width / 2, r[i].Rect.Y + r[i].Rect.Height / 2), HersheyFonts.HersheyComplex, fontScale, scalar, thickness, lineType, false); sb.AppendLine(string.Format("{0}({1}) ({2},{3},{4},{5})", r[i].LabelName , r[i].Confidence , r[i].Rect.Left , r[i].Rect.Top , r[i].Rect.Right , r[i].Rect.Bottom )); } } sb.AppendLine("耗時:" + (dt2 - dt1).TotalMilliseconds + "ms"); textBox1.Text = sb.ToString(); pictureBox2.Image = BitmapConverter.ToBitmap(src); } } }
以上就是C# PaddleDetection yolo實現(xiàn)印章檢測的詳細(xì)內(nèi)容,更多關(guān)于C#印章檢測的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
c#判斷數(shù)據(jù)庫服務(wù)器是否已經(jīng)啟動的方法
這篇文章主要介紹了使用c#判斷數(shù)據(jù)庫服務(wù)器是否已經(jīng)啟動的方法,大家參考使用吧2014-01-01C#實現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法
這篇文章主要介紹了C#實現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法,涉及C#創(chuàng)建縮略圖的相關(guān)圖片操作技巧,需要的朋友可以參考下2015-06-06測試框架nunit之a(chǎn)ssertion斷言使用詳解
NUnit是.Net平臺的測試框架,廣泛用于.Net平臺的單元測試和回歸測試中,下面我們用示例詳細(xì)學(xué)習(xí)一下他的使用方法2014-01-01