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

相关推荐
冬夜戏雪8 分钟前
agent的trace 和eval
开发语言·前端·javascript
Sagittarius_A*12 分钟前
Burst Lab | PHP 审计 13|反序列化(三):POP 链构造与 Gadget Chain 分析
开发语言·web安全·php·代码审计·反序列化
职场的momo33 分钟前
11个后端与AI岗位同时开放:Java、网关、推理优化怎么匹配
java·开发语言·人工智能
蓝速科技38 分钟前
蓝速科技丨新旧楼宇混杂场景下会议室预约门牌屏一体化改造方案
开发语言·科技·php
梦想的旅途21 小时前
Python实现企业微信文本消息发送
开发语言·python·企业微信
大鹏说大话2 小时前
美业微信会员系统哪个好
开发语言
半亩码田2 小时前
C#转Python第3.6篇:Python 的 @property 比 C# 的 get/set 更灵活
java·python·c#
程序员与背包客_CoderZ3 小时前
高性能分布式KV存储引擎RocksDB入门与C/C++编码实战
c语言·开发语言·数据库·c++·分布式·分布式数据库·rocksdb
钱栈up3 小时前
Mac 开发机一键发版不用切环境:我这样改造了团队的后端部署脚本Maven编译卡住20分钟?我靠两步定位到2处隐蔽编译错误
开发语言·python·macos
william_yangshun3 小时前
【大模型部署实战】kimi-k3-in-c 中文版:用 176KB 纯 C99 引擎在 CPU 上跑 Kimi K3 上手指南
c语言·开发语言