利用OCR识别扫描的jpg、tif文件的文字
第一步:下载老马哥的从 office和sharepoint 提取出来的注册表和dll http://115.com/file/dpa4qrt2
或者直接安装office和sharepoint2007
第二步:下载我的demo http://files.cnblogs.com/0banana0/OCR.zip
***识别度不是百分之百的 当然需要校准啦 在 编辑器里边修改错误的东西 !
第三步:发布
本地环境无措 发布到iis包错 “Object hasn't been initialized and can't be used yet”
解决办法:Go to IIS->ApplicatioPools->Default Applicationpool->Identity->custom account->Give the user name and password.
****发布的时候 iis还报一个错:Compiler Error Message: CS0016拒绝访问
解决办法:给c:\windows\temp 加上 network service (只加这个我的不行)和 iis_iusrs(后来加上和这个才行)权限
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.IO;
using System.Text;
using ContractManage.DAL;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; namespace ContractManage.uploadify
{
/// <summary>
/// Summary description for OCR
/// </summary>
public class OCR : IHttpHandler
{
private MODI.Document _document;
private MODI.Images _images;
private MODI.Image _image;
private MODI.Layout _layout;
private ManualResetEvent _completedOCR = new ManualResetEvent(false);
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
if (!string.IsNullOrEmpty(context.Request.QueryString["cid"]))
{
string cid = context.Request.QueryString["cid"];
string sPath = context.Server.MapPath("uploadify");
string path = sPath.Substring(, sPath.Length - ) + "\\OCRFile\\" + cid;
CheckFileType(path, cid);
}
context.Response.Write(" ");
} public void CheckFileType(string directoryPath, string cid)
{
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
while (files.MoveNext())
{
//get file extension
string fileExtension = Path.GetExtension(Convert.ToString(files.Current)); //get file path without extenstion
string filePath = Convert.ToString(files.Current).Replace(fileExtension, string.Empty); //get fileName
string fileName = Path.GetFileName(Convert.ToString(files.Current));
//Check for JPG File Format
if (fileExtension == ".jpg" || fileExtension == ".JPG" || fileExtension == ".tif" || fileExtension == ".tiff") // or // ImageFormat.Jpeg.ToString()
{
try
{
//OCR Operations ...
MODI.Document _document = new MODI.Document();
_document.OnOCRProgress += new MODI._IDocumentEvents_OnOCRProgressEventHandler(_document_OnOCRProgress);
_document.Create(Convert.ToString(files.Current));
_document.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true); _completedOCR.WaitOne();
//_document.Save(); _images = _document.Images;
_image = (MODI.Image)_images[];
//FileStream createFile = new FileStream(filePath + ".txt", FileMode.CreateNew);
//StreamWriter writeFile = new StreamWriter(createFile);
_layout = _image.Layout;
string strContent = _layout.Text;
_document.Close(false);
//string strPath = "uploadify/OCRFile/" + cid + "/" + fileName;
//string strContent = "没有内容";
string strPath = "uploadify/OCRFile/" + cid + "/" + fileName;
SaveDate(strPath, strContent, cid);
//writeFile.Write(strContent);
//writeFile.Close(); }
catch (Exception ex)
{
throw ex;
//MessageBox.Show("This Image hasn't a text or has a problem",
//"OCR Notifications",
//MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
} }
}
}
void _document_OnOCRProgress(int Progress, ref bool Cancel)
{
if (Progress == )
{
_completedOCR.Set();
}
}
private static void SetComObjectToNull(params object[] objects)
{
for (int i = ; i < objects.Length; i++)
{
object o = objects[i];
if (o != null)
{
Marshal.FinalReleaseComObject(o);
o = null;
}
}
} [MethodImpl(MethodImplOptions.NoInlining)]
public void Dispose()
{
SetComObjectToNull(_layout, _image, _images, _document);
GC.Collect();
GC.WaitForPendingFinalizers();
} public void SaveDate(string strPath, string strContent, string cid)
{
try
{
Pt_ContractImg img = new Pt_ContractImg();
img.Content = strContent;
img.Path = strPath;
img.ContractID = Convert.ToInt32(cid);
Pt_ContractImg_DAO.Insert(img);
}
catch (Exception ex)
{ }
finally
{ }
}
public bool IsReusable
{
get
{
return false;
}
} }
}
利用OCR识别扫描的jpg、tif文件的文字的更多相关文章
- 基于Python实现对PDF文件的OCR识别
http://www.jb51.net/article/89955.htm https://pythontips.com/2016/02/25/ocr-on-pdf-files-using-pytho ...
- 【程序员的吃鸡大法】利用OCR文字识别+百度算法搜索,玩转冲顶大会、百万英雄、芝士超人等答题赢奖金游戏
[先上一张效果图]: 一.原理: 其实原理很简单: 1.手机投屏到电脑: 2.截取投屏画面的题目部分,进行识别,得到题目和三个答案: 3.将答案按照一定的算法,进行搜索,得出推荐答案: 4.添加了一些 ...
- 深入学习OpenCV文档扫描及OCR识别(文档扫描,图像矫正,透视变换,OCR识别)
如果需要处理的原图及代码,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice 下面 ...
- 利用OCR文字识别+百度算法搜索,玩转冲顶大会、百万英雄、芝士超人等答题赢奖金游戏
[先上一张效果图]: 一.原理: 其实原理很简单: 1.手机投屏到电脑: 2.截取投屏画面的题目部分,进行识别,得到题目和三个答案: 3.将答案按照一定的算法,进行搜索,得出推荐答案: 4.添加了一些 ...
- 身份证扫描识别/身份证OCR识别的正确姿势,你get到了吗?
自从国家规定电信实名制之后,实名制已经推广到各个领域:办理通信业务需要实名制.银行开户需要实名制.移动支付需要实名制,就连注册个自媒体账户都需要实名制. 而实名制的背后,就是身份证信息的采集和录入验证 ...
- 汽车VIN码识别/汽车车架号OCR识别,移动端VIN码识别,OCR扫描工具
本文推荐了一项汽车VIN码自动识别技术,用户通过手机“扫一扫”的简单操作,就可以快速识别VIN码,查询到车辆的详细信息,为汽修汽配.二手车交易.车辆监管.查勘理赔提高工作效率. VIN是英文Vehic ...
- 全能扫描王(一款识别率超高的OCR识别APP)
前言 无论是在工作还是日常生活中,我们都会经常遇到,需要将一些纸质资料上的文字内容变成电子文档进行编辑.这个时候就需要拥有一款好用的手机扫描+OCR文字识别功能的应用了. 随着人工智能的兴起,我们都在 ...
- 基于Tesseract的OCR识别小程序
一.背景 先说下开发背景,今年有次搬家找房子(2020了应该叫去年了),发现每天都要对着各种租房广告打很多电话.(当然网上也找了实地也找),每次基本都是对着墙面看电话号码然后拨打,次数一多就感觉非常麻 ...
- 发票OCR识别/票据OCR自动识别
对于一些大的集团公司来说,分散式财务管理模式管理效率不高,管理成本相对较高,同时也制约了集团企业发展战略的实施,因而需要建设财务共享中心.一个企业想建造财务共享中心,面临的难题是大量的数据采集和信息处 ...
随机推荐
- kms可用激活服务器地址|kms可用激活服务器分享
kms可用激活服务器地址|kms可用激活服务器分享 kms可用激活服务器地址都有哪些呢?使用kms激活服务器激活windows和office是微软提供的激活方式之一.kms激活服务器普遍由个人或企 ...
- 智能优化 之 下山单纯形法 C++
单纯形法简介在其他网站上都可以查到,我就不多说了 我们主要说方法 它主要解决的是局部最优解的问题 利用多边形进行求解的,若有n个变量,则利用n+1边形 我们这里以两个变量为例,求解第三维度的最优解 例 ...
- Running multiple commands in one line in shell
You are using | (pipe) to direct the output of a command into another command. What you are lookin ...
- dom那些事儿
一.dom常识1.style属性style对象的属性值都是字符串,设置时必须包括单位,但是不含规则结尾的分号.比如,elem.style.width不能写为100,而要写为100px. 2.getCo ...
- python魔法方法-单目运算及一般算数运算
在比较的魔法方法中,我们讨论了魔法方法其实就是重载了操作符,例如>.<.==等.而这里,我们继续讨论有关于数值的魔法方法. 1.单目运算符或单目运算函数 __pos__(self) 实现一 ...
- Python中应用SQL及SQLAlchemy(一)
以SQLit3为例: import sqlite3 conn = sqlite3.connect('db.sqlite3') #获取游标对象 cur = conn.cursor() #执行一系列SQL ...
- BZOJ.4319.[cerc2008]Suffix reconstruction(后缀数组 构造 贪心)
题目链接 \(Description\) 给定SA数组,求满足SA[]的一个原字符串(每个字符为小写字母),无解输出-1. \(Solution\) 假设我们现在有suf(SA[j]),要构造suf( ...
- Codeforces757E.Bash Plays With Functions(积性函数 DP)
题目链接 \(Description\) q次询问,每次给定r,n,求\(F_r(n)\). \[ f_0(n)=\sum_{u\times v=n}[(u,v)=1]\\ f_{r+1}(n)=\s ...
- 张量系列(tensor02)
张量的两种运算 1. 张量的乘(Tensor product) tensorproduct() 2. 张量的缩并 tensorcontraction() The matrix trace is equ ...
- [HDU1598]find the most comfortable road
思路: 考虑一个暴力:枚举最大的边权和最小的边权,然后将边权在这之间的边全拿出来构成一张无向图,剩下的就是判断是否存在一条从$S$到$T$的路径.相当于判$S$和$T$是否连通,用并查集连一下即可.时 ...