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

相关推荐
徐同保2 分钟前
tailwindcss暗色主题切换
开发语言·前端·javascript
蓝纹绿茶29 分钟前
bash:**:pip:***python: 错误的解释器: 没有那个文件或目录
开发语言·python·pip
云知谷36 分钟前
【经典书籍】C++ Primer 第15章类虚函数与多态 “友元、异常和其他高级特性” 精华讲解
c语言·开发语言·c++·软件工程·团队开发
START_GAME1 小时前
深度学习Diffusers:用 DiffusionPipeline 实现图像生成
开发语言·python·深度学习
不爱编程的小九九2 小时前
小九源码-springboot088-宾馆客房管理系统
java·开发语言·spring boot
李趣趣2 小时前
数据库字段类型bit容易被忽视的bug
c#·bug
Evand J2 小时前
【MATLAB例程】到达角度定位(AOA),平面环境多锚点定位(自适应基站数量),动态轨迹使用EKF滤波优化。附代码下载链接
开发语言·matlab·平面·滤波·aoa·到达角度
细节控菜鸡2 小时前
【2025最新】ArcGIS for JS 实现随着时间变化而变化的热力图
开发语言·javascript·arcgis
Pluto_CSND3 小时前
Java实现gRPC双向流通信
java·开发语言·单元测试
虚行3 小时前
C#OPC客户端通信实操
c#