Friday, November 15, 2013

36: Capturing a Grayscale Image with the RasPi Camera

The raspistill command offers at least 30 command line options but no option to capture a grayscale image. There are considerable advantages to that mode for using a Pi as a security camera.

1. All of the BW info is contained in each single 8-bit pixel (looking at the Green value only gives you 70%).
2. The BW image takes up 1/3rd as much RAM and when you save an image to the filesystem the same JPEG quality is 1/10th the size of the RGB image.

Here's my little bw.py program (which assumes you are passing it an RGB file name):

#!/usr/bin/python
import StringIO
from PIL import Image
import sys

a = len(sys.argv)
if a != 2:
print "Usage: bw name.jpg\n"
exit(1)

im = Image.open(sys.argv[1]).convert("L")
file, ext = sys.argv[1].split('.')
im.save(file + 'BW.' + ext, "JPEG")

No comments:

Post a Comment