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

相关推荐
迪菲赫尔曼7 小时前
大模型入门实战 | 基于 YOLO 数据集微调 Qwen2.5-VL-3B-Instruct 的目标检测任务
人工智能·yolo·目标检测·大模型·微调·新手入门·qwen2.5
钓了猫的鱼儿18 小时前
无人机航拍数据集|第32期 无人机采矿区作业目标检测YOLO数据集202张yolov11/yolov8/yolov5可训练
yolo·目标检测·无人机·猫脸码客·无人机航拍数据集·无人机采矿区作业
钓了猫的鱼儿1 天前
无人机航拍数据集|第20期 无人机公路损伤目标检测YOLO数据集3771张yolov11/yolov8/yolov5可训练
yolo·目标检测·无人机·猫脸码客·无人机航拍数据集·无人机公路损伤目标检测数据集
钓了猫的鱼儿1 天前
无人机航拍数据集|第27期 无人机交通目标检测YOLO数据集3717张yolov11/yolov8/yolov5可训练
人工智能·yolo·目标检测
A7bert7771 天前
【YOLOv5部署至RK3588】模型训练→转换RKNN→开发板部署
c++·人工智能·python·深度学习·yolo·目标检测·机器学习
Coovally AI模型快速验证1 天前
YOLOv8-SMOT:基于切片辅助训练与自适应运动关联的无人机视角小目标实时追踪框架
人工智能·深度学习·yolo·计算机视觉·目标跟踪·无人机
是Dream呀1 天前
YOLOv7:重新定义实时目标检测的技术突破
yolo·目标检测·目标跟踪
钓了猫的鱼儿2 天前
无人机航拍数据集|第29期 无人机水稻稻穗目标检测YOLO数据集7894张yolov11/yolov8/yolov5可训练
yolo·目标检测·无人机·猫脸码客·无人机航拍数据集·无人机水稻稻穗目标检测
钓了猫的鱼儿2 天前
无人机航拍数据集|第22期 无人机城市交通目标检测YOLO数据集8624张yolov11/yolov8/yolov5可训练
yolo·目标检测·无人机·猫脸码客·无人机航拍数据集·无人机城市交通目标检测数据集
hixiong1232 天前
C# 编写一个XmlToDota的转换工具
开发语言·人工智能·yolo·c#