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

相关推荐
再一次等风来5 小时前
YOLO26 实测记录:从模型下载、预测验证到 ONNX Runtime 推理部署
yolo·计算机视觉·onnx·yolo26
动物园猫7 小时前
用于实验室智能识别的目标检测数据集分享(适用于YOLO系列深度学习分类检测任务)
深度学习·yolo·目标检测
jay神7 小时前
基于 YOLOv8 + CRNN 的车牌识别系统
深度学习·yolo·目标检测·计算机视觉·车牌识别
装不满的克莱因瓶7 小时前
掌握基于YOLO v5实现车牌目标检测任务的完整流程——从数据到部署的工业级实践
人工智能·python·深度学习·yolo·目标检测·计算机视觉·目标跟踪
stsdddd8 小时前
YOLO系列目标检测数据集大全【第二十八期】
yolo·目标检测·目标跟踪
bryant_meng1 天前
【YOLO-Master】When YOLO-Master Sees Ghosts
yolo·moe·yolo-master
前网易架构师-高司机1 天前
带标注的土豆马铃薯病叶数据集,识别6种病害和健康叶,识别率93.4%,3718张图,支持yolo,coco json,voc xml,文末有模型训练代码
yolo·数据集·病害·病叶·叶子·马铃薯·土豆
FL16238631292 天前
户外垃圾类型检测数据集VOC+YOLO格式4278张10类别
人工智能·yolo·机器学习
前网易架构师-高司机2 天前
带标注的番茄成熟颜色识别数据集,可识别红色,橙色,绿色,识别率80.6%,2517张图,支持yolo,coco json,voc xml,文末有模型训练代码
yolo·数据集·颜色·番茄·西红柿·成熟·红色
YOLO视觉与编程2 天前
jetson orin nano烧录jetpack7.2系统
人工智能·深度学习·yolo·目标检测·机器学习