[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

相关推荐
码途行者3 小时前
每天10分钟学Go:第17课 接口interface-只规定“能做什么“,不管它是什么
开发语言·后端·golang
头发还在的女程序员3 小时前
Java充电桩平台源码解析:枪口状态、上报时间与页面刷新怎样协同
java·开发语言·充电桩系统·充电桩管理·充电系统·充电小程序
timeDifference₇5 小时前
Python Vibe Coding实操实验报告
开发语言·jvm·python
geovindu6 小时前
python:DecisionTree
开发语言·后端·python·算法
rockey6277 小时前
AScript正式推出Template模板引擎
c#
geovindu7 小时前
python: Decision Tree Regressor
开发语言·后端·python·算法·决策树
沐言Agent9 小时前
做工业上位机,这个 C# 开源框架把 PLC 通讯、流程控制和 MES 对接都备好了
c#·工业上位机
炸膛坦客11 小时前
单片机/C/C++八股:(三十七)指针数组 和 数组指针
c语言·开发语言·c++
夜不会漫长11 小时前
C++:C++11特性
开发语言·c++·算法
apcipot_rain12 小时前
C++转java日记(13)
java·开发语言