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

相关推荐
筱筱木15 小时前
从标注优化到全流程落地:Python+YOLOv8 打造 YOLO模型训练 一体化平台
yolo
AI街潜水的八角17 小时前
基于YOLO26电池顶盖焊接缺陷检测系统1:电池顶盖焊接缺陷检测数据集说明(含下载链接)
人工智能·深度学习·yolo·目标跟踪
Ricky055318 小时前
搭载实时 FPGA 处理系统的航天器上用于海上监视的超分辨率YOLO目标检测技术(意大利2026年研究)
yolo·目标检测·fpga开发
YOLO数据集集合19 小时前
智慧农业|农田作物杂草识别数据集|航拍巡检|YOLO实例分割|深度学习训练集|智能除草视觉数据集
人工智能·深度学习·yolo·目标检测·无人机
星越华夏19 小时前
YOLO v11蚊子数据集训练
人工智能·python·深度学习·yolo
你是个什么橙20 小时前
缺陷检测数据集选择:NEU-DET、GC10-DET、MVTec_AD,将其转换成YOLO数据集适用的txt格式
yolo
前网易架构师-高司机21 小时前
带标注的交警识别数据集,可识别交警和非交警,5587张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·交警
Ricky055321 小时前
YOLO-FCE:一种基于特征与聚类增强的物种分类目标检测模型(澳大利亚2026年研究)
图像处理·人工智能·yolo·目标检测·分类
不懒不懒1 天前
基于 YOLOv10 的汽车机油滤芯缺陷检测系统(训练 + 测试 + 可视化 + 避坑)
yolo·汽车
视觉算法小姥1 天前
yolov11-obb在rk芯片部署的onnx模型输出的剪枝处理
算法·yolo·剪枝