[C#]使用OpenCvSharp实现区域文字提取

【官方框架地址】

github.com/shimat/opencvsharp

【算法介绍】

采用opencv算法实现文字区域提取,步骤如下:

(1)形态学操作

(2)查找轮廓

(3)筛选那些面积小的

(4)面积小的都筛选

(5)找到最小的矩形

【效果展示】

原图

提取结果:

【实现部分代码】

复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;

namespace FIRC
{
    public partial class Form1 : Form
    {
        Mat src = new Mat();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "图文件(*.*)|*.jpg;*.png;*.jpeg;*.bmp";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = false;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
              
                src = Cv2.ImRead(openFileDialog.FileName);
                pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(src);


            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(pictureBox1.Image==null)
            {
                return;
            }
          
            var resultMat =RegionManager.FindTextRegion(src);
            pictureBox2.Image= OpenCvSharp.Extensions.BitmapConverter.ToBitmap(resultMat); //Mat转Bitmap
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button3_Click(object sender, EventArgs e)
        {


        }
    }
}

【源码下载】

https://download.csdn.net/download/FL1623863129/88706018

【测试环境】

vs2019

netframework4.7.2

opencvsharp4.8.0

相关推荐
摇滚侠1 天前
搭建前端开发环境 安装 nodejs 设置淘宝镜像 最简化最标准版本 不使用 NVM NVM 高版本无法安装低版本 nodejs
java·开发语言·node.js
t198751281 天前
MATLAB十字路口车辆通行情况模拟系统
开发语言·matlab
weixin_408099671 天前
图片去水印 API 接口实战:网站如何实现自动去水印(Python / PHP / C#)
图像处理·人工智能·python·c#·php·api·图片去水印
yyk的萌1 天前
AI 应用开发工程师基础学习计划
开发语言·python·学习·ai·lua
Amumu121381 天前
Js:正则表达式(一)
开发语言·javascript·正则表达式
无人机9011 天前
Delphi 网络编程实战:TIdTCPClient 与 TIdTCPServer 类深度解析
java·开发语言·前端
froginwe111 天前
CSS 图像拼合技术
开发语言
计算机安禾1 天前
【数据结构与算法】第22篇:线索二叉树(Threaded Binary Tree)
c语言·开发语言·数据结构·学习·算法·链表·visual studio code
:mnong1 天前
Superpowers 项目设计分析
java·c语言·c++·python·c#·php·skills
我是唐青枫1 天前
C#.NET 分布式事务 深入解析:TCC、Saga、Outbox 与落地取舍
分布式·c#·.net