C# PaddleDetection yolo實(shí)現(xiàn)印章檢測(cè)
效果




項(xiàng)目

代碼
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印章檢測(cè)
{
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("耗時(shí):" + (dt2 - dt1).TotalMilliseconds + "ms");
textBox1.Text = sb.ToString();
pictureBox2.Image = BitmapConverter.ToBitmap(src);
}
}
}以上就是C# PaddleDetection yolo實(shí)現(xiàn)印章檢測(cè)的詳細(xì)內(nèi)容,更多關(guān)于C#印章檢測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#中高精度計(jì)時(shí)器Stopwatch的用法詳解
偶然發(fā)現(xiàn)C# 的計(jì)時(shí)器類Stopwatch,他特別適合測(cè)量運(yùn)行時(shí)間,使用簡(jiǎn)單、計(jì)時(shí)精確,下面就跟隨小編一起來(lái)學(xué)習(xí)一下它的具體應(yīng)用吧2024-11-11
C#監(jiān)測(cè)IPv4v6網(wǎng)速及流量的實(shí)例代碼
這篇文章主要介紹了C#監(jiān)測(cè)IPv4v6網(wǎng)速及流量的實(shí)例代碼,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
基于動(dòng)態(tài)修改App.Config與web.Config的使用詳解
本篇文章是對(duì)動(dòng)態(tài)修改App.Config與web.Config的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Unity Shader實(shí)現(xiàn)素描風(fēng)格的渲染
這篇文章主要為大家詳細(xì)介紹了Unity Shader實(shí)現(xiàn)素描風(fēng)格的渲染,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-04-04
C#編程自學(xué)之?dāng)?shù)據(jù)類型和變量二
這篇文章繼續(xù)介紹了C#數(shù)據(jù)類型和變量,是對(duì)上一篇文章的補(bǔ)充,希望對(duì)大家的學(xué)習(xí)有所幫助。2015-10-10
C#中的IEnumerable簡(jiǎn)介及簡(jiǎn)單實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了C#中的IEnumerable簡(jiǎn)介及簡(jiǎn)單實(shí)現(xiàn)實(shí)例,本文講解了IEnumerable一些知識(shí)并給出了一個(gè)簡(jiǎn)單的實(shí)現(xiàn),需要的朋友可以參考下2015-03-03
將字符串轉(zhuǎn)換成System.Drawing.Color類型的方法
將字符串轉(zhuǎn)換成System.Drawing.Color類型的方法,需要的朋友可以參考一下2013-04-04
C# wpf簡(jiǎn)單顏色板的實(shí)現(xiàn)
wpf本身沒(méi)有提供顏色板之類的控件,有些業(yè)務(wù)使用場(chǎng)景需要使用顏色板之類的控件,本文就簡(jiǎn)單實(shí)現(xiàn),感興趣的可以了解一下2021-10-10

