A Win32 Python Extension for Accessing Video Devices (e.g. a USB WebCam, a TV-Card, ...)
by Markus Gritsch ()
I would like to put together a list of
Python-powered WebCam URLs, so please send me an email with the URL of
the plain image or the URL of the HTML page if you use
VideoCapture.
PIL version 1.1.2 and below shows a memory
leak when using .gif fonts. Remove the files 'helvB08.gif' and
'helvetica-10.gif' in the Lib folder of your Python installation if you
have used a version of VideoCapture prior to 0.7!!
[ VideoCapture-0.9-5.zip
]
binaries, sourcecode, examples, and batteries included - no
warranty, no liability, provided 'as is'
A stand-alone binary of the included GUI tool 'webcam-watcher' is
available
here.
VideoCapture is a Python extension
for Win32 which makes it possible to access video-capture devices (e.g.
a USB webcam). It consists of a low-level native module (vidcap.pyd)
and a high-level module written in Python (VideoCapture.py) which
should be used solely.
Also included are some tools which can be used to periodically upload a
WebCam-image to a WebServer, monitor and save a picture at a given URL
to the local disk, and so on. Please refer to the README.txt file in
the 'Tools' folder for further details.
Here is a list of VideoCapture-powered WebCams:
Beside Python and the
VideoCapture module itself, you will need the following additional
components:
-
The low-level module uses DirectShow which is already included in
DirectX 8.0 and higher. If you don't have DirectShow, download DirectX
from Microsoft and install it. Windows XP has DirectX included.
-
The high-level module needs PIL to produce actual images from the
pixel-data. PIL
can be downloaded from PythonWare.
-
(optionally) If you want to use 'scp' as the transfer method in
webcam-uploader.py, you need either scp2.exe, which is included in
the installer available from SSH, or pscp.exe, which is
available bundled or separately at the PuTTY
homepage.
To make use of VideoCapture just copy the files from the 'PythonXX'
folder to the corresponding folders of your 'PythonXX' installation,
where XX must match with the version of Python you have installed on
your system.
Taking a snapshot is as easy as
from VideoCapture import Device
cam = Device()
cam.saveSnapshot('image.jpg')
-
The 'Examples' folder contains simple examples which show how easy
it is to obtain images from a video device by using VideoCapture.
Refer to 'exa2_show-possibilities.py' for further details on
additional options available.
-
Look at the module
documentation for in-depth information.
-
setResolution() probably does not work on Devices where the
resolution is set in the CaptureFilterProperties.
-
Some TV-cards forget the tuner (channel) settings after
TV-application termination, so VideoCapture should provide a method
to display the tuner's property page.
If you want to acquire pictures from a scanner or a digital camera
which supports the TWAIN protocol you can use Kevin Gill's excellent twainmodule.
(01.03.2012) Version 0.9-5
-
Added a new function to vidcapmodule.cpp to obtain the Windows
"friendly name" (e.g. "Microsoft Lifecam VX-4000") for an instantiated
device. Contributed by Jeremy Mortis.
(15.04.2011) Version 0.9-4
-
Included a precompiled binary of the low level module linked
against Python 2.7 64-bit contributed by Jurriaan Schreuder.
(04.10.2010) Version 0.9-3
-
Included a precompiled binary of the low level module linked
against Python 2.7 contributed by Chris Spencer.
(30.11.2008) Version 0.9-2
-
Included a precompiled binary of the low level module linked
against Python 2.6 contributed by Jim Gasbarro.
(8.1.2007) Version 0.9-1
-
Included a precompiled binary of the low level module linked
against Python 2.5.
(27.8.2005) Version 0.9
-
Jonathan Viney fixed a bug which had the potential of leading to
a crash when using the module without a camera connected.
-
Included a precompiled binary of the low level module linked
against Python 2.4.
(8.10.2003) Version 0.8
-
Added module documentation.
-
Moved project to SourceForge.net.
-
Included a precompiled binary of the low level module linked
against Python 2.3.
-
Incorporated stand-alone webservers from Don Garrett and Don Kimber
(Tools\3rdParty). The pushserver from Don Kimber is quite
interesting. Now I can watch TV in a Mozilla window with 25 fps
:-)
-
Added setResolution() method contributed by Don Kimber. (Probably
works only on devices which have the resolution specified in the
CapturePinProperties.)
-
Don Kimber fixed a small but serious inconsistency in
displayCapturePinProperties() with sometimes resulted in a
seg-fault.
(4.3.2002) Version 0.7
-
Replaced the .gif fonts by .png fonts, since PIL version 1.1.2 and
below shows a memory leak when using .gif fonts. Remove the files
'helvB08.gif' and 'helvetica-10.gif' in the Lib folder of your
Python installation if you have used a version of VideoCapture
prior to 0.7!!
-
Replaced displayPropertyPage() by displayCaptureFilterProperties()
and displayCapturePinProperties(). This finally allows selecting
things like the video size used during capturing for every kind of
device-drivers (now also for WDM drivers, previously only for VfW
drivers).
-
Since there were some memory-leak issues with some device drivers
when the filter graph was started and stopped for each capture, the
graph is now continuously running. Beside solving the memory issue
this has the big advantage, that taking snapshots is *really* fast
now. Taking 10 and more snapshots per second is no problem :-)
-
scp can now also be performed with the pscp.exe program found in
the PuTTY distribution.
-
Fixed a minor memory leak by freeing MediaType.pbFormat.
-
Added the DirectShow AMCAP utility which can be used to check
whether the capture device is compatible with VideoCapture.
(20.2.2002) Version 0.6
-
Included a precompiled binary of the low level module linked
against Python 2.2.
-
Put a stand-alone executable of the GUI program 'webcam-watcher' on
the webpage.
-
Added scp as an additional upload method for webcam-uploader
(additionally to ftp).
-
Other minor enhancements to all the programs in the 'Tools' folder.
-
The displayPropertyPage() dialog is displayed on top of all other
windows.
-
The filtergraph is rebuild after calling displayPropertyPage().
(08.12.2001) Version 0.5
-
Changed the filtergraph initialization to use the capture-pin
instead of the preview-pin of the video device filter.
This should resolve a strange timeout problem and it even allows me
to capture snapshots from my TV-card :-)
-
Added a method displayPropertyPage() to the Device class which
displays a dialog-box containing the property pages of the capture
device. This should allow selecting things like the video size
used during capturing.
(10.7.2001) Version 0.4
-
Added a PyQt based program which periodically retrieves a picture
from the web and displays it in a GUI window.
-
Several enhancements to webcam-uploader. Now also a HTML file
which displays the uploaded image and periodically reloads itself
is placed together with the image on the WebServer.
(28.6.2001) Version 0.3
-
Included a precompiled binary of the low level module linked
against Python 2.1 (in addition to the one which was already there
for Python 2.0).
-
Added a tool to periodically upload a WebCam-image to a WebServer
via FTP.
-
Added a tool to monitor (and save in case of a change) a Picture
located at a given URL.
-
More than one Device instance can be held open at the same time.
-
The location of the timestamp in the image is selectable.
(24.6.2001) Version 0.2
-
Added extensive error checking after every system call. In case
something goes wrong an exception is raised.
-
Some enhancements to the high level interface like selectable
fontstyle, various shadow modes for better font legibility.
-
The video-device that should be used can be specified.
(18.6.2001) Version 0.1
-
Initial release.
Have fun!