trids Posted August 8, 2007 Share Posted August 8, 2007 Have you ever wanted to capture a portion of the screen with AU3, maybe just a window? Well here's a handy little utility that does it via the commandline .. minicap. And it's FREE!Very neat, many options to meet your custom needs: download here.But wait! There's more .. here is an example of how to use it. Plus for free it does an OCR of the screen capture, using ptrex's recent discovery!Before you run the script below, startup an instance of Notepad and type in some text that you want to be OCR-ed. Experiment with different fonts and font sizes.expandcollapse popup; ; ; minicap_au3.exe .. automation of minicap.exe (screen capture commandline utility) ; -> http://www.softpedia.com/get/Multimedia/Graphic/Graphic-Capture/MiniCap.shtml ; Global $oMyError = ObjEvent("AutoIt.Error","_OCRErrFunc") ;Dependencies FileInstall( "D:\_#WWW\MiniCap - 1.08.02\MiniCap\MiniCap.exe", @SYSTEMDIR & "\" ) ;Wait for the window so that we capture it $sTargetImage = "D:\My OCR\OCR_tgt.gif" $sTargetTitle = "Untitled - Notepad" WinWaitActive( $sTargetTitle ) #cs -------------------------------------------------------------------------------- ;Capture the target by PID $nPID = WinGetProcess( $sTargetTitle ) $sSwitches = ' -save "' & $sTargetImage & '"' $sSwitches &= ' -capturepid ' & $nPID $sSwitches &= ' -exit' RunWait( @COMSPEC & ' /c minicap.exe ' & $sSwitches, "", @SW_HIDE) -------------------------------------------------------------------------------- #ce ;Capture the target by position $aPos = WinGetPos( $sTargetTitle ) $sSwitches = ' -save "' & $sTargetImage & '"' $sSwitches &= ' -captureregion ' & $aPos[0] & ' ' & $aPos[1] & ' ' & $aPos[2] + $aPos[0] -1 & ' ' & $aPos[3] + $aPos[1] -1 $sSwitches &= ' -exit' RunWait( @COMSPEC & ' /c minicap.exe ' & $sSwitches, "", @SW_HIDE) ;Now lets do something with the saved image .. ;.. like OCR it and see what it says $sTargetText = _OCRGetText( $sTargetImage ) ;Display the results Msgbox( 0, @SCRIPTNAME, "Results of OCR:" & @LF & $sTargetText ) Func _OCRGetText( $Image ) Local $oDoc = ObjCreate("MODI.Document") $oDoc.Create($Image) If @ERROR Then Return SetError(1) $oDoc.Ocr(9, True, False) ;ENGLISH = 9 If @ERROR Then Return SetError(2) Return $oDoc.Images(0).Layout.Text $oDoc = 0 EndFunc Func _OCRErrFunc() $HexNumber = hex($oMyError.number, 8) Msgbox(0, @SCRIPTNAME,"We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext) SetError(1) ; to check for after this function returns EndfuncHave fun! Link to comment Share on other sites More sharing options...
ptrex Posted August 8, 2007 Share Posted August 8, 2007 @trids Great stuff !! I like small commandline tools a lot. Perfect marriage between the MiniCap and the OCR. Thanks for sharing. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
JPeters Posted November 5, 2007 Share Posted November 5, 2007 This looks like it'll help me a lot with a project I'm working on. I'm trying to get it working with the Notepad example, but I'm getting an error on line 45: $oDoc.Ocr(9, True, False) ;ENGLISH = 9 The error I'm getting is: We intercepted a COM Error ! err.description is: OCR running error err.windescription: □□□□□□□□□□□□□□□ err.number is: 80020009 err.lastdllerror is: 0 err.scriptline is: 45 err.source is: err.helpfile is: err.helpcontext is: 0 The interaction with Minicap seems to be working fine, as there is a capture of Notepad in the location I specified. I do have the MODI registry entries and Program Files directory mentioned in ptrex's thread. Any idea how to fix this error? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 5, 2007 Moderators Share Posted November 5, 2007 Just curious why you'd use this and not mod the _Screen_Capture.au3 to do a portion of the screen and save to file? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
JPeters Posted November 6, 2007 Share Posted November 6, 2007 (edited) Just curious why you'd use this and not mod the _Screen_Capture.au3 to do a portion of the screen and save to file?Wanders off to look at _Screen_Capture.au3...Incidentally, I think I traced the issue I was having before to Minicap saving the screenshot as too small of an image. Taking a screenshot manually and using ptrex's code works for me. Perhaps I can use _Screen_Capture.au3 as SmOke_N suggests.EDIT: ...I guess _Screen_Capture.au3 isn't included in the basic AutoIt3 installation? Sorry for being a newb... but where do I find it?EDIT2: Found something along those lines in Auto3Lib. Thanks! Edited November 6, 2007 by JPeters Link to comment Share on other sites More sharing options...
S0789300 Posted January 13, 2009 Share Posted January 13, 2009 Wanders off to look at _Screen_Capture.au3...Where can I find _Screen_Capture.au3? Link to comment Share on other sites More sharing options...
Developers Jos Posted January 13, 2009 Developers Share Posted January 13, 2009 Did you try the Helpfile ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
S0789300 Posted September 20, 2009 Share Posted September 20, 2009 Ok I got this puppy working a while ago and I got a screenshot rolling. However, sometimes when I MODI the image I have taken, if the words or numbers its trying to OCR is along the edge of the image, it has issues with accuracy. It seems that MODI has a border around it in which it cannot read -- anyone know of a quick fix for this? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now