Photo Capture Plugin

Purpose

The purpose of this plugin is to capture an image from locally connected cameras.

Usage

Cameras connected via a local ethernet network are sometimes referred to as IP or WEB cameras. Most IP/WEB connected cameras allow photo and/or video collection by common protocols such as http, fswebcam or rtsp. The site https://www.ispyconnect.com/sources.aspx can be used to determine if and how a camera image can be captured from a particular make and model of camera, via http, fswebcam or rtsp. The file defined in config_filename (see Arguments below) must contain a single command that is used get the photo, and 4 command types are currently supported by this plugin, either http, rtsp, fswebcam or ffmpeg. The command must start with either of these keywords. Comments are allowed in the config filename, but must start with '#'. Some examples of the contents of config_filename:

http://root:password@192.168.1.2/cgi-bin/viewer/video.jpg
ffmpeg -y -i rtsp://admin:password@192.168.1.100:554/live -vframes 1 
fswebcam -d /dev/video0 -r 640x480 --jpeg 100 -S 20 --set brightness=40% -F 1  

If collecting via rtsp, then installation of the ffmpeg command must be done manually, as below, if its not already installed. If ffmpeg is not installed, do the following on an X86 device.

sudo apt-get update
sudo apt-get install -y libav-tools
ffmpeg -version

For testing, try and capture an image to the filename /tmp/img.jpg, try the following:

ffmpeg -y -i rtsp://admin:admin@192.168.10.113:554/live -vframes 1 /tmp/img.jpg

Capturing an image via http is much easier. The convert tool is optional, and only to reduce the size of the image if it is too big.

sudo apt-get update
sudo apt-get install -y imagemajick
wget -O /tmp/temp.jpg http://<uid>:<pwd>@192.168.0.23/jpg/image.jpg?size=3 && convert /tmp/temp.jpg -resize 650 /tmp/photo1.jpg
wget -O /tmp/photo1.jpg http://<uid>:<pwd>@192.168.0.23/jpg/image.jpg?size=3

You may have to encode the password using this guide: https://www.w3schools.com/tags/ref_urlencode.ASP if it contains special characters. For example; A password of (say) ()&^% becomes: %28%29%26%5E%25.

At the moment, the plugin WILL NOT setup the WATCH scenario in the Ardexa YAML file. This MUST be done manually. An example is shown below. If you don't know how to do this, contact Ardexa.

watch:
  - table: data
    source: photo
    file: /opt/ardexa/watch/image.jpg
    check: hash
    attach: true

Ardexa does not recommend USB connected cameras. However if you need to connect to a USB device, the fswebcam seems to be a more usable and stable app. The fswebcam allows for better collection and control of camera properties. Its best to use a config file to control exposure and resolution. Its usually better to leave the settings to auto, so the camera can work it out. It may be work better to make sure the camera skips the first 50 or so frames, so it can execute its auto focus, etc functions before taking a frame. To install the fswebcam package and set controls, do the following:

sudo apt-get update
sudo apt-get install -y fswebcam
fswebcam -d /dev/video1 -r 640x480 --jpeg 85 -F 1
fswebcam -d v4l2:/dev/video0 --list-controls
fswebcam -d v4l2:/dev/video0 --set brightness=50%
fswebcam -d v4l2:/dev/video0 --set contrast=3

Arguments

This plugin only needs 1 mandatory argument, a config filename, which as described above contains the Linux command to take a frame. All the other options are as follows

--latitude                      ... The lattiude, required if taking pictures only during daylight hours
--longitude                     ... The longitude, required if taking pictures only during daylight hours
--elevation                     ... The elevation (in metres), required if taking pictures only during daylight hours
--photo_only_during_sunlight    ... If present, it will only take photos during daylight hours
--after_sunrise_before_sunset   ... If present, it will only take photos sunsetrise hours before sunset or after sunrise
--sunsetrise                    ... A value something like 0.0 to 24.0, in hours
--copy_storage                  ... If if this argument is present, it will copy photos to storage_directory. Default is /opt/ardexa/photo/storage
--config_filename               ... This is the config filename (see below). The default is /opt/ardexa/config/photo-capture/photo.config
--output_filename               ... This is the directory for copying the photo. Default is /opt/ardexa/watch/image.jpg
--storage_directory             ... This is the directory to store the photos. Default is /opt/ardexa/photo/storage/
--max_storage_age               ... This is the maximum days to store photos. Default is 10.0 days. Anything after this will be deleted. Fractions may be used.

AXIS Camera Control

These are high quality cameras made in Sweden. They can be controlled (pan/zoom/tilt/etc) using a (local) web API. See reference: https://www.axis.com/support/developer-support/axis-camera-application-platform/q-and-a. API guide is found at : https://www.axis.com/files/tech_notes/script_guide.pdf. For controlling the camera, the userid must have access rights to undertake the task. Examples below

curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?whoami=1
curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?info=1&camera=1
curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?query=position
curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?rpan=10&camera=1
curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?rpan=-30&camera=1
curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?move=home
curl --digest -u "userid:password" -X GET http://192.168.2.2/axis-cgi/com/ptz.cgi?rtilt=-30&camera=1

VIVOTEK Camera Control

These are cameras made in Taiwan. Some of them can be controlled (pan/zoom/tilt/etc) using a (local) web API. See reference: http://download.vivotek.com/downloadfile/downloads/usersmanuals/fd8167manual_en.pdf. For controlling the camera, the userid must have access rights to undertake the task. Examples below

curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/getparam.cgi?network_ipaddress
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/getparam.cgi?system_hostname
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/getparam.cgi?videoin_ptzstatus
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/getparam.cgi?capability_eptz
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/syslog.cgi
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/getparam.cgi?ircutcontrol_disableirled
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/setparam.cgi?ircutcontrol_disableirled=1
curl -X GET http://userid:password@192.168.2.2/cgi-bin/admin/getparam.cgi?eptz_c0_zoomspeed