If you have a Raspberry Pi camera module, you’ve probably used
which are command line tools for using the camera. Dave Jones, a Database Admin, software developer and SQL know-it-all based in Manchester has been working on an equivalent,
feature complete implementation of these in Python. This means you can access the camera module directly from a Python script, without using
executing a subprocess.
Speaking as an avid Pythonist, picamera’s implementation is beautiful and it really is a wonderful library to use. It works really well for demonstrations using the Pi camera, and for real world applications. Part of the appeal of the Raspberry Pi
is that you can work on embedded electronics projects without needing to know low-level languages or have to program a microprocessor – instead you have the choice of a range of accessible high-level languages such as Python – and this is an extension of that
kind of abstraction, which open up a world of possibilities to a wider diversity of makers.
import picamera from time import sleep camera = picamera.PiCamera() camera.capture('image.jpg') camera.start_preview() camera.vflip = True camera.hflip = True camera.brightness = 60 camera.start_recording('video.h264') sleep(5) camera.stop_recording()
Also you can do things like this:
for i in range(100): camera.brightness = i sleep(0.1)
and watch the preview flow through the brightness levels.
The library has many configurations – you can change the brightness, contrast, saturation, image effects, exposure modes and such, as well as optionally show a live preview of the camera’s view. You can capture single images and sequences of images as well
as video streams.
Here’s a presentation of picamera Dave gave at Manchester Raspberry Jam XVI – where he demonstrates the basic usage of the module by typing commands in to a Python
prompt on his laptop, with a monitor displaying the camera output (unfortunately out of shot in the video):