Jump to content

OCR + Tesseract help


Recommended Posts

Hi Everyones,

I need to read the number of X Axis, Y Axis and Z axis on the screen I've attached, I tought to use tesseract to convert the number to text, but the thing is the PC where the software run is on Windows Nt4 SP6, I can't get tesseract to work on this old PC, Does anyone know if it possible? what should I do? If you have better idea how to do that I'm open to all suggestion.

Thank You

Karkanov

post-57568-12722081827819_thumb.jpg

Link to comment
Share on other sites

Try using the control commands, after getting the info of the controls autoit window info tool.

I imagine that if you can get tesseract to operate then you know how to navigate the helpfile.

Try some code and dont hesitate to ask if you are having trouble.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hello, 

I´ve written a tool to "solve" problems like yours by comparing images. To detect the right "characters" it is helpful to have a constant colour in the background of the characters.

The background of the characters (the numbers you are looking for) in your picture is not evenly in one colour. Are the different colours due to the compression-artefacts of the jpg?

post-51807-12722113755726_thumb.jpg

Link to comment
Share on other sites

Hello, 

I´ve written a tool to "solve" problems like yours by comparing images. To detect the right "characters" it is helpful to have a constant colour in the background of the characters.

The background of the characters (the numbers you are looking for) in your picture is not evenly in one colour. Are the different colours due to the compression-artefacts of the jpg?

The background is not the same, because they are "control object" BUt if I try to read the control value for some reason I don't get any value, it's like the windows don't refresh the value everytime it changes. Do you need to teach your tool every character before use it??

Link to comment
Share on other sites

hmmm, if the AutoIt Window-Info-Tool doesn´t get results, try to use an other little program to make the OCR. Copy these files into the scriptdir....

djpeg.exe

gocr.exe

;script by Funkey  www.AutoIt.de
#include <ScreenCapture.au3>

Local $pid = Run('notepad.exe')
WinWait('[Class:Notepad]')
WinActivate('[Class:Notepad]')
WinWaitActive('[Class:Notepad]')
Send('This is an OCR Test!')

Local $text = _ReadControl_OCR("[Class:Notepad]", "", "Edit1", 2, 2, @ScriptDir)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ScriptDir = ' & @ScriptDir & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If @error Then
    MsgBox(16, "OCR-Error", @error)
Else
    MsgBox(64, "Result", $text)
EndIf

Local $text = _ReadGuiArea_OCR("[Class:Notepad]", "", 3, 2, 350, 18, @ScriptDir)
If @error Then
    MsgBox(16, "OCR-Error", @error)
Else
    MsgBox(64, "Result", $text)
EndIf

ProcessClose($pid)

Func _ReadControl_OCR($hWnd, $sText, $hCtrl, $iBorderX = 0, $iBorderY = 0, $AppDir = @ScriptDir)
    ;funkey
    WinActivate($hWnd)
    Local $Timeout = WinWaitActive($hWnd, $sText, 1)
    If Not $Timeout Then Return SetError(1, 0, "")
    Local $WinPos = WinGetPos($hWnd, $sText)
    Local $ControlPos = ControlGetPos($hWnd, $sText, $hCtrl)
    If @error Then Return SetError(2, 0, "")
    Local $aClientSize = WinGetClientSize($hWnd, $sText)
    If @error Then Return SetError(3, 0, "")
    Local $Rahmen = ($WinPos[2] - $aClientSize[0]) / 2
    Local $iOffsetx = $WinPos[2] - $aClientSize[0] - $Rahmen
    Local $iOffsety = $WinPos[3] - $aClientSize[1] - $Rahmen
    Local $Wert = ""
    _ScreenCapture_Capture(@ScriptDir & '\TextControl.jpg', _
            $WinPos[0] + $ControlPos[0] + $iOffsetx + $iBorderX, _
            $WinPos[1] + $ControlPos[1] + $iOffsety + $iBorderY, _
            $WinPos[0] + $ControlPos[0] + $ControlPos[2] + $iOffsetx - $iBorderX, _
            $WinPos[1] + $ControlPos[1] + $ControlPos[3] + $iOffsety - $iBorderY, False)
    RunWait(@ComSpec & " /c " &'djpeg -greyscale -dither none TextControl.jpg TextControl.pnm', @ScriptDir, @SW_HIDE)
    Local $App = Run(@ComSpec & " /c " & 'gocr -i TextControl.pnm', @ScriptDir, @SW_HIDE, 0x2)
    While 1
        $Wert &= StdoutRead($App)
        If @error Then ExitLoop
    WEnd
 ;   FileDelete(@ScriptDir & '\TextControl.jpg')
 ;   FileDelete(@ScriptDir & '\TextControl.pnm')
    Return $Wert
EndFunc   ;==>_ReadQWidget

Func _ReadGuiArea_OCR($hWnd, $sText, $x1, $y1, $x2, $y2, $AppDir = @ScriptDir)
    ;funkey
    WinActivate($hWnd)
    Local $Timeout = WinWaitActive($hWnd, $sText, 1)
    If Not $Timeout Then Return SetError(1, 0, "")
    Local $WinPos = WinGetPos($hWnd, $sText)
    Local $aClientSize = WinGetClientSize($hWnd, $sText)
    If @error Then Return SetError(2, 0, "")
    Local $Rahmen = ($WinPos[2] - $aClientSize[0]) / 2
    Local $iOffsetx = $WinPos[2] - $aClientSize[0] - $Rahmen
    Local $iOffsety = $WinPos[3] - $aClientSize[1] - $Rahmen
    Local $Wert = ""
    _ScreenCapture_Capture(@ScriptDir & '\TextArea.jpg', _
            $WinPos[0] + $x1 + $iOffsetx, _
            $WinPos[1] + $y1 + $iOffsety, _
            $WinPos[0] + $x2 + $iOffsetx, _
            $WinPos[1] + $y2 + $iOffsety, False)
    RunWait(@ComSpec & " /c " &'djpeg -greyscale -dither none TextArea.jpg TextArea.pnm', @ScriptDir, @SW_HIDE)
    Local $App = Run(@ComSpec & " /c " & 'gocr -i TextArea.pnm', @ScriptDir, @SW_HIDE, 0x2)
    While 1
        $Wert &= StdoutRead($App)
        If @error Then ExitLoop
    WEnd
;    FileDelete(@ScriptDir & '\TextArea.jpg')
;    FileDelete(@ScriptDir & '\TextArea.pnm')
    Return $Wert
EndFunc   ;==>_ReadQWidget

If this doesn´t work properly, we have to "teach" each character of the numbers  :idea:

Link to comment
Share on other sites

hmmm, if the AutoIt Window-Info-Tool doesn´t get results, try to use an other little program to make the OCR. Copy these files into the scriptdir....

djpeg.exe

gocr.exe

;script by Funkey  www.AutoIt.de
#include <ScreenCapture.au3>

Local $pid = Run('notepad.exe')
WinWait('[Class:Notepad]')
WinActivate('[Class:Notepad]')
WinWaitActive('[Class:Notepad]')
Send('This is an OCR Test!')

Local $text = _ReadControl_OCR("[Class:Notepad]", "", "Edit1", 2, 2, @ScriptDir)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ScriptDir = ' & @ScriptDir & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If @error Then
    MsgBox(16, "OCR-Error", @error)
Else
    MsgBox(64, "Result", $text)
EndIf

Local $text = _ReadGuiArea_OCR("[Class:Notepad]", "", 3, 2, 350, 18, @ScriptDir)
If @error Then
    MsgBox(16, "OCR-Error", @error)
Else
    MsgBox(64, "Result", $text)
EndIf

ProcessClose($pid)

Func _ReadControl_OCR($hWnd, $sText, $hCtrl, $iBorderX = 0, $iBorderY = 0, $AppDir = @ScriptDir)
    ;funkey
    WinActivate($hWnd)
    Local $Timeout = WinWaitActive($hWnd, $sText, 1)
    If Not $Timeout Then Return SetError(1, 0, "")
    Local $WinPos = WinGetPos($hWnd, $sText)
    Local $ControlPos = ControlGetPos($hWnd, $sText, $hCtrl)
    If @error Then Return SetError(2, 0, "")
    Local $aClientSize = WinGetClientSize($hWnd, $sText)
    If @error Then Return SetError(3, 0, "")
    Local $Rahmen = ($WinPos[2] - $aClientSize[0]) / 2
    Local $iOffsetx = $WinPos[2] - $aClientSize[0] - $Rahmen
    Local $iOffsety = $WinPos[3] - $aClientSize[1] - $Rahmen
    Local $Wert = ""
    _ScreenCapture_Capture(@ScriptDir & '\TextControl.jpg', _
            $WinPos[0] + $ControlPos[0] + $iOffsetx + $iBorderX, _
            $WinPos[1] + $ControlPos[1] + $iOffsety + $iBorderY, _
            $WinPos[0] + $ControlPos[0] + $ControlPos[2] + $iOffsetx - $iBorderX, _
            $WinPos[1] + $ControlPos[1] + $ControlPos[3] + $iOffsety - $iBorderY, False)
    RunWait(@ComSpec & " /c " &'djpeg -greyscale -dither none TextControl.jpg TextControl.pnm', @ScriptDir, @SW_HIDE)
    Local $App = Run(@ComSpec & " /c " & 'gocr -i TextControl.pnm', @ScriptDir, @SW_HIDE, 0x2)
    While 1
        $Wert &= StdoutRead($App)
        If @error Then ExitLoop
    WEnd
 ;   FileDelete(@ScriptDir & '\TextControl.jpg')
 ;   FileDelete(@ScriptDir & '\TextControl.pnm')
    Return $Wert
EndFunc   ;==>_ReadQWidget

Func _ReadGuiArea_OCR($hWnd, $sText, $x1, $y1, $x2, $y2, $AppDir = @ScriptDir)
    ;funkey
    WinActivate($hWnd)
    Local $Timeout = WinWaitActive($hWnd, $sText, 1)
    If Not $Timeout Then Return SetError(1, 0, "")
    Local $WinPos = WinGetPos($hWnd, $sText)
    Local $aClientSize = WinGetClientSize($hWnd, $sText)
    If @error Then Return SetError(2, 0, "")
    Local $Rahmen = ($WinPos[2] - $aClientSize[0]) / 2
    Local $iOffsetx = $WinPos[2] - $aClientSize[0] - $Rahmen
    Local $iOffsety = $WinPos[3] - $aClientSize[1] - $Rahmen
    Local $Wert = ""
    _ScreenCapture_Capture(@ScriptDir & '\TextArea.jpg', _
            $WinPos[0] + $x1 + $iOffsetx, _
            $WinPos[1] + $y1 + $iOffsety, _
            $WinPos[0] + $x2 + $iOffsetx, _
            $WinPos[1] + $y2 + $iOffsety, False)
    RunWait(@ComSpec & " /c " &'djpeg -greyscale -dither none TextArea.jpg TextArea.pnm', @ScriptDir, @SW_HIDE)
    Local $App = Run(@ComSpec & " /c " & 'gocr -i TextArea.pnm', @ScriptDir, @SW_HIDE, 0x2)
    While 1
        $Wert &= StdoutRead($App)
        If @error Then ExitLoop
    WEnd
;    FileDelete(@ScriptDir & '\TextArea.jpg')
;    FileDelete(@ScriptDir & '\TextArea.pnm')
    Return $Wert
EndFunc   ;==>_ReadQWidget

If this doesn´t work properly, we have to "teach" each character of the numbers  :idea:

Thank You, work pretty good, I'll need to make some modyfications, and see how that could be more accurante but it give me a very good starting point. you helped me a lot. I'll copy the final result in few days.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...