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.


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

Here are the steps for installing both these libraries.


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

Install libghoto2

git clone

Execute the following commands to install libgphoto2

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

Install ghoto2

git clone

Build and installgphoto2

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

Update Configs


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

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

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store