Skip to content

cam_camcap.py

Pragmatismo edited this page Feb 19, 2023 · 8 revisions

camcap.py

The script camcap.py is designed to be called by cron at regular intervals to take a photo using a webcam.

This script will not take an image if more than 95% of the storage space is being used, this is to protect the rest of the system and allow normal operation to continue.

If it fails to create an image it will write an error to the error log.

It uses one of two programs 'FSWebcam' and 'UVCcapture' which must be installed, this can be done via the pigrow install dialogue in the gui system tab or with the commands;

sudo apt install fswebcam
sudo apt install uvccapture

Command Line

settings_file

Specify the settings file created by the gui camera config tools.

set=/home/<USERNAME>/Pigrow/config/camera_settings.txt
set=camera_settings.txt

If none are supplied it will default to the above.

caps_path

Set caps folder

 caps=/home/<USERNAME>/Pigrow/caps/ 

images will be stored here with the name cap_.jpg

retry attempts

The amount of times it tries to take a picture before giving up

attempts=3

error log

The location of the error log to record problems.

errlog=/home/<PATH>/Pigrow/logs/err_log.txt

Settings file

The settings file is created in the gui camera tab, it's a simple key=value list.

FSWebcam is able to set all the webcam specific commands which are unique to each model, the basic controls are fairly standard but do sometimes differ also each device has it's own selection of settings depending on it's capabilities - focus controls and etc.

When the webcam is connected to the raspberry pi the gui will be able to poll the webcam for a list of settings and use these to create the controls, how these controls work and the values used is likely to depend on your camera. To make this list press the 'get opt list' button.

FSwebcam settings in pigrow gui

When taking a photo with FSWebcam camcap.py creates a command string adding these in the format

--set "contrast=20" --set "autofocus=False"

there are also some settings in the file which are used to control the behaviour of FSWebcam

resolution=  image resolution 
cam_num=     which webcam to use 
fs_delay=    how long to wait for the image to settle down before taking a picture
fs_fskip=    how many frames to skip before taking a picture  
fs_banner=False  remove the banner showing the time the image was taken 

some webcams take a while to settle down after initialization, if your images aren't coming out right you can experiment with longer delay and frame skip options.

Clone this wiki locally