eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

AutoIt

autoit でTesseract.au3 OCRを使う

投稿日:

Tesseract.au3

こちらからダウンロード
https://www.autoitscript.com/forum/topic/89542-tesseract-screen-ocr-udf/

使う前の準備

Tesseractのダウンロードインストール
http://memo.eightban.com/autoit/autoit-ocr

Tesseract.au3カスタマイズ

tesseract.exeの場所とパラメータを変えます

コードを追加

Global const $Tesseract_Exe_Path = "c:\app\Tesseract-OCR\tesseract.exe"
Global $tesseract_para = ""

func _TesseractparaSet($temp_para)
$tesseract_para = $temp_para
Return 1
EndFunc

コードの変更 3箇所

ShellExecuteWait($Tesseract_Exe_Path, $capture_filename & " " & $ocr_filename & " " & $tesseract_para, "", "", @SW_HIDE)

;; ShellExecuteWait(@ProgramFilesDir & "\Tesseract-OCR\tesseract.exe", $capture_filename & " " & $ocr_filename, "", "", @SW_HIDE)

メモ帳を使ったサンプル


#include <Tesseract.au3>
;
Global  $tesseract_para1 = " --psm 3 --oem 1 -l jpn+eng"
;Global  $tesseract_para1 = " --psm 3 --oem 1 -l jpn"
;Global  $tesseract_para1 = " "
;Global  $tesseract_para1 = " "
;Global  $tesseract_para1 = " -c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyz0123456789  --psm 7 --oem 1 -l jpn"
Local $pid = Run('notepad.exe')
WinWait('[Class:Notepad]')
WinActivate('[Class:Notepad]')
WinWaitActive('[Class:Notepad]')
Send("test")
 _TesseractparaSet($tesseract_para1)

    $text1 = _TesseractScreenCapture()
    $text2 = _TesseractWinCapture('[Class:Notepad]', "")
    $text3 = _TesseractControlCapture('[Class:Notepad]', "","[CLASS:RichEditD2DPT; INSTANCE:1]")
	$col =  _TesseractWinFind("[Class:Notepad]", "", "Windows", 1, 0, "", 1, 2, 0, 0, 0, 0, 0)
     MsgBox(0, "_TesseractScreenCapture", $text1,10)
     MsgBox(0, "_TesseractWinCapture", $text2,10)
     MsgBox(0, "_TesseractControlCapture", $text3,10)
     MsgBox(0, "_TesseractWinFind", $col,10)

WinClose("[CLASS:Notepad]", "")
Send("{RIGHT}")
Send("{ENTER}")

こちらの関数を使うと画面を指定したりキャプチャーする画面のサイズを指定できます

-AutoIt

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.