资源简介
基于OpenCVsharp的C#程序用于提取文字区域
代码片段和文件信息
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OpenCVSharpDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string fileName;
Mat mat;
private void Form1_Load(object sender EventArgs e)
{
fileName = @Application.StartupPath + @“\test.png“;
mat = new Mat(fileName);
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Image = mat.ToBitmap();
}
public void findTextRegion(Mat dilation)
{
// 1. 查找轮廓
OpenCvSharp.Point[][] contours;
HierarchyIndex[] hierarchly;
Rect biggestContourRect = new Rect();
Cv2.FindContours(dilation out contours out hierarchly RetrievalModes.Tree ContourApproximationModes.ApproxSimple);
// 2. 筛选那些面积小的
int i = 0;
foreach (OpenCvSharp.Point[] contour in contours)
{
double area = Cv2.ContourArea(contour);
//面积小的都筛选掉
if (area < 1000)
{
continue;
}
//轮廓近似,作用很小
double epsilon = 0.001 * Cv2.ArcLength(contour true);
//找到最小的矩形
biggestContourRect = Cv2.BoundingRect(contour);
if (biggestContourRect.Height > (biggestContourRect.Width * 1.2))
{
continue;
}
//画线
mat.Rectangle(biggestContourRectnew Scalar(0 255 0) 2);
}
pictureBox1.Image = mat.ToBitmap();
//Cv2.ImShow(“img“ mat);
}
public Mat preprocess(string imgPath)
{
Mat dilation2 = new Mat();
//读取灰度图
using (Mat src = new Mat(imgPath ImreadModes.Grayscale))
{
//1.Sobel算子,x方向求梯度
Mat sobel = new Mat();
Cv2.Sobel(src sobel MatType.CV_8U 1 0 3);
//2.二值化
Mat binary = new Mat();
Cv2.Threshold(sobel binary 0 255 ThresholdTypes.Otsu | ThresholdTypes.Binary);
//3. 膨胀和腐蚀操作的核函数
Mat element1 = new Mat();
Mat element2 = new Mat();
OpenCvSharp.Size size1 = new OpenCvSharp.Size(30 9);
OpenCvSharp.Size size2 = new OpenCvSharp.Size(24 6);
element1 = Cv2.GetStructuringElement(MorphShapes.Rect size1);
element2 = Cv2.GetStructuringElement(MorphShapes.Rect size2);
//4. 膨胀一次,让轮廓突出
Mat dilation = new Mat();
Cv2.Dilate(binary dilation element2);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\
文件 10 2020-04-26 06:48 OpenCVSharpDemo-master\.gitignore
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\
文件 90112 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\.suo
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\Server\
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\Server\sqlite3\
文件 0 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\Server\sqlite3\db.lock
文件 622592 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\Server\sqlite3\storage.ide
文件 32768 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\Server\sqlite3\storage.ide-shm
文件 197792 2020-04-26 06:48 OpenCVSharpDemo-master\.vs\OpenCVSharpDemo\v16\Server\sqlite3\storage.ide-wal
文件 1126 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo.sln
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\
文件 10 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\.gitignore
文件 3324 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Form1.Designer.cs
文件 3702 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Form1.cs
文件 5698 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Form1.resx
文件 5421 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\OpenCVSharpDemo.csproj
文件 475 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Program.cs
目录 0 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Properties\
文件 1286 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Properties\AssemblyInfo.cs
文件 2772 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Properties\Resources.Designer.cs
文件 5496 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Properties\Resources.resx
文件 1072 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Properties\Settings.Designer.cs
文件 242 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\Properties\Settings.settings
文件 152 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\packages.config
文件 79127 2020-04-26 06:48 OpenCVSharpDemo-master\OpenCVSharpDemo\test.png
文件 71 2020-04-26 06:48 OpenCVSharpDemo-master\README.md
相关资源
- OPCUA:C#使用OpcUaHelper开源库开发客M
- opencvsharp检测圆
- Openvc 动态人脸识别对比学习
- 倍福CNC 界面
- 异步TASK Async和await使用
- C# 斑马手持终端WINCE开发 MC32N0 vs2008
- 本机多进程相互访问Pipe
- C# 朗读文本文字(SpeechSynthesizer)
- CSharp language specification 5.0中文(C# 语
-
C# 开发BHO(Browser Helper ob
ject)插件 - C#游戏辅助helper类[内存多级指针读写
- XenCenter开发
- C#Twincat3读写程序
- 自定义UpDownControl
- SuperPuTTY-1.4.0.8.zip
- BouncyCastle C#源码
- c#使用openoffice组件操作文件
- C# 监测服务器使用情况CPU、内存、硬
-
cef_binary_32_64双版包和pepflashpla
yer. - C#实现将WPF字体呈现到OpenGL 支持汉字
- C#实现封装SPC过程能力工具类ProcessC
- C#照片识别人脸截取成身份证比例的证
- C# WM wince UI集合版7 IN 1
- asp.net上机实验mypetshop源码
- 高清彩版 ASP.NET Core 2 High Performance(
- 基于C#和OpenTK的3D坐标系演示
- C# 7.0 in a Nutshell The Definitive Reference 无
- C#使用pem格式的密钥对文件来做RSA加解
- C#设计模式 (美)James W.Cooper著 中文
-
Hands-On Typesc
ript for C# and .NET Core De
评论
共有 条评论