csharp:Optical Character Recognition
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using MODI;//Microsoft Office Document Imaging
// 首先用office安装盘这个组件,默认安装office的时候是不会安装的,只要添加这个组件功能就好了安装说明:http://support.microsoft.com/kb/982760
//组件Microsoft Office Document Imaging 12.0 Type Library(office2007)
//或者Microsoft Office Document Imaging 11.0 Type Library(office2003)
//中文简体OCR引擎 http://www.microsoft.com/downloads/thankyou.aspx?familyId=dd172063-9517-41d8-82af-29c38f7437b6&displayLang=zh-hk namespace ToText
{
/// <summary>
/// Optical Character Recognition光学字符识别
/// 20140507 Geovin Du
/// 涂聚文
/// </summary>
public static class OCRGetstring
{
/// <summary>
/// 语言类型
/// </summary>
/// <returns></returns>
public static DataTable getLanguageList()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID",typeof(int));
dt.Columns.Add("LanguageName", typeof(string));
dt.Columns.Add("LanguageLCID", typeof(string));
//dt.Rows.Add(1, "", 1);
dt.Rows.Add(1,"简体中文", "2052");
dt.Rows.Add(2,"繁体中文", "1028");
dt.Rows.Add(3,"英语", "9");
dt.Rows.Add(4,"捷克语", "5");
dt.Rows.Add(5,"丹麦语", "6");
dt.Rows.Add(6,"德语", "7");
dt.Rows.Add(7,"希腊语", "8");
dt.Rows.Add(8,"西班牙语", "10");
dt.Rows.Add(9,"芬兰语", "11");
dt.Rows.Add(10,"法语", "12");
dt.Rows.Add(11, "匈牙利语", "14");
dt.Rows.Add(12, "意大利语", "16");
dt.Rows.Add(13, "日语", "17");
dt.Rows.Add(14, "韩语", "18");
dt.Rows.Add(15, "荷兰语", "19");
dt.Rows.Add(16, "挪威语", "20");
dt.Rows.Add(17, "波兰语", "21");
dt.Rows.Add(18, "葡萄牙语", "22");
dt.Rows.Add(19, "俄语", "25");
dt.Rows.Add(20,"瑞典语", "29");
dt.Rows.Add(21,"土耳其语", "31");
return dt;
} /// <summary>
///
/// </summary>
/// <param name="sValue"></param>
/// <returns></returns>
private static MODI.MiLANGUAGES GetLanuageType(string sValue)
{
switch (sValue)
{
case "2052":
return MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED;
case "5":
return MODI.MiLANGUAGES.miLANG_CZECH;
case "6":
return MODI.MiLANGUAGES.miLANG_DANISH;
case "7":
return MODI.MiLANGUAGES.miLANG_GERMAN;
case "8":
return MODI.MiLANGUAGES.miLANG_GREEK;
case "9":
return MODI.MiLANGUAGES.miLANG_ENGLISH;
case "10":
return MODI.MiLANGUAGES.miLANG_SPANISH;
case "11":
return MODI.MiLANGUAGES.miLANG_FINNISH;
case "12":
return MODI.MiLANGUAGES.miLANG_FRENCH;
case "14":
return MODI.MiLANGUAGES.miLANG_HUNGARIAN;
case "16":
return MODI.MiLANGUAGES.miLANG_ITALIAN;
case "17":
return MODI.MiLANGUAGES.miLANG_JAPANESE;
case "18":
return MODI.MiLANGUAGES.miLANG_KOREAN;
case "19":
return MODI.MiLANGUAGES.miLANG_DUTCH;
case "20":
return MODI.MiLANGUAGES.miLANG_NORWEGIAN;
case "21":
return MODI.MiLANGUAGES.miLANG_POLISH;
case "22":
return MODI.MiLANGUAGES.miLANG_PORTUGUESE;
case "25":
return MODI.MiLANGUAGES.miLANG_RUSSIAN;
case "29":
return MODI.MiLANGUAGES.miLANG_SWEDISH;
case "31":
return MODI.MiLANGUAGES.miLANG_TURKISH;
case "1028":
return MODI.MiLANGUAGES.miLANG_CHINESE_TRADITIONAL;
default:
return MODI.MiLANGUAGES.miLANG_ENGLISH;
}
} /// <summary>
/// Images轉換文字
/// </summary>
/// <param name="image">Image</param>
/// <param name="language">语言类型</param>
/// <returns></returns>
public static string ExtractText(this System.Drawing.Image image,string language)
{
var tmpFile = Path.GetTempFileName();
StringBuilder sb = new StringBuilder();
//string text;
try
{
var bmp = new Bitmap(Math.Max(image.Width, 1024), Math.Max(image.Height, 768));
var gfxResize = Graphics.FromImage(bmp);
gfxResize.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height));
bmp.Save(tmpFile + ".bmp", ImageFormat.Bmp);
var doc = new MODI.Document();
doc.Create(tmpFile + ".bmp");
// doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
doc.OCR(GetLanuageType(language), true, true); // 识别文字类型
var img = (MODI.Image)doc.Images[0];
var layout = img.Layout;
sb.Append(layout.Text);
//text = sb.ToString();// layout.Text;
}
finally
{
File.Delete(tmpFile);
File.Delete(tmpFile + ".bmp");
} return sb.ToString();// text;
}
/// <summary>
/// 来源图片文件轉換文字
/// </summary>
/// <param name="fileToOCR">file文件</param>
/// <param name="language">语言类型</param>
/// <returns></returns>
public static string getFileToOCR(string fileToOCR, string language)
{
StringBuilder sb = new StringBuilder();
if (File.Exists(fileToOCR))
{ MODI.Document md = new MODI.Document();
md.Create(fileToOCR);
md.OCR(GetLanuageType(language), true, true);
MODI.Image img;
MODI.Layout layout;
for (int i = 0; i < md.Images.Count; i++)
{
img = (MODI.Image)md.Images[i];
layout = img.Layout;
sb.Append(layout.Text);
} md.Close(false); }
else
{
sb.Append("");
}
return sb.ToString();
}
}
}
csharp:Optical Character Recognition的更多相关文章
- OCR (Optical Character Recognition,光学字符识别)
OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗.亮的模式确定其形状,然后用字符识别方法将形状翻译 ...
- 图片OCR(Optical Character Recognition)
目录 Photo OCR问题描述 滑动窗口(Sliding Windows) 获得大量数据和人工数据(Getting Logs of Data and Artificial Data) 瓶颈分析:需要 ...
- OCR(Optical Character Recognition)算法总结
https://zhuanlan.zhihu.com/p/84815144 最全OCR资料汇总,awesome-OCR
- 第 38 章 OCR - Optical Character Recognition
38.1. Tesseract 查找Tesseract安装包 $ apt-cache search Tesseract ocrodjvu - tool to perform OCR on DjVu d ...
- USACO 5.4 Character Recognition
Character Recognition This problem requires you to write a program that performs character recogniti ...
- USACO 5.4 Character Recognition(DP)
非常恶心的一题,卡了三个月,没什么动力做了,代码直接抄的别人的... 这题主要思路就是预处理出几个数组,再预处理出几个数组,最后DP,输出一下路径... 写起来挺非常麻烦,代码不贴了,丢人... 把U ...
- Go 语言相关的优秀框架,库及软件列表
If you see a package or project here that is no longer maintained or is not a good fit, please submi ...
- OCR 即 光学字符识别
OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗.亮的模式确定其形状,然后用字符识别方法将形状翻译 ...
- Code Project精彩系列(转)
Code Project精彩系列(转) Code Project精彩系列(转) Applications Crafting a C# forms Editor From scratch htt ...
随机推荐
- Corn表达式
CronTrigger CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTr ...
- 9012年,我终于找到了Pypi稳定的源....
前情提要 近日听说华为也做了一个华为开源镜像站所以去体验了一波然后此处做个总结吧. 既然是体验当然是从直观的第一感觉UI开始说起. 界面体验 一点进去挺好的界面很清爽. 最难能可贵的是终于没有再使用列 ...
- Machine learning吴恩达第三周 Logistic Regression
1. Sigmoid function function g = sigmoid(z) %SIGMOID Compute sigmoid function % g = SIGMOID(z) compu ...
- 关闭tensorflow运行时的警告信息
执行简单的矩阵相乘的程序: import tensorflow as tf m1 = tf.constant([[3,3]]) m2 = tf.constant([[2],[3]]) product ...
- [BZOJ 4857][Jsoi2016]反质数序列
传送门 $ \color{green} {solution : } $ 因为 $ 1 $ 的个数我们最多只能选一个,所以剩下的数如果组成素数那么只有一奇一偶,显然是个二分图模型 #include &l ...
- [转] Centos 系统swap虚拟内存添加与删除配置
[From]https://blog.csdn.net/lengyue1084/article/details/51405640 [From]https://yuukis.cn/24/ SWAP是Li ...
- Ubuntu定时任务设置
设置很简单,但如果误入歧途,会耽误很多时间 步骤如下: 1. 以root执行:vi /etc/crontab 2. 在文件最后添加cron配置(每天凌晨四点执行,并将日志输出到/data/cron.l ...
- mssqlServer大量数据快速插入:SqlBulkCopy
SqlBulkCopy类,为微软的一个大量数据快速插入.直接上代码 表结构: namespace SqlBulkCopy的演示 { using System.Data.SqlClient; publi ...
- php 图片上传 并返回上传文件位置 支持多文件上传
<?php /** * Created by PhpStorm. * User: DY040 * Date: 2018/4/26 * Time: 13:23 */ echo '<pre&g ...
- kafka的安装及基本使用
1.安装zookeeper # 解压缩 [root@localhost zookeeper]# .tar.gz [root@localhost zookeeper]# zk_simple # 复制zo ...