Tutorial 12: Take a Picture with Pi Camera

The Raspberry Pi Foundation had released two cameras designed to plug directly into the Raspberry Pi board: the regular Pi Camera and the Pi NOIR Camera. In the previous tutorial I showed you how to connect the camera and take a picture with it using Bash commands. In this tutorial I show you how to take pictures using Python 3!

This tutorial is a little older (published in 2015!). The main principles are still relevant, so I haven't needed to update this lesson.


DIFFICULTY
EASY
LINUX UNDERSTANDING
LITTLE
COMPUTER FAMILIARITY
LITTLE
PYTHON PROGRAMMING
SOME
ABOUT
0
MINUTES
  • How to use Python 3 to capture an image with the Pi Camera
You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!


import picamera

# Setup the camera such that it closes
# when we are done with it.
print("About to take a picture.")
with picamera.PiCamera() as camera:
    camera.resolution = (1280,720)
    camera.capture("/home/pi/Desktop/cookie/newimage.jpg")
print("Picture taken.")

If you’re interested in a little more on this topic, check out: