|
本帖最后由 35888894 于 2012-10-24 13:16 编辑
Local $hhh=_OCR_GetStringByPic("D:\1112.bmp",0);图片路径
Local $lsad=FileGetSize(@TempDir&"\1112.bmp")
MsgBox(0,$lsad/1024,$hhh)
崩溃了,如何解决由com组件引发的崩溃呢?
以下是OCR库文件代码
Const $miLANG_CZECH = 5
Const $miLANG_DANISH = 6
Const $miLANG_DUTCH = 19
Const $miLANG_ENGLISH = 9
Const $miLANG_FINNISH = 11
Const $miLANG_FRENCH = 12
Const $miLANG_GERMAN = 7
Const $miLANG_GREEK = 8
Const $miLANG_HUNGARIAN = 14
Const $miLANG_ITALIAN = 16
Const $miLANG_JAPANESE = 17
Const $miLANG_KOREAN = 18
Const $miLANG_NORWEGIAN = 20
Const $miLANG_POLISH = 21
Const $miLANG_PORTUGUESE = 22
Const $miLANG_RUSSIAN = 25
Const $miLANG_SPANISH = 10
Const $miLANG_SWEDISH = 29
Const $miLANG_TURKISH = 31
Const $miLANG_SYSDEFAULT = 2048
Const $miLANG_CHINESE_SIMPLIFIED = 2052
Const $miLANG_CHINESE_TRADITIONAL = 1028
;通过URL获取图片文本
Func _OCR_GetStringByPic($picpach1,$ocrkey=0);图片路径
If Not FileExists($picpach1) Then Return ""
Local $lsad=FileGetSize($picpach1)/1024
If $lsad>1800 Then Return 0
;调整图片大小为一屏幕可显示
PUBLIC_RESIZS_PIC($picpach1)
If $ocrkey<>0 Then
OCR_2ZH($picpach1,@TempDir&"\oopb.bmp");2值化
$picpach1=@TempDir&"\oopb.bmp"
EndIf
_GDIPlus_Startup()
Local $var = $picpach1;FileOpenDialog("选择图片", "", "图像文件 (*.jpg;*.bmp;*.tif;*.png;*.gif)")
Local $pname=StringRight($var,3)
$pname=StringLower($pname) ;取得文件名,再转换成小写
Local $Image = _GDIPlus_ImageLoadFromFile ($var)
Local $width1=_GDIPlus_ImageGetWidth($Image)
Local $height1=_GDIPlus_ImageGetHeight($Image)
If @DesktopWidth<$width1 Or @DesktopHeight<$height1 Then
_GDIPlus_ImageDispose($Image);释放图像对象
_GDIPlus_Shutdown()
Return 0
EndIf
;~ If @DesktopWidth<$width1 Then $width1=@DesktopWidth
;~ If @DesktopHeight<$height1 Then $height1=@DesktopHeight
;~ Local $tsdfsdfs=StringRegExp($picpach1,"[^\/\\]+\.[^\.]+$",3)
;~ Local $gfilexad="ooo2.bmp"
;~ If UBound($tsdfsdfs)>0 Then
;~ $gfilexad=$tsdfsdfs[0]
;~ FileDelete(@TempDir&"\o"&$gfilexad)
;~ _ImageResize2($picpach1, @TempDir&"\o"&$gfilexad, @DesktopWidth, @DesktopHeight)
;~ $picpach1=@TempDir&"\o"&$gfilexad
;~ MsgBox(0,FileExists($picpach1),@TempDir&"\o"&$gfilexad)
;~ _GDIPlus_Startup()
;~ $Image = _GDIPlus_ImageLoadFromFile ($picpach1)
;~ EndIf
;~ EndIf
; _myBitmapInvertColor($Image);二值化
If $pname<> "tif" then ;转换成 tif格式,用于识别
$file=TimerInit()&".tif"
$hImage = _GDIPlus_ImageLoadFromFile ($var)
$sCLSID = _GDIPlus_EncodersGetCLSID ("TIF")
$tData = DllStructCreate("int Data")
DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
$tParams = _GDIPlus_ParamInit (1)
_GDIPlus_ParamAdd ($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))
_GDIPlus_ImageSaveToFileEx ($hImage, @TempDir&"\"&$file, $sCLSID, DllStructGetPtr($tParams))
_GDIPlus_ImageDispose($hImage);释放图像对象
EndIf
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Image)
_GDIPlus_ImageDispose($Image);释放图像对象
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
Local $lang=$miLANG_CHINESE_SIMPLIFIED
; Local $lang=$miLANG_CHINESE_SIMPLIFIED
;Local $lang=9
;Local $lang=1028
If $pname="tif" Then
$path=$var
Else
$path=@TempDir&"\"&$file
EndIf
Local $obj=ObjCreate("MODI.Document")
If @error Then Return SetError(0)
If Not IsObj($obj) Then Return ""
$obj.Create($path)
; MsgBox(0,"",$path)
If @error Then Return SetError(0)
$obj.Ocr($lang,True,True)
If @error Then Return SetError(1)
Dim $a[1]
For $oWord in $obj.Images(0).Layout.Words
; If @error Then Return SetError(0)
If $lang=9 Then
_ArrayAdd($a,$oWord.text&" ")
; If @error Then Return SetError(0)
Else
_ArrayAdd($a,$oWord.text)
; If @error Then Return SetError(0)
EndIf
Next
$date=_ArrayToString($a,"")
;If @error Then Return SetError(0)
Return $date
EndFunc
;修改图片大小
Func PUBLIC_RESIZS_PIC($picpath)
_GDIPlus_Startup()
Local $Image = _GDIPlus_ImageLoadFromFile ($picpath)
Local $width1=_GDIPlus_ImageGetWidth($Image)
Local $height1=_GDIPlus_ImageGetHeight($Image)
If @DesktopWidth<$width1 Or @DesktopHeight<$height1 Then
_GDIPlus_ImageDispose($Image);释放图像对象
_GDIPlus_Shutdown()
If @DesktopWidth<$width1 Then $width1=@DesktopWidth
If @DesktopHeight<$height1 Then $height1=@DesktopHeight
Select
Case @DesktopWidth<$width1 And @DesktopHeight<$height1
If $width1/@DesktopWidth>$height1/@DesktopHeight Then
$height1=@DesktopHeight/@DesktopWidth*$width1
$width1=@DesktopWidth
Else
$width1=@DesktopWidth/@DesktopHeight*$height1
$height1=@DesktopWidth
EndIf
Case @DesktopWidth<$width1
$height1=@DesktopHeight/@DesktopWidth*$width1
$width1=@DesktopWidth
Case @DesktopHeight<$height1
$width1=@DesktopWidth/@DesktopHeight*$height1
$height1=@DesktopWidth
EndSelect
Local $tsdfsdfs=StringRegExp($picpath,"[^\/\\]+\.[^\.]+$",3)
Local $gfilexad="ooo2.bmp"
If UBound($tsdfsdfs)>0 Then
$gfilexad=$tsdfsdfs[0]
FileDelete(@TempDir&"\o"&$gfilexad)
_ImageResize2($picpath, @TempDir&"\o"&$gfilexad, $width1, $height1)
FileCopy(@TempDir&"\o"&$gfilexad,$picpath,1)
EndIf
EndIf
_GDIPlus_ImageDispose($Image);释放图像对象
_GDIPlus_Shutdown()
EndFunc |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?加入
×
|