Last modified: May 17, 2011
Contents
For using the toolkit from the Gamera GUI, a Menu is added. After importing the toolkit you can get a image by selecting the menu item. If there is more than one single driver installed the following dialogue will be displayed for selecting one of the installed drivers.
After selecting the driver you can set the parameters for taking a image.
This takes a single frame from the webcam. width and height have to be proportional to the native resolution of the camera.
- Width is width of the resulting image.
- Height is height of the resulting image.
- Camera is the device which the image is taken from.
- Wait is the number of images taken every 200 ms before the image is imported. This can be useful for cameras which take some time to focus.
The toolkit can be used as shown in following example. For full documentation see the Webcam class documentation
This example simply saves a single frame from the first webcam.
from gamera.core import *
init_gamera()
import gamera.toolkits.webcam as wtk #shorter name for toolkit
cam = wtk.Webcam()
dev = cam.getDevices()
if len(dev) == 0:
print "no device found"
exit(1)
#select first device
selected_device = dev[0]
print "Selected device: %s" % selected_device
cam.initSession(640,480,selected_device)
#get RGB image from Webcam
img = cam.snapshotFromWebcam()
cam.closeSession()
#now you could do everything with this image
img.save_PNG("test.png")
This example shows how to select a webcam driver.
import gamera.toolkits.webcam as wtk
# get a list of available drivers
drivers = wtk.Drivers()
# create a webcam instance with the first available driver
if len(drivers) > 0:
cam = wtk.Webcam(drivers[0])