Sign in to follow this  
Followers 0
loopz

Tesseract

14 posts in this topic

Hello!

I need help for a small project to recover the text of an image. So I chose the Tesseract OCR .
I did a lot of research on forums. I probably forgot something...

For example, this code doesn't work correctly :

#include <GDIPlus.au3>
#include <Tesseract.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
Opt("WinTextMatchMode", -2)
$img = @tempdir & "\img.png"
InetGet ("http://nsa26.casimages.com/img/2011/06/24//110624070800223936.png", $img)
Global $hGUI, $hImage, $hGraphic
$hGUI = GuiCreate("imgtest", 145, 30, 0, 0, $WS_POPUP)
GuiSetState()
_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile($img)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
Sleep(500)
$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 2, 0, 0, 5, 5, 0)
GuiDelete($hGUI)
MsgBox(0,"",$text)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()
FileDelete($img)
[/code]

I have no errors but nothing is displayed in the MsgBox .

I know that the subject has been done and redone ... So sorry, but I have the feeling of being stuck.

Thanks for your help (and sorry for my english)

Share this post


Link to post
Share on other sites



Help please

Share this post


Link to post
Share on other sites

I'm on windows 8 but i don't think it's the pb. I try everything i found, i don't understand why it doesn't work..

Share this post


Link to post
Share on other sites

First off, how do you know you have no errors, you do absolutely no error checking in your script? Check @error after every function call, use consolewrite to display the value of every variable after the functions return. Then you'll know where it's failing.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thank you for your answer.

I try it and i have no error and in $text i have nothing.. 

Share this post


Link to post
Share on other sites

Ok Jos and thank you too.

#include <GDIPlus.au3>
#include <Tesseract.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>

Opt("WinTextMatchMode", -2)

;$img = @tempdir & "\img.png"
$img = "img.tif"
;InetGet ("http://nsa26.casimages.com/img/2011/06/24//110624070800223936.png", $img)
;InetGet ("img.tif", $img)

Global $hGUI, $hImage, $hGraphic
$hGUI = GuiCreate("imgtest", 128, 19, 0, 0, $WS_POPUP)
GuiSetState()

_GDIPlus_StartUp()
$hImage   = _GDIPlus_ImageLoadFromFile($img)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
Sleep(500)

ConsoleWrite($hImage & @CRLF & $hGraphic & @CRLF)

$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 3, 0, 0, 5, 5, 0)
;$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 2, 0, 0, 256, 38, 0)
;$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 2, 0, 0, 128, 19, 0)

ConsoleWrite("hello" & @CRLF)
ConsoleWrite($text & @CRLF)
Sleep(5000)

GuiDelete($hGUI)
MsgBox(0,"",$text)

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()
;FileDelete($img)

I have the image in the same folder as the script.

I add this code to see the value of $text :

ConsoleWrite($text & @CRLF)
Sleep(5000)

And i execute the code in SciTE with the console.

Share this post


Link to post
Share on other sites

Thought you added some checks to ensure the performed functions were successful?
Something like this right after the performed UDF or Function:

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console

I see you are showing some variables now but you haven't shared whether they are correct or not.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

OK thank you, i add this code : 

$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 3, 0, 0, 5, 5, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console

and the result in the console : 

@@ Debug(39) >Error code: 0

Share this post


Link to post
Share on other sites

You should do something like this instead of a single error check.

#include <GDIPlus.au3>
#include <Tesseract.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>

Opt("WinTextMatchMode", -2)

;$img = @tempdir & "\img.png"
$img = "img.tif"
;InetGet ("http://nsa26.casimages.com/img/2011/06/24//110624070800223936.png", $img)
;InetGet ("img.tif", $img)

Global $hGUI, $hImage, $hGraphic
$hGUI = GuiCreate("imgtest", 128, 19, 0, 0, $WS_POPUP)
GuiSetState()

_GDIPlus_StartUp()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
$hImage   = _GDIPlus_ImageLoadFromFile($img)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
Sleep(500)

ConsoleWrite($hImage & @CRLF & $hGraphic & @CRLF)

$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 3, 0, 0, 5, 5, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $text = ' & $text & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
;$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 2, 0, 0, 256, 38, 0)
;$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 2, 0, 0, 128, 19, 0)

ConsoleWrite("hello" & @CRLF)
ConsoleWrite($text & @CRLF)
Sleep(5000)

GuiDelete($hGUI)
MsgBox(0,"",$text)

_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ShutDown()
;FileDelete($img)

Once you see where you're getting an error, you'll start to understand where you need to fix your script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ok BreawManNH. I try it : 

#include <GDIPlus.au3>
#include <Tesseract.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>

Opt("WinTextMatchMode", -2)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console

;$img = @tempdir & "\img.png"
$img = "img.tif"
;InetGet ("http://nsa26.casimages.com/img/2011/06/24//110624070800223936.png", $img)
;InetGet ("img.tif", $img)

Global $hGUI, $hImage, $hGraphic
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
$hGUI = GuiCreate("imgtest", 128, 19, 0, 0, $WS_POPUP)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
GuiSetState()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console

_GDIPlus_StartUp()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
$hImage   = _GDIPlus_ImageLoadFromFile($img)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
Sleep(500)

$text = _TesseractWinCapture("imgtest", "", 0, "", 1, 3, 0, 0, 5, 5, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console

ConsoleWrite("hello" & @CRLF)
ConsoleWrite($text & @CRLF)
;Sleep(5000)

GuiDelete($hGUI)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
MsgBox(0,"",$text)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console

_GDIPlus_GraphicsDispose($hGraphic)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
_GDIPlus_ImageDispose($hImage)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
_GDIPlus_ShutDown()
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') >Error code: ' & @error & @CRLF) ;### Debug Console
;FileDelete($img)

And the result in the console : 

@@ Debug(20) >Error code: 0
@@ Debug(28) >Error code: 0
@@ Debug(30) >Error code: 0
@@ Debug(32) >Error code: 0
@@ Debug(35) >Error code: 0
@@ Debug(37) >Error code: 0
@@ Debug(39) >Error code: 0
@@ Debug(41) >Error code: 0
@@ Debug(45) >Error code: 0
hello

@@ Debug(52) >Error code: 0
@@ Debug(54) >Error code: 0
@@ Debug(57) >Error code: 0
@@ Debug(59) >Error code: 0
@@ Debug(61) >Error code: 0

No luck for me

Share this post


Link to post
Share on other sites

Oh i try it in the Tesseract.au3 i took and i've an error.

I look at this and i tell you what it is.

Share this post


Link to post
Share on other sites

You don't have to reply on this. The example in first post works perfectly for me without any changes at all. Of course I have changed the half hard-coded paths for Tesseract.exe in Tesseract.au3 to the proper paths on Win 7.

Share this post


Link to post
Share on other sites

LarsJ your answer was not necessary ... They helped me a lot, unlike you. It's the objective of this forum.

BrewManNH and Jos thank you for your help, I solved my problem. For me, I've changed $tesseract_temp_path in Tesseract.au3 for the image (and not for the Tesseract.exe).

Resolved

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0