How Do You Get Linux to Use a Camera with No GUI Environment (e.g., a crontab execution)?

Problem scenario
You have a Python program that takes a picture with a USB-attached camera. But when the crontab runs the program, the program does not work. You want vlc or some camera application to launch and capture a photo when the Python program is run with a crontab execution. You want a solution to work if you are logged into a terminal with Putty with no desktop GUI logged in. What do you do?

1. Install fswebcam. (In our experience vlc works best in a desktop GUI environment.)

For Debian/Ubuntu Linux, run this command to install fswebcam: sudo apt-get -y install fswebcam libjpeg8-dev imagemagick

For CentOS/RHEL/Fedora, run these commands:

sudo yum -y install gd gd-devel git
git clone
cd fswebcam
sudo ./configure --prefix=/usr
sudo make
sudo make install

2. To use it, run this command: fswebcam -r 640x480 --jpeg 85 -D 1 /tmp/usb_camera_photo.jpg

3. You are done. You may want to have Python invoke the bash command above. (Remember that import subprocess, import os, import system are potential ways of invoking a Bash command. There are security risks associated with these.)

Leave a comment

Your email address will not be published. Required fields are marked *