Jump to content

OCR & Paste


ronriel
 Share

Recommended Posts

Yeah. This can/will be very useful =D

@OP

Good job! I modified it though...

@All

Here is my modification. Has error checking to make sure it doesn't 'crash' on you.

Resizes the image 1.25x. This enables it to better 'read' the characters.

Removed the cursor from the capture.

Removed the ridiculously long white-space at the end of the OCR'd text.

Credits go to Ronriel. I just made it work better :mellow:

szhlopp i have one problem....i have installed microsoft office 2007 ultimate and windows xp sp2

when i try to open file(image) i got this tooltray "Error. OCR could not 'read' any characters."

if i go to start menu/all programs/Microsoft Office/Microsoft Office Tools i have Microsoft Office Document Imaging and it's work awesome

but when i try to use your script non result:|

i try all script from here and no one work:(( what it's wrong in this???

i check the reg file and i don't have MODI.Document

is this the problem???how i can fix it???

tnx

Link to comment
Share on other sites

szhlopp i have one problem....i have installed microsoft office 2007 ultimate and windows xp sp2

when i try to open file(image) i got this tooltray "Error. OCR could not 'read' any characters."

if i go to start menu/all programs/Microsoft Office/Microsoft Office Tools i have Microsoft Office Document Imaging and it's work awesome

but when i try to use your script non result:|

i try all script from here and no one work:(( what it's wrong in this???

i check the reg file and i don't have MODI.Document

is this the problem???how i can fix it???

tnx

Yep it is.

Control Panel>Change/remove software>MS office>Modify. Go through the screens and enable OCR :mellow:

Link to comment
Share on other sites

Yep it is.

Control Panel>Change/remove software>MS office>Modify. Go through the screens and enable OCR :mellow:

i don't know wth it's wrong but i have installed ocr files and still don't work:((

i don't know if it's this but i install all from microsoft office 2007 and nothing:|

this is the option for ocr???

Posted ImagePosted Image

here it's the screen from regedit modi

Posted Image

any ideea what it's wrong??? i still get traytip "Error. OCR could not 'read' any characters."

wow...now i try section read...that's work...but if i try image read didn't work and i scan on scanner some page from one workshop and nothing:| it's only text over there no images

Edited by Kyme
Link to comment
Share on other sites

i don't know wth it's wrong but i have installed ocr files and still don't work:((

i don't know if it's this but i install all from microsoft office 2007 and nothing:|

this is the option for ocr???

Posted ImagePosted Image

here it's the screen from regedit modi

Posted Image

any ideea what it's wrong??? i still get traytip "Error. OCR could not 'read' any characters."

wow...now i try section read...that's work...but if i try image read didn't work and i scan on scanner some page from one workshop and nothing:| it's only text over there no images

That error message is the ONE and ONLY error you get. if anything is wrong you get that error.

And yes, you do apparently have OCR installed on your computer.

Link to comment
Share on other sites

That error message is the ONE and ONLY error you get. if anything is wrong you get that error.

And yes, you do apparently have OCR installed on your computer.

now i get what's the problem...when i scan the page whit scanner the paper was unlinear and the script was unable to scan it:|

it's work but not with all text

i have one question...it is posible to make the script to be able to read images like this???

Posted Image

don't think i will use it for bots for forums or some like that...i am silkroad player and this will be awesome solution to pass the verification image behind the login screen

tnx

Link to comment
Share on other sites

  • 7 years later...
  • Moderators

JonyGreen,

if you absolutely MUST reply to an 8 year old thread just to say "thanks" then at least please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - repeating the post just pads the thread unnecessarily.

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 years later...
On 9/18/2008 at 10:46 AM, ronriel said:

Hi, This can be quite useful.

 

This little script lets you select any part of the screen, use OCR to read for texts,and then store them in the clipboard.

You may also select image files directly and read texts in them.

 

Just Press ALT+Q to start.

 

 

 

 

UPDATE:

*OCR script now tries to detect line breaks. OCR'd text will now be pasted with @CRLFS.

*Removed the cursor from the captured image.

 

 

;r-OCR
;By: ronriel

;updated oct. 20, 2008
;autoit-v3.2.12.1
;Tested  Windows XP SP2 with MS Office 2007

#Include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>

_Singleton("script",0)
Opt("GUIOnEventMode",1)
Opt("WinTitleMatchMode", 4)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
HotKeySet("!q","ShowWin")

Local $err = ObjEvent("AutoIt.Error","Error")

$GUI = GUICreate("", 90, 40,-1,-1,0x80880000,$WS_EX_TOOLWINDOW)
WinSetTrans($GUI,'',200)
$B1 = GUICtrlCreateButton("Read Region", 0, 0, 90, 20)
GUICtrlSetBkColor(-1,0xe6e6fa)
GUICtrlSetOnEvent(-1,"Capture")
$B2 = GUICtrlCreateButton("Read File", 0, 20, 90, 20)
GUICtrlSetBkColor(-1,0xe6e6fa)
GUICtrlSetOnEvent(-1,"Capture")

$GUI2 =  GUICreate("", 0 , 0 , 0, 0,  BitOR($WS_POPUP,$WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xe6e6fa,$GUI2)
WinSetTrans($GUI2,'',60)
GUISetState(@SW_HIDE)

$GUI3 = GUICreate("", 0 , 0 , 0,0 ,  BitOR($WS_POPUP,$WS_BORDER), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0xFF0000,$GUI3)
GUISetState(@SW_HIDE)

TrayCreateItem("Info")
TrayItemSetOnEvent(-1,'Ex')
$Exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,'Ex')
TraySetState()

Func ShowWin()
    If BitAND(WinGetState($GUI),2) Then
        GUISetState(@SW_HIDE,$GUI)
    Else
        $Mpos = MouseGetPos()
        WinMove($GUI,'',$Mpos[0]-45,$Mpos[1]-10)
        GUISetState(@SW_SHOW,$GUI)
    EndIf
EndFunc

Func Capture()
    Local $Image = @TempDir&"\ScreenCapture.png", $v = 0

    If @GUI_CtrlId = $B1 Then
        GUISetState(@SW_HIDE,$GUI)
        GUISetState(@SW_SHOW,$GUI3)
        Do
            Sleep(10)
            ToolTip("Read Region")
            $c = MouseGetPos()
            WinMove($GUI3,"",$c[0]-2.5,$c[1]-2.5,5,5)
            If _IsPressed(01) Then
                ToolTip('')
                $C1 = MouseGetPos()
                    Do
                        Sleep(10)
                        $C2 = MouseGetPos()
                            If $C2[0] <> $C1[0] And $C2[1] <> $C1[1] Then 
                                GUISetState(@SW_SHOW,$GUI2)
                            EndIf
                            If $C1[0] < $C2[0] Then 
                                $X = $C1[0]
                                $W = $C2[0] - $C1[0]
                            Else
                                $X = $C2[0]
                                $W = $C1[0] - $C2[0]
                            EndIf
                            If $C1[1] < $C2[1] Then 
                                $Y = $C1[1]
                                $H = $C2[1] - $C1[1]
                            Else
                                $Y = $C2[1]
                                $H = $C1[1] - $C2[1]
                            EndIf
                        WinMove($GUI2,"",$X,$Y,$W,$H)
                        WinMove($GUI3,"",$c2[0]-2.5,$c2[1]-2.5,5,5)
                    Until Not _IsPressed(01)
                $v = 1
            EndIf
        Until $v = 1
        GUISetState(@SW_HIDE,$GUI2)
        GUISetState(@SW_HIDE,$GUI3)
        _ScreenCapture_Capture($Image,$x,$y,$x+$W,$y+$h,False)
    ElseIf @GUI_CtrlId = $B2 Then
        GUISetState(@SW_HIDE,$GUI)
        $Image = FileOpenDialog("Choose an Image File",@DesktopDir&"\","Images (*.jpg;*.bmp;*.gif;*.png;*.tif)")
        if @error then Return
    EndIf
    $OCR = OCR($Image)
    If @error then Return
    ClipPut($OCR)
    TrayTip("Info","Text saved to Clipboard",2,1)
EndFunc
    
Func OCR($Image)
    Local  $y = 0, $string
    
    $miDoc = ObjCreate("MODI.Document")
    $miDoc.Create($Image)
    If @error Then Return SetError(1)
    
    $miDoc.Ocr(9, True, True);language is English
    If @error Then  
        TrayTip("Info","OCR could not read any character.",2,1)
        ClipPut("Error!")
        Return SetError(1)
    EndIf

    For $Word In $miDoc.Images(0).Layout.Words
        $delim = ' '
        If $miDoc.Images(0).Layout.Words($y).Rects(0).Bottom < $miDoc.Images(0).Layout.Words($y+1).Rects(0).Top Then $delim = @CRLF
        $string &= $Word.text & $delim
        $y += 1
    Next
Return StringTrimRight($string,1)
EndFunc

Func Error()
Endfunc

Func Ex()
    If @TRAY_ID = $Exit Then 
        Exit
    Else
        MsgBox(0,"Info", "Press ALT+Q to start."&@CRLF&@CRLF&"r-OCR"&@CRLF&"By: ronriel (ronriel@yahoo.com)")
    EndIf
EndFunc

While 1
Sleep(100000)
WEnd

 

Hi! It is great peace of code! 

The problem is that I have office 2019 and this "Document Imaging" is no longer provided from Microsoft. I've tried to install it but with no success. Now is not possible to use MODI.Document as object :( 

I'have installed Optical Character Recognition(OCR) from Office Tools, Microsoft SharePoint Designer , but still can't make it work :(

Can you help me? Thank you!

 

 

 

 

 

 

Good Luck!

 

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...