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

相关推荐
Wah-Aug3 小时前
YOLOv5口罩检测
yolo
深度学习lover6 小时前
<项目代码>yolo织物缺陷识别<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·织物缺陷识别·项目代码
、、、、南山小雨、、、、7 小时前
加载YOLO模型,处理mp4视频
python·yolo·音视频
令狐掌门9 小时前
PySide6集成yolo v8实现图片人物检测、视频人物检测以及摄像头人物检测
yolo·pyside6 yolo
Ponp_13 小时前
Ubuntu 22.04 + ROS 2 Humble实现YOLOV5目标检测实时流传输(Jetson NX与远程PC通信)
linux·运维·yolo
深度学习lover21 小时前
<数据集>yolo螺丝螺母识别数据集<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·螺丝螺母识别
熊猫_豆豆1 天前
YOLO python 实现多种物体识别(时钟,水杯,小熊,路人,车辆)
人工智能·yolo·物品识别
学技术的大胜嗷2 天前
如何裁剪YOLOv8m的大目标检测头并验证其结构
深度学习·yolo·目标检测·计算机视觉
城南皮卡丘2 天前
【源码+数据集+训练教程】基于YOLOv8+Flask+Layui的智能垃圾分类检测系统
yolo·flask·layui·垃圾分类
Sunhen_Qiletian2 天前
高性能人工智能目标检测开山篇----YOLO v1算法详解(上篇)
人工智能·深度学习·yolo·目标检测·计算机视觉·目标跟踪