本帖最后由 xuzhenjun130 于 2011-1-7 17:49 编辑 史上最简单的图形验证码识别代码 , 下面的代码就是JavaScript, 直接使用Office 2003 中的MODI OCR对象2008-04-19 20:39史上最简单的图形验证码识别代码 , 下面的代码就是JavaScript, 直接使用Office 2003 中的MODI OCR对象
<script>
var oModi = new ActiveXObject("MODI.Document");
oModi.Create("C:\\English.tif");
oModi.Images(0).OCR(9); // 0x804
var oLy = oModi.Images(0).Layout;
alert(oLy.Text);
delete oLy;
delete oModi;
</script>
我测试上面代码没反应
以下是vb版的利用微软OCR控件, 只需要不到10行代码就能够实现自已的OCR文字识别软件.
1. 添加控件,需要安装office2003, 没有安装office2003的可以从别人机子上拷贝相关文件,注册regsvr32.exe mdivwctl.dll,
控件一般在这个目录下:C:\Program Files\Common Files\Microsoft Shared\MODI.0, 只需要相关的几个文件就可以了, 此文件夹全部文件大概在21M左右.
2.工程->部件->添加这个控件:Microsoft Office Document Imaging 11.0 Type Library
Option Explicit
'OCR的主要功能
Private Function OCRImageFile(ByVal strName As String) As Boolean
Dim modiDocument As New MODI.Document
Dim modiImages As New MODI.Images
Dim modiImage As New MODI.Image
Dim modiLayout As New MODI.Layout
Dim ImageCount As Integer
Dim i As Integer
modiDocument.OCR miLANG_CHINESE_SIMPLIFIED, False, False
Set modiImage = modiDocument.Images
For i = 0 To ImageCount
Set modiImage = modiImages.Item(i)
Set modiLayout = modiImage.Layout
Text1.Text = modiLayout.Text
Next i
modiDocument.Close False: Set modiDocument = Nothing
If ImageCount > 0 Then
OCRImageFile = True
Else
OCRImageFile = False
End If
End Function
另外一个例子Sub TestOCR()
Dim miDoc As MODI.Document
Set miDoc = New MODI.Document
Dim OutText As MODI.Layout
miDoc.Create "C:\1.tif "
Screen.MousePointer = vbHourglass
miDoc.OCR miLANG_CHINESE_SIMPLIFIED '语言为简体中文
'miDoc.OCR
Set OutText = miDoc.Images(0).Layout '识别第一页的数据
Text1.Text = OutText.Text
Screen.MousePointer = vbDefault
miDoc.Close False
Set OutText = Nothing
Set miDoc = Nothing
End Sub
下面的c++版的MODI.Document doc = new MODI.Document();
doc.Create("picPath");
MODI.Image image;
MODI.Layout layout;
string ret = null;
//doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);识别英文
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;
ret += layout.Text;
}
return ret;
下面的我写的au3,取不到任何文字,很是郁闷,请高手帮忙,根据上面其它版本的代码,写一个能用au3版本的$obj=ObjCreate("MODI.Document")
$obj.Create("c:\test.tif")
$obj.OCR(9,True,True)
$s=$obj.Images(0).Layout
MsgBox(0,0,$s)
|