Skip to content

Raspberry Pi Camera

firepick1 (localhost) edited this page Oct 23, 2015 · 15 revisions

Pick-and-Place Vision

The 5MP resolution of the Raspberry Pi Camera provides a wealth of information for pick-and-place (PnP) operation. Although humans love video, we will rely on still pictures for pick-and-place. Still pictures provide greater control over the entire imaging process. There is also no need for the motion-tracking capability of video. For this reason we will use:

raspistill

Prerequisites

Before proceeding, you will need:

RAM Disk

We will be processing a lot of images and we want to keep them off the SD card. Lets create a RAM disk with at least 64MB of storage for our images:

sudo mkdir /img
sudo mount -t tmpfs -o 64m tmpfs /img

Parameters

The raspistill program is versatile and we will launch it in continuous, triggered image capture mode using the following command line:

raspistill -w 400 -h 400 -ex snow -awb fluorescent -ev 12 -t 0 -s -o /img/camauto.jpg &
Parameter Description
-w 400 Image width ensures small file size for fast OpenCV processing
-h 400 Image height ensures small file size for fast OpenCV processing
-ex snow Exposure for a predominantly white background (e.g., paper)
-awb ... Fixed white balance for capturing image series (auto is too variable)
-ev 12 Increase exposure for brighter image over auto exposure
-t 0 Continuous picture capture
-s Wait for SIGUSR1 to take a picture
-o ... RAM disk image output file (i.e., /img/camauto.jpg)

Once raspistill is running in the background, we can take a picture using the following simple bash script that sends a signal and waits 300ms for capturing the image, which it renames as /img/img01.jpg:

PID=`ps -C raspistill -o pid=`
kill -SIGUSR1 $PID
sleep 0.3
mv /img/camauto.jpg /img/img01.jpg

The 300ms capture interval accounts for the shutter speed (1-100ms) as well as the JPG compression time. Faster times can be achieved by specifying -ISO 800 and using the Pi camera as a light meter (-set) to determine shutter speed (-ss) for a series of captures. However, 300ms is certainly fast enough for many applications. The method described here is simple to use and works for different camera heights from the bed.

Clone this wiki locally