C# PaddleDetection yolo 印章检测

效果

项目

代码

复制代码
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);
        }
    }
}

下载

Demo下载

相关推荐
海思开发板总店4 小时前
Hi3516CV610 YOLO部署教程 源码虚拟机文档 YOLOv8 等 模型转换 模型部署
yolo
IMA小队长6 小时前
Linux下Mamba-YOLO复现
linux·运维·yolo
Coding茶水间6 小时前
基于深度学习的肾结石检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·深度学习·yolo·目标检测·机器学习·计算机视觉
前网易架构师-高司机7 小时前
带标注信息的钉子识别数据集,99.4%识别率,近六千章图片,支持yolo,coco json, pascal voc xml格式的标注数据集
yolo
A7bert7778 小时前
【YOLOv5seg部署RK3588】模型训练→转换RKNN→开发板部署
linux·c++·人工智能·深度学习·yolo·目标检测
智驱力人工智能10 小时前
加油站静电夹检测 视觉分析技术的安全赋能与实践 静电夹检测 加油站静电夹状态监测 静电接地报警器检测
人工智能·深度学习·算法·安全·yolo·边缘计算
不想起名字呢13 小时前
Yolov5 RKNN 后处理拆分-知其然知其所以然
yolo·rknn
FL162386312914 小时前
[C#][winform]基于yolov11的水下目标检测系统C#源码+onnx模型+评估指标曲线+精美GUI界面
人工智能·yolo·目标检测
Dingdangcat8614 小时前
篮球场景目标检测与识别实时定位与分类YoloV8分割改进AIFI原创
yolo·目标检测·分类
牙牙要健康14 小时前
【YOLOv8-Ultralytics】 【目标检测】【v8.3.235版本】 模型专用预测器代码predict.py解析
yolo·目标检测·目标跟踪