Using the Viewfinder
Taking a good photo is difficult if you get no visual feedback for aimingthe camera. For this purpose, the viewfinder, like the one shown in
Figure 5.8, produces a stream of Image objects that are produced by the
camera in real-time. It is up to you what to do with these images, but
typically you want to show them on the canvas, to help the user aim the
camera properly.
Example 34: Viewfinder
import camera, appuifw, e32
def viewfinder(img):
img.point((100, 100), outline = (255, 0, 0), width = 10)
canvas.blit(img)
def quit():
camera.stop_finder()
lock.signal()
appuifw.app.body = canvas = appuifw.Canvas()
appuifw.app.exit_key_handler = quit
camera.start_finder(viewfinder)
lock = e32.Ao_lock()
lock.wait()
The function camera.start viewfinder() takes a single parameter,
a callback function that handles the incoming images. In this case,
the job is handled by the function viewfinder. To convince you that
the viewfinder images are just normal Image objects, we draw a small
red dot on each image before showing it on the canvas.
The camera.start viewfinder() function accepts two optional
parameters besides the callback function:
• backlight defines whether the device backlight is kept on when
the camera viewfinder is in operation. backlight = 1 makes it on,
which is the default, and 0 off.
• size defines the viewfinder image size, as in size = (176, 144).
It is important to stop the viewfinder, using the camera.stop
finder() function, once you do not need it, otherwise it may keep the
camera busy in the background and drain the battery quickly.
No comments:
Post a Comment