Jump to content

Recommended Posts

Posted

Awesome.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

As so far _UWPOCR_GetText() support only $hBitmap or FileFullPath, could you add a feature to provide BinaryVariant ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

@mLipok  I think it's not needed you just need to use _GDIPlus_BitmapCreateFromMemory

 

Saludos

Edited by Danyfirex
Posted (edited)

How to get data from desired/specified window ?

As so far I try:

#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include "..\UWPOCR.au3"


_Example()

Func _Example()

    #Region - create example bitmap - take a screenshot
    _GDIPlus_Startup()
    ;hImage/hBitmap GDI
    Local $hTimer = TimerInit()
    Local $hHBitmap = _ScreenCapture_CaptureWnd("", WinWait("[REGEXPTITLE:(?i)(.*SciTE.*)]"))
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    #EndRegion - create example bitmap  - take a screenshot

    #Region - do the OCR Stuff
    ;Get OCR Text From hImage/hBitmap
;~  _UWPOCR_Log(__UWPOCR_Log) ;Enable Log
    Local $sOCRTextResult = _UWPOCR_GetText($hBitmap, Default, True)
    MsgBox(0, "Time Elapsed: " & TimerDiff($hTimer), $sOCRTextResult)
    #EndRegion - do the OCR Stuff

    #Region - bitmap clean up
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    #EndRegion - bitmap clean up

EndFunc   ;==>_Example

But this not works properly.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
Posted

So I checked:
 

#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include "..\UWPOCR.au3"


_Example()

Func _Example()

    #Region - create example bitmap - take a screenshot
    _GDIPlus_Startup()
    ;hImage/hBitmap GDI
    Local $hTimer = TimerInit()
;~  Local $hHBitmap = _ScreenCapture_CaptureWnd("", WinWait("[REGEXPTITLE:(?i)(.*SciTE.*)]"))
;~  Local $hHBitmap = _ScreenCapture_CaptureWnd("", WinWait("[CLASS:SciTEWindow]"))
;~  Local $hHBitmap = _ScreenCapture_CaptureWnd("", WinWait("[CLASS:AVL_AVView]"))
    Local $hHBitmap = _ScreenCapture_CaptureWnd("", WinWait("[CLASS:AcrobatSDIWindow]"))
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    #EndRegion - create example bitmap  - take a screenshot

    #Region - do the OCR Stuff
    ;Get OCR Text From hImage/hBitmap
;~  _UWPOCR_Log(__UWPOCR_Log) ;Enable Log
    Local $sOCRTextResult = _UWPOCR_GetText($hBitmap, Default, True)
    MsgBox(0, "Time Elapsed: " & TimerDiff($hTimer), $sOCRTextResult)
    #EndRegion - do the OCR Stuff

    #Region - bitmap clean up
    _WinAPI_DeleteObject($hHBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    #EndRegion - bitmap clean up

EndFunc   ;==>_Example

and:

  Quote

Developing for ÂcIcbe Reader - ÂcIcbe Âcrcbat Reader DC (32-bit)
Plik Edycja Widok
1
Podpis
Okno
Pomoc
Developing for Ado.. x
Zaloguj się
Introduction
This chapter describes the supwrted platforms for development using the Acrobat SDK, and summarizes
the technologies available within the SDK.
Supported platforms
This section describes the requirements for using the interapplication communication and Acrobat core
and extendui APIS on all platforms. The follcw.•łng platforms are currently supported for
development with Adobe Rea der:
Solaris•
HP-UX
Details for each platform are described belwa.
Windows
Microsoft Windows 2CKH) with Service Pack 2
Microsoft Windows XP Professional or Home Edition
Development environments
Microsoft Visual Studio AET 2CH)2
Microsoft Visual Studio 2CH)5
Note: For more information on the Windcws environment, su the and Developing P,'ug-ins and
Apm'łcatbns.
Mac OS
Mac OS X versions 10.28 or Later.
Development environment
Note: For more information on Mac OS development environments, see the Ovewiew and Devenp,ing
P,'ug-ins and Applications


 

Expand  

and it is taken from:

image.thumb.png.b790d1309b137ccad6847d28f854d2d9.png

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

The issues with OCR are becuase I had zoomed out PDF (68%)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

When you get some spare time you can check: https://github.com/DanysysTeam/UWPOCR/pulls

I did some PR

;)

In the next steps, I will try to provide functions such as:

_UWPOCR_GetTextFromFile()
_UWPOCR_GetTextFromScreen()
_UWPOCR_GetTextFromWindow()
_UWPOCR_GetTextFromMemory()

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

is the advantage that we dont need to install tesseract?  is it faster? or is it better in any other way?

Edited by drrehak
Posted

@drrehak It seems to be it's supported since Windows 10. Faster or better. I don't know. It need to be tested to know it.

 

Saludos

Posted (edited)
  On 1/11/2022 at 2:16 PM, drrehak said:

is the advantage that we dont need to install tesseract?

Expand  

Yes. Only Windows 10 + AutoIt

  On 1/11/2022 at 2:16 PM, drrehak said:

is it faster?

Expand  

Please do some test with tesseract and show how you test them (post here: 1. code snippet  2. testing image 3. your timing results).
Then we prepare example for the same source data with this UDF an you will be able to compare.

  On 1/11/2022 at 2:16 PM, drrehak said:

is it better in any other way?

Expand  

As so far nobody asked this question and I doupt that any body use this features with AutoIt any time before , so we can only guess.

btw. I saw that @Danyfirex answered when I was in the middle ofr my writing here.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Moderators
Posted

Danyfirex,

Nice work Dany!!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Here is a script to compare UWPOCR vs Tesseract. (it just load image process and show result in editboxes and display the processed image to compare visually. 

#include <WinAPISys.au3>
#include <WinAPIsysinfoConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <FileConstants.au3>
#include "..\..\UWPOCR.au3"

Global $g_sTesseractPath = @ScriptDir & "\tesseract-ocr-w64-setup-v5.0.0-alpha.20210811\tesseract.exe" ;change me

_TestUWPOCRvsTesseractOCR()

Func _TestUWPOCRvsTesseractOCR()

    Local $sFileOpenDialog = FileOpenDialog("Select images to process", @ScriptDir & "\", "Images (*.jpg;*.png;*.gif;*.tif;*.bmp)", BitOR($FD_FILEMUSTEXIST, $FD_MULTISELECT))
    Local $aFiles = StringSplit($sFileOpenDialog, "|", 1)
    Local $sImagePath = ""
    For $i = 2 To $aFiles[0]
        $sImagePath = $aFiles[$i]
        _GUIComparation($sImagePath, _UWPOCR_GetText($sImagePath), _GetTesseractOCRText($sImagePath))
    Next
EndFunc   ;==>_TestUWPOCRvsTesseractOCR

Func _GUIImageProcessed($sTitle, $sImagePath)
    _GDIPlus_Startup()
    Local Const $iW = @DesktopWidth, $iH = @DesktopHeight

    Local $hImage = _GDIPlus_ImageLoadFromFile($sImagePath) ;create a GDI bitmap by capturing full screen of the desktop

    Local $iWImage = _GDIPlus_ImageGetWidth($hImage)
    Local $iHImage = _GDIPlus_ImageGetHeight($hImage)
    If $iWImage > $iW Or $iHImage > $iH Then
        $iWImage = Int($iWImage / 1.5)
        $iHImage = Int($iHImage / 1.5)
    EndIf

    Local $hBitmap_Scaled = _GDIPlus_ImageResize($hImage, $iWImage, $iHImage) ;resize image

    Local $hGUI = GUICreate($sTitle, $iWImage, $iHImage, -1, -1) ;create a test gui to display the resized image
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) ;display scaled image

    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap_Scaled)
    _GDIPlus_Shutdown()
    Return $hGUI
EndFunc   ;==>_GUIImageProcessed

Func _GUIComparation($sTitle, $sUWPOCRText, $sTesseractText)
    Local $hGUIImage = _GUIImageProcessed($sTitle, $sTitle)
    GUIRegisterMsg($WM_NCHITTEST, _WM_NCHITTEST)
    Local $iWidth = @DesktopWidth - 100
    Local $iHeight = @DesktopHeight - 100
    Local $hWindow = GUICreate($sTitle, $iWidth, $iHeight)
    GUISetBkColor(0x000000)
    Local $idtxtUWPOCR = GUICtrlCreateEdit($sUWPOCRText, 0, 30, ($iWidth / 2) - 5, $iHeight - 30, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
    GUICtrlSetFont(-1, 11)
    Local $idtxtTesseract = GUICtrlCreateEdit($sTesseractText, ($iWidth / 2) + 5, 30, ($iWidth / 2) - 5, $iHeight - 30, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
    GUICtrlSetFont(-1, 11)
    GUICtrlCreateLabel("UWPOCR Output", 1, 5, ($iWidth / 2) - 5, 25, $SS_CENTER)
    GUICtrlSetColor(-1, 0xffffff)
    GUICtrlSetFont(-1, 15)
    GUICtrlCreateLabel("Tesseract Output", ($iWidth / 2) + 5, 5, ($iWidth / 2) - 5, 25, $SS_CENTER)
    GUICtrlSetColor(-1, 0xffffff)
    GUICtrlSetFont(-1, 15)
    GUISetState(@SW_SHOW, $hWindow)
    WinActivate($hGUIImage)
    WinMove($hGUIImage, "", Default, $iHeight / 2)
    MsgBox(0, "Info", "Click to continue...")
    GUIDelete($hWindow)
    GUIDelete($hGUIImage)
EndFunc   ;==>_GUIComparation

Func _WM_NCHITTEST($hWnd, $uMsg, $wParam, $lParam)
    Return $HTCAPTION
EndFunc   ;==>_WM_NCHITTEST


Func _GetTesseractOCRText($sImagePath)
    Local $sFileOutText = @ScriptDir & "\output"
    RunWait('"' & $g_sTesseractPath & '" "' & $sImagePath & '" "' & $sFileOutText & '"', "", @SW_HIDE)
    Local $sOutText = FileRead($sFileOutText & ".txt")
    FileDelete($sOutText)
    Return $sOutText
EndFunc   ;==>_GetTesseractOCRText

Saludos

Posted (edited)

Check available languages with _ArrayDisplay(_UWPOCR_GetSupportedLanguages())

Install additional language packs like described here:

https://support.microsoft.com/en-us/windows/language-packs-for-windows-a5094319-a92d-18de-5b53-1cfc697cfca8

Select language codes as displayed in above mentioned check:

image.png.e38304ee3cdf1a787c9e0d1040772f18.png

e.g.  : Local $sOCRTextResult = _UWPOCR_GetText($sImageFilePath,"de-DE",True)

Edited by KaFu
Posted

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
×
×
  • Create New...