Sign in to follow this  
Followers 0
Creator

Windows Image Acquisition Automation

7 posts in this topic

#1 ·  Posted (edited)

I made a start with reading about WIA (Windows Image Acquisition) and digging through some sample sdk stuff.

It should become an udf for easely acquiring media throug scanner, photocamera, webcam etc...

It comes in paticularly handy with the ocr script from ptrex:

http://www.autoitscript.com/forum/index.ph...0608&hl=ocr :)

Its just the first few bits of code and more is to come (scanning to tif works anywayz :P )

You think this is worth the effort to devellop, or is this doomed to end up being used by ... well.. erhm..just me? ;)

WIA is supposed to be supported by minimal Windows XP SP1. The script uses wiaaut.dll which should be in system32. If not, the dll is attached. Copy it to system32 and register it with regsvr32.

Let me know what you think.

Creator

#cs ----------------------------------------------------------------------------

Just the beginning of an WIA udf.
Minimun OS: Windows XP SP1 (WIA Supported)

Author: Creator
Description: An udf for image acquisition(scanner, photocamera, webcam etc..)
Note: Device must me on to prevent error messages (or you can handle device errors to supress them ;-) )

#ce ----------------------------------------------------------------------------


; FormatID

Global Const $wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatGIF = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Global Const $wiaFormatTIFF = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"

; EventID

Global Const $wiaEventDeviceConnected = "{A28BBADE-64B6-11D2-A231-00C04FA31809}"
Global Const $wiaEventDeviceDisconnected = "{143E4E83-6497-11D2-A231-00C04FA31809}"
Global Const $wiaEventItemCreated = "{4C8F4EF5-E14F-11D2-B326-00C04F68CE61}"
Global Const $wiaEventItemDeleted = "{1D22A559-E14F-11D2-B326-00C04F68CE61}"
Global Const $wiaEventScanImage = "{A6C5A715-8C6E-11D2-977A-0000F87A926F}"
Global Const $wiaEventScanPrintImage = "{B441F425-8C6E-11D2-977A-0000F87A926F}"
Global Const $wiaEventScanFaxImage = "{C00EB793-8C6E-11D2-977A-0000F87A926F}"
Global Const $wiaEventScanOCRImage = "{9D095B89-37D6-4877-AFED-62A297DC6DBE}"
Global Const $wiaEventScanEmailImage = "{C686DCEE-54F2-419E-9A27-2FC7F2E98F9E}"
Global Const $wiaEventScanFilmImage = "{9B2B662C-6185-438C-B68B-E39EE25E71CB}"
Global Const $wiaEventScanImage2 = "{FC4767C1-C8B3-48A2-9CFA-2E90CB3D3590}"
Global Const $wiaEventScanImage3 = "{154E27BE-B617-4653-ACC5-0FD7BD4C65CE}"
Global Const $wiaEventScanImage4 = "{A65B704A-7F3C-4447-A75D-8A26DFCA1FDF}"

; CommandID

Global Const $wiaCommandSynchronize = "{9B26B7B2-ACAD-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandTakePicture = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandDeleteAllItems = "{E208C170-ACAD-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandChangeDocument = "{04E725B0-ACAE-11D2-A093-00C04F72DC3C}"
Global Const $wiaCommandUnloadDocument = "{1F3B3D8E-ACAE-11D2-A093-00C04F72DC3C}"

; WiaSubType enumeration

Global Const $UnspecifiedSubType = 0
Global Const $RangeSubType = 1
Global Const $ListSubType = 2
Global Const $FlagSubType = 3

; WiaDeviceType enumeration

Global Const $UnspecifiedDeviceType = 0
Global Const $ScannerDeviceType = 1
Global Const $CameraDeviceType = 2
Global Const $VideoDeviceType = 3

; WiaItemFlag enumeration

Global Const $FreeItemFlag = 0x0
Global Const $ImageItemFlag = 0x01
Global Const $FileItemFlag = 0x02
Global Const $FolderItemFlag = 0x04
Global Const $RootItemFlag = 0x08
Global Const $AnalyzeItemFlag = 0x010
Global Const $AudioItemFlag = 0x020
Global Const $DeviceItemFlag = 0x040
Global Const $DeletedItemFlag = 0x080
Global Const $DisconnectedItemFlag = 0x0100
Global Const $HPanoramaItemFlag = 0x0200
Global Const $VPanoramaItemFlag = 0x0400
Global Const $BurstItemFlag = 0x0800
Global Const $StorageItemFlag = 0x01000
Global Const $TransferItemFlag = 0x02000
Global Const $GeneratedItemFlag = 0x04000
Global Const $HasAttachmentsItemFlag = 0x08000
Global Const $VideoItemFlag = 0x010000
Global Const $RemovedItemFlag = 0x80000000

; WiaPropertyType enumeration

Global Const $UnsupportedPropertyType = 0
Global Const $BooleanPropertyType = 1
Global Const $BytePropertyType = 2
Global Const $IntegerPropertyType = 3
Global Const $UnsignedIntegerPropertyType = 4
Global Const $LongPropertyType = 5
Global Const $UnsignedLongPropertyType = 6
Global Const $ErrorCodePropertyType = 7
Global Const $LargeIntegerPropertyType = 8
Global Const $UnsignedLargeIntegerPropertyType = 9
Global Const $SinglePropertyType = 10
Global Const $DoublePropertyType = 11
Global Const $CurrencyPropertyType = 12
Global Const $DatePropertyType = 13
Global Const $FileTimePropertyType = 14
Global Const $ClassIDPropertyType = 15
Global Const $StringPropertyType = 16
Global Const $ObjectPropertyType = 17
Global Const $HandlePropertyType = 18
Global Const $VariantPropertyType = 19
Global Const $VectorOfBooleansPropertyType = 101
Global Const $VectorOfBytesPropertyType = 102
Global Const $VectorOfIntegersPropertyType = 103
Global Const $VectorOfUnsignedIntegersPropertyType = 104
Global Const $VectorOfLongsPropertyType = 105
Global Const $VectorOfUnsignedLongsPropertyType = 106
Global Const $VectorOfErrorCodesPropertyType = 107
Global Const $VectorOfLargeIntegersPropertyType = 108
Global Const $VectorOfUnsignedLargeIntegersPropertyType = 109
Global Const $VectorOfSinglesPropertyType = 110
Global Const $VectorOfDoublesPropertyType = 111
Global Const $VectorOfCurrenciesPropertyType = 112
Global Const $VectorOfDatesPropertyType = 113
Global Const $VectorOfFileTimesPropertyType = 114
Global Const $VectorOfClassIDsPropertyType = 115
Global Const $VectorOfStringsPropertyType = 116
Global Const $VectorOfVariantsPropertyType = 119

; WiaImagePropertyType enumeration

Global Const $UndefinedImagePropertyType = 1000
Global Const $ByteImagePropertyType = 1001
Global Const $StringImagePropertyType = 1002
Global Const $UnsignedIntegerImagePropertyType = 1003
Global Const $LongImagePropertyType = 1004
Global Const $UnsignedLongImagePropertyType = 1005
Global Const $RationalImagePropertyType = 1006
Global Const $UnsignedRationalImagePropertyType = 1007
Global Const $VectorOfUndefinedImagePropertyType = 1100
Global Const $VectorOfBytesImagePropertyType = 1101
Global Const $VectorOfUnsignedIntegersImagePropertyType = 1102
Global Const $VectorOfLongsImagePropertyType = 1103
Global Const $VectorOfUnsignedLongsImagePropertyType = 1104
Global Const $VectorOfRationalsImagePropertyType = 1105
Global Const $VectorOfUnsignedRationalsImagePropertyType = 1106

; WiaEventFlag enumeration

Global Const $NotificationEvent = 1
Global Const $ActionEvent = 2

; WiaImageIntent enumeration

Global Const $UnspecifiedIntent = 0
Global Const $ColorIntent = 1
Global Const $GrayscaleIntent = 2
Global Const $TextIntent = 4

; WiaImageBias enumeration

Global Const $MinimizeSize = 65536
Global Const $MaximizeQuality = 131072




; Example start: Opens default image acquisition software for input and saves to tempfolder\scan.tif

$COMerror = ObjEvent("AutoIt.Error","MyErrFunc")

$wiaDev = ObjCreate("WIA.DeviceManager") ;not used yet
$wiaDlg = ObjCreate("WIA.CommonDialog")
$IP = ObjCreate( "Wia.ImageProcess")
$wiaImg = ObjCreate( "Wia.ImageFile")

$wiaImg = $wiaDlg.ShowAcquireImage

$IP.Filters.Add($IP.FilterInfos("Convert").FilterID)
$IP.Filters(1).Properties("FormatID").Value = $wiaFormatTIFF
$wiaImg = $IP.Apply($wiaImg)

$wiaImg.SaveFile(@TempDir & "\scan.tif")

Func MyErrFunc()
  $HexNumber=hex($COMerror.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $COMerror.description    & @CRLF & _
             "err.windescription:"     & @TAB & $COMerror.windescription & @CRLF & _
             "err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $COMerror.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $COMerror.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $COMerror.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $COMerror.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $COMerror.helpcontext _
            )
  SetError(1)  
Endfunc


;Example end

wiaaut.dll

Edited by Creator

Share this post


Link to post
Share on other sites

looks nice i'll try it out when i have time!


[center][/center]

Share this post


Link to post
Share on other sites

looks nice i'll try it out when i have time!

Cool. Let me know if you think this can be usefull :)

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

@Creator

This looks promising, but it throws Errors on me ?!

Lines 168, 172, 174

I have a Multifunctional printer / scanners connected over the network on my PC.

But it does not seems to like this type of device.

regards,

ptrex

Hmmm... looks like .ShowAcquireImage is not doing its job.

That example fires up the default "scan gui" which (correct me if im wrong) is not installed when only using networkprinterdrivers.

I myself have a multifunctional HP and have the HP printer software suite installed and it fires up here.

Ill try to add a device picker combo and a more direct way to scan (directly). Then the network printer should work (i hope :) )

Actually i was already working on it, but i wanted to make sure there would be some people who find it usefull out there. Ill try to speed up the expansion of the example.

Creator

Share this post


Link to post
Share on other sites

This is really great. Especially as the "EZTW32.dll"-solutions wont work for me.

But as this thread is titled "...Automation"  so how can I aquire pictures without the dialog? Just by using the default ( or scripted ) configurations?

 

Thank you very much and keep on going!

best regards 

Blues


My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Oh....ok 2007... maybe Creator is not around here so often. So I encourage the whole community to figure out how one could bypass the dialog to capture an image from the scanner by using windows WIA

 

 

best regards 

 

Blues


My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
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
Sign in to follow this  
Followers 0