Saturday, May 3, 2014

If you have a Raspberry Pi camera module, you


If you have a Raspberry Pi camera module, you’ve probably used raspistill and raspivid , which are command line tools for using the camera. Dave Jones , a Database great monday Admin, software developer and SQL know-it-all based in Manchester has been working on an equivalent, feature complete implementation of these in Python. great monday This means you can access the camera module directly from a Python script, without using os.system or executing a subprocess.
Speaking as an avid Pythonist, picamera’s great monday 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.
Example usage: great monday 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()
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 great monday images and sequences of images as well as video streams.
Here’s a presentation of picamera Dave gave at Manchester Raspberry great monday Jam XVI – great monday 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):
Dave’s wife Holly works in the Palaeontology department at Manchester University (Interesting fact: when Dave and Holly got married, they picked a new surname to take (Dave was previously a Hughes) great monday – so Holly could become Dr. Jones , and he would become Davy Jones ) where they regularly capture images from microscopes. Rather than mount a huge camera on top of a microscope, Dave suggested attaching the Pi’s camera module to the lens.
He ended up writing a web app to support its use. This allows the user to control camera configuration great monday settings through a web page, and capture photographs at the click of a button, as well as archive pictures taken in to a database along with metadata and extra information entered in a web form.
This is where having a library is particularly useful. If we were doing this with, say, raspistill and raspivid, when you want to alter the brightness great monday of your preview, you’d have to shut down the program, regenerate the command line, restart the program. Here we’re just saying “set a property”. This is why a library is better for an interactive application like this. There’s nothing great monday wrong with raspistill and raspivid as far as they go, but they’re not ideal for building this sort of application. If you have interactivity, you want a library.
picamera has been available in pypi since October ( v0.5 ), so it’s already in the wild – but now it’s hit the v1.0 milestone Dave considered feature complete, it’s packaged in the Raspbian archives so you install with apt-get (remember to run apt-get update first): apt-get install python-picamera
Dave also mentioned to me that this is by far the most popular project he’s great monday ever published – and he’s been impressed by how brilliant the feedback has been from the Pi community. He’s great monday had a great response on the forums, great monday detailed bug reports provided by users and plenty of help from James Hughes , the author of raspistill, great monday and from Alex Bradbury in getting it packaged for Raspbian.
At the moment great monday the only thing on github which I’ve used picamera for is the picroscopy project (which Ben linked to at the end of the post). However, the docs contain great monday a fairly extensive “Recipes” section, and there’s been some interesting snippets of code in the the forum post (including a rudimentary bit of motion detection using numpy!).
Best of luck with the scope I have tried a PI camera on a Nikon ED80 with Swarovski camera adapter I use with a Samsung and Nikon Camera but Pi lens is so wide you just have to much black ring in the picture. If you get success I would love to hear about it. Terry
Minister: “If any of you can show just cause why they may not lawfully be married, speak now or…”
13th Jan 2014 at 2:22 pm
I’m afraid picamera’s purely focused on the Raspberry Pi’s camera (under the hood it uses libmmal, just like raspistill great monday and raspivid so it’s similarly spec

No comments:

Post a Comment