Prev: python bijection
Next: python and netezza
From: News123 on 22 Nov 2009 12:32 Hi, I'm trying to scan a document from a python 2.6 script without user interaction. I found a code snippet, that allows me to scan under Vista, but that doesn't allow me to select the dpi / color mode / etc. The snippet uses win32com.client # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end My problems are: - This script works fine for me under Windows 7, however I'm unable to specify additional parameters, like dpi and color mode. - The script doesn't work under windows XP, though the scanner driver is installed. (Gimp finds the scanner (as WIA scanner)). Perhaps 'WIA.CommonDialig' has another name or I need to install some DLL. The error message is: -------------------------------------------------------------------- Traceback (most recent call last): File "C:\work\python\minidemos\wia_get_simple.py", line 7, in <module> wia = win32com.client.Dispatch("WIA.CommonDialog") File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Invalid class string', None, None) --------------------------------------------------------------------- As I have no knowledge of Win32com and WIA I would appreciate some help or good documentation about wincom32 / WIA with python thanks for your help and bye N
From: r on 23 Nov 2009 02:18 On Nov 22, 11:32 am, News123 <news...(a)free.fr> wrote: > - This script works fine for me under Windows 7, however I'm > unable to specify additional parameters, like dpi and > color mode. I have found something interesting but have no idea HOW to implement it?? It seems the setting for the scanner are in the registry and must be changed that way or by specifically calling these constants on the device. WIA_IPS_YRES (ScannerPictureYres) Contains the current vertical resolution, in pixels per inch, for the device. An application sets this property to set the vertical resolution. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE or WIA_PROP_LIST WIA_IPS_XRES (ScannerPictureXres) Contains the current horizontal resolution, in pixels per inch, for the device. An application sets this property to set the horizontal resolution. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE or WIA_PROP_LIST WIA_IPS_OPTICAL_XRES (ScannerPictureOpticalXres) Note This property is supported only by Windows Vista and later. Horizontal Optical Resolution. Highest supported horizontal optical resolution in DPI. This property is a single value. This is not a list of all resolutions that can be generated by the device. Rather, this is the resolution of the device's optics. The minidriver creates and maintains this property. This property is required for all items. Type: VT_I4, Access: Read Only, Valid values: WIA_PROP_NONE WIA_IPS_OPTICAL_YRES (ScannerPictureOpticalYres) Note This property is supported only by Windows Vista and later. Vertical Optical Resolution. Highest supported vertical optical resolution in DPI. This property is a single value. This is not a list of all resolutions that are generated by the device. Rather, this is the resolution of the device's optics. The minidriver creates and maintains this property. This property is required for all items.Type: VT_I4, Access: Read Only, Valid values: WIA_PROP_NONE WIA_IPS_BRIGHTNESS (ScannerPictureBrightness) The image brightness values available within the scanner.Contains the current hardware brightness setting for the device. An application sets this property to the hardware's brightness value. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_RANGE WIA_IPS_CONTRAST (ScannerPictureContrast) Contains the current hardware contrast setting for a device. An application sets this property to the hardware's contrast value. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_RANGE WIA_IPS_ORIENTATION (ScannerPictureOrientation) Specifies the current orientation of the documents to be scanned. The minidriver creates and maintains this property. Type: VT_I4, Access: Read/Write, Valid Values: WIA_PROP_LIST ------------------------ Image Intent Constants ------------------------ Image intent constants specify what type of data the image is meant to represent. The WIA_IPS_CUR_INTENT scanner property uses these flags. To provide an intent, combine an intended image type flag with an intended size/quality flag by using the OR operator. WIA_INTENT_NONE should not be combined with any other flags. Note that an image cannot be both grayscale and color. WIA_INTENT_IMAGE_TYPE_COLOR (ImageTypeColor) WIA_INTENT_IMAGE_TYPE_GRAYSCALE (ImageTypeGrayscale) WIA_INTENT_IMAGE_TYPE_TEXT (ImageTypeText) WIA_INTENT_MINIMIZE_SIZE (MinimizeSize) WIA_INTENT_MAXIMIZE_QUALITY (MaximizeQuality) WIA_INTENT_BEST_PREVIEW (BestPreview)
From: News123 on 23 Nov 2009 03:30 Hi r, r wrote: > On Nov 22, 11:32 am, News123 <news...(a)free.fr> wrote: > >> - This script works fine for me under Windows 7, however I'm >> unable to specify additional parameters, like dpi and >> color mode. > > I have found something interesting but have no idea HOW to implement > it?? It seems the setting for the scanner are in the registry and must > be changed that way or by specifically calling these constants on the > device. > > WIA_IPS_YRES (ScannerPictureYres) > Contains the current vertical resolution, in pixels per inch, for the > device. An application sets this property to set the vertical > resolution. The minidriver creates and maintains this property. Type: > VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE > or WIA_PROP_LIST > This sounds interesting. I do have two questions: 1.) do these entries really have an impact? --------------------------------------------- Did you find out whether changing the resolution or color mode in the registry has really an impact when scanning an image with my python script? 2.) Where are these registry entries? --------------------------------------- Under which windows version did you find these registry entries (XP, Vista or Win7)? I can't locate them, but probably my approach is too naive. I started regedit and searched with CTRL-F for 'WIA_IPS_YRES'. Perhaps these settings are scanner dependant? My current script: # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end bye N
From: News123 on 23 Nov 2009 03:31 Hi r, r wrote: > On Nov 22, 11:32 am, News123 <news...(a)free.fr> wrote: > >> - This script works fine for me under Windows 7, however I'm >> unable to specify additional parameters, like dpi and >> color mode. > > I have found something interesting but have no idea HOW to implement > it?? It seems the setting for the scanner are in the registry and must > be changed that way or by specifically calling these constants on the > device. > > WIA_IPS_YRES (ScannerPictureYres) > Contains the current vertical resolution, in pixels per inch, for the > device. An application sets this property to set the vertical > resolution. The minidriver creates and maintains this property. Type: > VT_I4, Access: Read/Write or Read Only, Valid Values: WIA_PROP_RANGE > or WIA_PROP_LIST > This sounds interesting. I do have two questions: 1.) do these entries really have an impact? --------------------------------------------- Did you find out whether changing the resolution or color mode in the registry has really an impact when scanning an image with my python script? 2.) Where are these registry entries? --------------------------------------- Under which windows version did you find these registry entries (XP, Vista or Win7)? I can't locate them, but probably my approach is too naive. I started regedit and searched with CTRL-F for 'WIA_IPS_YRES'. Perhaps these settings are scanner dependant? My current script: # ##################### script start import win32com.client,os WIA_IMG_FORMAT_PNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" WIA_COMMAND_TAKE_PICTURE = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" os.chdir('c:/temp') wia = win32com.client.Dispatch("WIA.CommonDialog") dev = wia.ShowSelectDevice() for command in dev.Commands: if command.CommandID==WIA_COMMAND_TAKE_PICTURE: foo=dev.ExecuteCommand(WIA_COMMAND_TAKE_PICTURE) i=1 for item in dev.Items: if i==dev.Items.Count: image=item.Transfer(WIA_IMG_FORMAT_PNG) break i=i+1 image.SaveFile("test.png") ######################### script end bye N
From: r on 23 Nov 2009 03:59
more *maybe useful dump? >>> for i in dev.Items: for p in i.Properties: if not p.IsReadOnly: print p.Name, '->', p.Value Color Profile Name -> sRGB Color Space Profile Brightness -> 0 Contrast -> 0 Private Highlight Level -> 0 Private Midtone Level -> 0 Private Shadow Level -> 0 Private Gamma -> 2200 Private Saturation -> 1000 Private Hue X -> 0 Private Hue Y -> 0 Private Sharpen Level -> 3 Threshold -> 55 Horizontal Resolution -> 200 Vertical Resolution -> 200 Horizontal Start Position -> 0 Vertical Start Position -> 0 Horizontal Extent -> 1700 Vertical Extent -> 2338 Current Intent -> 0 Data Type -> 3 Media Type -> 128 Format -> {B96B3CAA-0728-11D3-9D7B-0000F81EF32E} Private Source Depth -> 0 Private Preview -> 0 Private Exposure Method -> 0 Private Smoothing -> 1 Private Color Enhanced -> 0 Private TMA Method -> 0 >>> dev.DeviceID u'{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0000' >>> for p in dev.Properties: print p.Name, '->', p.Value Item Name -> Root Full Item Name -> 0000\Root Item Flags -> 76 Unique Device ID -> {6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\0000 Manufacturer -> Hewlett-Packard Description -> HP Deskjet F300 Type -> 65538 Port -> \\.\Usbscan0 Name -> HP Deskjet F300 Server -> local Remote Device ID -> UI Class ID -> {0A8DC120-D685-4247-9CD1-8712F6BB2DED} Hardware Configuration -> 0 BaudRate -> STI Generic Capabilities -> 48 WIA Version -> 2.0 Driver Version -> 0.0.0.216 PnP ID String -> \\?\usb#vid_03f0&pid_5511&mi_00#6&2def7e7&0&0000# {6bdd1fc6-810f-11d0-bec7-08002be2092f} STI Driver Version -> 2 Horizontal Bed Size -> 8500 Vertical Bed Size -> 11690 Horizontal Bed Registration -> 0 Vertical Bed Registration -> 0 Access Rights -> 3 Horizontal Optical Resolution -> 2400 Vertical Optical Resolution -> 2400 Firmware Version -> 1.0.na Max Scan Time -> 500000 Now how to set the values... hmmm? |