autoit莫迪。文档错误变量必须是“Object”类型

时间:2022-06-01 16:20:14
#include <Constants.au3>
#include <ScreenCapture.au3>
#Include <Misc.au3>
#include <Array.au3>
#include <GDIPlus.au3>


$image = @MyDocumentsDir & "\aaa_teste.jpg"
ConsoleWrite(OCR($image))


Func OCR($Image)
    Local $miDoc, $Doc
    Local $str
    Local $oWord
    Local $sArray[500]
    Local $as_Text = ""


    $miDoc = ObjCreate("MODI.Document")
    ConsoleWrite("ObjCreate - The error value is: " & @error & @CRLF)
    $miDoc.Create(@TempDir & '\OCR_ImageResize.jpg')
    ConsoleWrite("Create - The error value is: " & @error & @CRLF)
    $miDoc.Ocr(9, False, False)
    ConsoleWrite("Ocr - The error value is: " & @error & @CRLF)

    If $Error = False Then
        $i = 0
        For $oWord in $miDoc.Images(0).Layout.Words

            $str = $str & $oWord.text & @CrLf
                ConsoleWrite($oWord.text & @CRLF)
            $sArray [$i] = $oWord.text
            $i += 1

        Next

        $as_Text = _ArrayToString($sArray," ",0)
        $as_Text = StringReplace($as_Text, "  ", "", 0)

    ElseIf $Error = True Then

        $Error = False
    EndIf

    $miDoc.Close(False)
    Return $as_Text

EndFunc

I`m trying read a text from a screencapture The error is:

我试着从屏幕截图中读取文本错误是:

"C:\Users\jose.barbosaneto\Desktop\TESTE.au3" (23) : ==> Variable must be of type "Object".: $miDoc.Create(@TempDir & '\OCR_ImageResize.jpg') $miDoc^ ERROR

“C:\ \ jose.barbosaneto \用户桌面\证人。au3"(23): ==>变量必须为“Object”类型。:miDoc美元。创建(@TempDir & \ OCR_ImageResize.jpg)美元miDoc ^错误

Please help me

请帮我

1 个解决方案

#1


1  

The only downside of MODI library is that it relies 100 % on MS Office. So if you don't have the proper version installed it will not find the needed COM object.

莫迪图书馆唯一的缺点是它100%依赖于MS Office。因此,如果您没有安装适当的版本,它将无法找到所需的COM对象。

Check the Office version you have installed and see if MODI is in there. Go in Uninstall Programs and click on Change/Repair on the MS Office version you have. From there you can check if MODI documents are installed.

检查你安装的Office版本,看看莫迪是否在里面。进入卸载程序,点击MS Office版本的更改/修复。从那里您可以检查是否安装了MODI文档。

Edit: Install MDI to TIFF Files Converter and SharePoint Designer from this link: https://support.microsoft.com/en-us/kb/982760 After installing them go to > Uninstall a Program>MS Office SharePoint Designer 2007> Right click on it and select Change>select Add or Remove Features. From there in the menu you will find the option Office Tools. Expand it. Then click on the small arrows on MODI(Microsoft Office Document Imaging) and select "Run all from my Computer".

编辑:从这个链接安装MDI到TIFF文件转换器和SharePoint设计器:https://support.microsoft.com/en-us/kb/982760安装后,到>卸载程序> mb1 mms Office SharePoint Designer 2007,右键单击并选择Change>选择添加或删除特性。从菜单中你可以找到Office工具选项。扩大它。然后点击莫迪上的小箭头(Microsoft Office文档映像),选择“从我的电脑上运行所有”。

And you are ready to go!

你已经准备好出发了!

Edit2: Here is a tested and working example.

这是一个测试和工作的例子。

#include <GUIConstants.au3>
#include <Array.au3>

Dim $miDoc, $Doc
Dim $str
Dim $oWord
Dim $sArray[500]

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

Local $ImagePath = @DesktopDir & "\Untitled.png" ; you can choose .tif format if you also want
; Initialize error handler
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$miDoc = ObjCreate("MODI.Document")
$miDocView = ObjCreate("MiDocViewer.MiDocView")

$Viewer = GUICreate("Embedded MODI Viewer", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)


;Creates an ActiveX Control in the GUI.
$GUIActiveX = GUICtrlCreateObj($miDocView, -1, -1, 640, 580)
GUICtrlSetResizing($Viewer, $GUI_DOCKAUTO)


$miDoc.Create($ImagePath)
$miDoc.Ocr($miLANG_ENGLISH, True, False)

; Show GUI
GUISetState()

$miDocView.Document = $miDoc
$miDocView.SetScale(0.75, 0.75)


While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd



$i = 0

For $oWord In $miDoc.Images(0).Layout.Words

    $str = $str & $oWord.text & @CRLF
    ConsoleWrite($oWord.text & @CRLF)
    $sArray[$i] = $oWord.text
    $i += 1
Next

_ArrayDisplay($sArray, "OCR Result")



;MsgBox(0,"",$miDocView.FileName)

;------------------------------ This is a COM Error handler --------------------------------
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "COM Error Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    SetError(1) ; to check for after this function returns
EndFunc   ;==>MyErrFunc

#1


1  

The only downside of MODI library is that it relies 100 % on MS Office. So if you don't have the proper version installed it will not find the needed COM object.

莫迪图书馆唯一的缺点是它100%依赖于MS Office。因此,如果您没有安装适当的版本,它将无法找到所需的COM对象。

Check the Office version you have installed and see if MODI is in there. Go in Uninstall Programs and click on Change/Repair on the MS Office version you have. From there you can check if MODI documents are installed.

检查你安装的Office版本,看看莫迪是否在里面。进入卸载程序,点击MS Office版本的更改/修复。从那里您可以检查是否安装了MODI文档。

Edit: Install MDI to TIFF Files Converter and SharePoint Designer from this link: https://support.microsoft.com/en-us/kb/982760 After installing them go to > Uninstall a Program>MS Office SharePoint Designer 2007> Right click on it and select Change>select Add or Remove Features. From there in the menu you will find the option Office Tools. Expand it. Then click on the small arrows on MODI(Microsoft Office Document Imaging) and select "Run all from my Computer".

编辑:从这个链接安装MDI到TIFF文件转换器和SharePoint设计器:https://support.microsoft.com/en-us/kb/982760安装后,到>卸载程序> mb1 mms Office SharePoint Designer 2007,右键单击并选择Change>选择添加或删除特性。从菜单中你可以找到Office工具选项。扩大它。然后点击莫迪上的小箭头(Microsoft Office文档映像),选择“从我的电脑上运行所有”。

And you are ready to go!

你已经准备好出发了!

Edit2: Here is a tested and working example.

这是一个测试和工作的例子。

#include <GUIConstants.au3>
#include <Array.au3>

Dim $miDoc, $Doc
Dim $str
Dim $oWord
Dim $sArray[500]

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

Local $ImagePath = @DesktopDir & "\Untitled.png" ; you can choose .tif format if you also want
; Initialize error handler
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$miDoc = ObjCreate("MODI.Document")
$miDocView = ObjCreate("MiDocViewer.MiDocView")

$Viewer = GUICreate("Embedded MODI Viewer", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)


;Creates an ActiveX Control in the GUI.
$GUIActiveX = GUICtrlCreateObj($miDocView, -1, -1, 640, 580)
GUICtrlSetResizing($Viewer, $GUI_DOCKAUTO)


$miDoc.Create($ImagePath)
$miDoc.Ocr($miLANG_ENGLISH, True, False)

; Show GUI
GUISetState()

$miDocView.Document = $miDoc
$miDocView.SetScale(0.75, 0.75)


While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd



$i = 0

For $oWord In $miDoc.Images(0).Layout.Words

    $str = $str & $oWord.text & @CRLF
    ConsoleWrite($oWord.text & @CRLF)
    $sArray[$i] = $oWord.text
    $i += 1
Next

_ArrayDisplay($sArray, "OCR Result")



;MsgBox(0,"",$miDocView.FileName)

;------------------------------ This is a COM Error handler --------------------------------
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "COM Error Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    SetError(1) ; to check for after this function returns
EndFunc   ;==>MyErrFunc