C# PaddleDetection yolo實現(xiàn)印章檢測
更新時間:2023年11月10日 09:11:35 作者:天天代碼碼天天
這篇文章主要為大家詳細介紹了C#如何結(jié)合PaddleDetection yolo實現(xiàn)印章檢測,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(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)印章檢測的詳細內(nèi)容,更多關(guān)于C#印章檢測的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#監(jiān)測IPv4v6網(wǎng)速及流量的實例代碼
這篇文章主要介紹了C#監(jiān)測IPv4v6網(wǎng)速及流量的實例代碼,文中講解非常細致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
基于動態(tài)修改App.Config與web.Config的使用詳解
本篇文章是對動態(tài)修改App.Config與web.Config的使用進行了詳細的分析介紹,需要的朋友參考下2013-05-05
Unity Shader實現(xiàn)素描風(fēng)格的渲染
這篇文章主要為大家詳細介紹了Unity Shader實現(xiàn)素描風(fēng)格的渲染,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-04-04
C#編程自學(xué)之?dāng)?shù)據(jù)類型和變量二
這篇文章繼續(xù)介紹了C#數(shù)據(jù)類型和變量,是對上一篇文章的補充,希望對大家的學(xué)習(xí)有所幫助。2015-10-10
C#中的IEnumerable簡介及簡單實現(xiàn)實例
這篇文章主要介紹了C#中的IEnumerable簡介及簡單實現(xiàn)實例,本文講解了IEnumerable一些知識并給出了一個簡單的實現(xiàn),需要的朋友可以參考下2015-03-03
將字符串轉(zhuǎn)換成System.Drawing.Color類型的方法
將字符串轉(zhuǎn)換成System.Drawing.Color類型的方法,需要的朋友可以參考一下2013-04-04

