Jump to content

Take screendumps with minicap.exe


trids
 Share

Recommended Posts

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.

;
;
;   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
Endfunc

Have fun!

:P

Link to comment
Share on other sites

  • 2 months later...

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

  • Moderators

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

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 by JPeters
Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...

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

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