[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

相关推荐
dorabighead1 分钟前
JavaScript 高级程序设计 读书笔记(第三章)
开发语言·javascript·ecmascript
风与沙的较量丶41 分钟前
Java中的局部变量和成员变量在内存中的位置
java·开发语言
水煮庄周鱼鱼1 小时前
C# 入门简介
开发语言·c#
编程星空1 小时前
css主题色修改后会多出一个css吗?css怎么定义变量?
开发语言·后端·rust
软件黑马王子2 小时前
Unity游戏制作中的C#基础(6)方法和类的知识点深度剖析
开发语言·游戏·unity·c#
Logintern092 小时前
使用VS Code进行Python编程的一些快捷方式
开发语言·python
Multiple-ji2 小时前
想学python进来看看把
开发语言·python
一个小白12 小时前
C++——list模拟实现
开发语言·c++
bug总结2 小时前
新学一个JavaScript 的 classList API
开发语言·javascript·ecmascript
Nicole Potter2 小时前
请说明C#中的List是如何扩容的?
开发语言·面试·c#