-
Notifications
You must be signed in to change notification settings - Fork 22
cam_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
Select the video source and capture tool in the gui's camera tab to open the tool specific controls.
FSwebcam is the recommended capture tool.
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 extra settings depending on it's capabilities, such as 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 settings work and the values used is likely to depend on your camera, refer to your webcams datasheet for more information.
To make this list press the 'get opt list' button.
You can test the camera in three ways;
Take using cam default - what the program takes when no settings are given Take using local settings - the settings from the gui Take using saved settings - the settings file saved on the pi
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.
camcap.py is a command line tool that's normally called by cron or the camera tab in the gui, a typical cron line to run it every five minuets is;
*/5 * * * * /home/pi/Pigrow/scripts/cron/camcap.py set=camera_settings.txt
this can be set in the gui's cron tab by adding a new repeating job, selecting the cron folder and camcap.py then adding set=camera_settings.txt to the args field, a tool to do this automatically will be added soon.
See the cron section [not yet written] for information on pausing cron jobs, editing settings at set times and other cron features.
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.
Set caps folder
caps=/home/<USERNAME>/Pigrow/caps/
images will be stored here with the name cap_.jpg
The amount of times it tries to take a picture before giving up
attempts=3
The location of the error log to record problems.
errlog=/home/<PATH>/Pigrow/logs/err_log.txt