How to Capture Images from DSLR using Raspberry Pi and GPhoto2

Photo by Oscar Ivan Esquivel Arteaga on Unsplash

In this short post, I will walk you through the steps for controlling and capturing pictures from a DSLR connected to the Raspberry Pi using a USB cable. There are numerous tutorials out there for this setup but I found them to be outdated to some extent. This post covers the installation of libgphoto2 and ghoto2 from the source and also covers the steps for capturing pictures using Python scripts.


For this tutorial, I am assuming that you have a Raspberry Pi with Raspbian or Noob OS installed on it. You can get a Raspberry Pi from Amazon if you don’t already have one.

Also, I am assuming that you already have one of the supported cameras listed here:

I used the Canon Rebel T7 camera which I got from Amazon.

Install libgphoto2 and gphoto2

libghoto2 library lets you interface with 100s of supported DSLR cameras and ghoto2 is a command-line utility for using libghoto2

Here are the steps for installing both these libraries.

Install the following dependencies:

sudo apt-get install git make autoconf libltdl-dev libusb-dev libexif-dev libpopt-dev libxml2-dev libjpeg-dev libgd-dev gettext autopoint

Download the latest code for libgphoto2 from:

git clone

Execute the following commands to install libgphoto2

cd ~/libgphoto2
autoreconf --install --symlink
sudo make install

Download code for gphoto2

git clone

Build and installgphoto2

cd ~/gphoto2
autoreconf --install --symlink
sudo make install

Add the following line in /etc/


Refresh cache before proceeding further.

sudo ldconfig

Generate udev rules for the camera

/usr/local/lib/libgphoto2/print-camera-list udev-rules version 201 group plugdev mode 0660 | sudo tee /etc/udev/rules.d/90-libgphoto2.rules

Generate the hardware database file for udev

/usr/local/lib/libgphoto2/print-camera-list hwdb | sudo tee /etc/udev/hwdb.d/20-gphoto.hwdb

Using ghoto2

Now that we have both the libraries installed, now we can use ghoto2 for interfacing with the camera. Make sure that the camera is connected to the Raspberry Pi.

Execute the following command to see if ghoto2 can detect the camera.

gphoto2 --auto-detect

If your camera name shows up in the output, you can now go ahead and click a picture by executing the following command:

gphoto2 --capture-image

Using Python Scripts

Now that we have tested that the camera connection is working fine, we will go ahead and capture pictures using simple python scripts. Firstly, install the python wrapper for ghoto2

sudo pip install -v gphoto2

Next, create a script that will let you capture an image from the DSLR.

We first get an instance of the camera object using get_camera and then pass this instance to thecapture_image function to click a picture.

That’s it for this post. I hope you would have found this useful.

Grad Student at ASU | Student Researcher at The Luminosity Lab | Ex Senior Software Engineer, Zeta | Volunteer, Wikimedia Foundation