C# PaddleDetection 版面分析

效果

项目

代码

复制代码
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 = 2D;
        int thickness = 4;
        LineTypes lineType = LineTypes.Link4;

        PaddleConfig paddleConfig;
        PaddleDetector d;
        String startupPath;
        float confidence = 0.75f;
        DetectionResult[] r;
        Mat src;

        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);
            src = Cv2.ImRead(img);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            startupPath = System.Windows.Forms.Application.StartupPath;
            paddleConfig = PaddleConfig.FromModelDir(startupPath + "\\ppyolov2_r50vd_dcn_365e_publaynet\\");
            string configYmlPath = startupPath + "\\ppyolov2_r50vd_dcn_365e_publaynet\\infer_cfg.yml";
            d = new PaddleDetector(paddleConfig, configYmlPath);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null)
            {
                return;
            }

            r = d.Run(src);
            for (int i = 0; i < r.Length; i++)
            {
                if (r[i].Confidence > confidence)
                {
                    Scalar scalar = Scalar.RandomColor();
                    Cv2.Rectangle(src, r[i].Rect, scalar, 1, LineTypes.Link8, 0);
                    Cv2.PutText(src, r[i].LabelName, 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);
                }
            }
            pictureBox2.Image = BitmapConverter.ToBitmap(src);
        }
    }
}

Demo下载

相关推荐
techdashen5 分钟前
在 Fly.io 上使用 Rust 构建远程开发环境:从 Tokio 到 eBPF
开发语言·后端·rust
留白_9 分钟前
pandas文件读取与存储
开发语言·python·pandas
夕除17 分钟前
AOP 实现 Redis 缓存切面解析
java·开发语言·python
feifeigo12324 分钟前
马尔可夫决策过程(MDP)MATLAB 实现
开发语言·matlab
攻城狮Soar33 分钟前
STL源码解析之list(1)
开发语言·c++
x***r15134 分钟前
Postman-win64-7.3.5-Setup安装配置教程(Windows 详细版)
开发语言·lua
林森lsjs34 分钟前
【日耕一题】4. 较为复杂情况下的求和
java·开发语言
2401_8697695938 分钟前
内容5 日期类实现
开发语言·c++
白露与泡影1 小时前
2026秋招冲刺:1000道Java高频面试题(各大厂考点汇总)
java·开发语言·面试
IT龟苓膏1 小时前
Java 并发基础:进程、线程、线程状态、synchronized、volatile 一篇讲清
java·开发语言·jvm