当前位置:首页 > Windows程序 > 正文

c#图文识别

2024-03-31 Windows程序

我主要是用于识别视频上的文字,只是图文识另外技术还不够成熟,识别起来对照困难,有些简单的页面可以识别。

技术分享图片

技术分享图片

本文介绍两种对照主流和成熟的识别方法:

方法一、Asprise-OCR实现。

方法二、Microsoft Office Document Imaging(Office 2007) 组件实现。

方法一、Asprise-OCR的使用。

Asprise-OCR下载地点:

?lang=csharp 

此中需要使用的3个dll是AspriseOCR.dll、DevIL.dll、ILU.dll。

需要注意的是这几个.dll是vc写的引用要在措施顶用DllImport引用,,关键代码:

[DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]

public static extern IntPtr OCR(string file, int type);

[DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]

static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);

[DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]

static extern IntPtr OCRBarCodes(string file, int type);

[DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]

static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);

挪用代码很简单只有一句:

MessageBox.Show(Marshal.PtrToStringAnsi(OCRpart(img_path, -1, startX, startY, width, height)));

此中img_path:为图片路径,startX、startY坐标均为0即可,width、height图片的宽和高。

方法二、Microsoft Office Document Imaging(Office 2007) 组件实现。

在使用之前需要给大家说的是Imaging 组件的兼容性不是很好,使用win 7 office 2007的时必需打上office 2007 sp1或者sp2补丁,读取中文才行。 

sp1补丁地点(226M) :

sp2补丁地点(301 MB):

 

给项目添加组件引用,如图:

技术分享图片

使用代码:

MODI.Document doc = new MODI.Document();

doc.Create(img_Path);

MODI.Image image;

MODI.Layout layout;

doc.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true);  // 识别简体中文

for (int i = 0; i < doc.Images.Count; i++)

{

image = (MODI.Image)doc.Images[i];

layout = image.Layout;

sb.Append(layout.Text);

}

MessageBox.Show(sb.ToString());

此中img_Path为图片路径,MODI.MiLANGUAGES为读取图片的文字类型枚举。

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/35409.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494590访问次数
  • 建站天数
  • 友情链接