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下载

相关推荐
宿州派大星43 分钟前
目标检测:YOLOv1架构原理与损失函数全解析
人工智能·yolo·目标检测
神仙别闹2 小时前
基于Python Yolo实现绝缘子目标检测程序
python·yolo·目标检测
微尘hjx17 小时前
【AI视觉软件 03】基于 Ultralytics + DeepSORT 的多目标跟踪与改进(支持YOLO全系列,重点车跟踪)
人工智能·yolo·目标跟踪·视觉检测·deepsort·ultralytics·车跟踪
迪菲赫尔曼19 小时前
【基础篇 04】第一次使用终端:命令在哪里输入,电脑现在又“站”在哪里?
python·yolo·目标检测
qq_25294131681 天前
混凝土损伤分割与检测数据集 | 混凝土损伤 实例分割 裂缝检测 裸露钢筋 结构健康监测9261期
人工智能·yolo·目标检测·计算机视觉·混泥土
a puppy slide 葱1 天前
ICML | 2026 | MFH‑NAS:面向多模态融合目标检测的混合神经架构搜索框架
人工智能·yolo·目标检测·计算机视觉·架构·nas·神经网络架构搜索
2601_967987372 天前
用Python+OpenCV+YOLO写个游戏脚本:从自动瞄准到自动采集的保姆级教程
python·opencv·yolo·目标检测·游戏自动化
迪菲赫尔曼2 天前
【基础篇 02】文件、文件夹和路径:先把学习资料放对地方
yolo·计算机视觉·论文·教程·ultralyt
小豆庄2 天前
AI换脸能骗过检测,视频脱敏为什么该回到本地
人工智能·yolo·阿里云·ai·ocr·视频
小毕超2 天前
从推理到训练:Intel Ultra 核显 GPU 加速 YOLO 模型训练
pytorch·yolo·gpu·intel