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

相关推荐
红色的山茶花10 小时前
YOLOv7-0.1部分代码阅读笔记-general.py
笔记·yolo
源代码•宸11 小时前
完美解决 no model scale passed. assuming scale=‘n‘ 的YOLO问题
经验分享·yolo
lanboAI13 小时前
基于yolov5的番茄成熟度检测系统,支持图像、视频和摄像实时检测【pytorch框架、python源码】
python·yolo·智能手机
goomind14 小时前
YOLOv11实战宠物狗分类
人工智能·yolo·机器学习·计算机视觉·分类·聚类
aabbcccddd0116 小时前
yolov8目标检测如何设置背景/无标签图像参与训练
人工智能·yolo·目标检测·ultralytics
啊文师兄17 小时前
使用 Pytorch 搭建视频车流量检测资源(基于YOLO)
人工智能·pytorch·yolo
牙牙要健康1 天前
【目标检测】【Ultralytics-YOLO系列】Windows11下YOLOV5人脸目标检测
人工智能·yolo·目标检测
Python图像识别-11 天前
基于yolov8、yolov5的番茄成熟度检测识别系统(含UI界面、训练好的模型、Python代码、数据集)
python·yolo·ui
双木的木1 天前
集智书童 | YOLOv8架构的改进:POLO 模型在多类目标检测中的突破 !
人工智能·python·深度学习·yolo·目标检测·机器学习·计算机视觉
985小水博一枚呀2 天前
【深度学习目标检测|YOLO算法4-4】YOLO家族进化史:从YOLOv1到YOLOv11的架构创新、性能优化与行业应用全解析——工业领域
网络·人工智能·深度学习·算法·yolo·目标检测·架构