simonsobs / socs

Simons Observatory specific OCS agents.
BSD 2-Clause "Simplified" License
12 stars 12 forks source link

Add Agent to support RTSP compatible IP cameras #605

Open tskisner opened 6 months ago

tskisner commented 6 months ago

This agent adds support for acquiring snapshots and short recordings from cameras that can stream the RTSP protocol.

Description

This new agent records frames to disk (default every 10s) and passes them through a motion detection algorithm. If there is motion, a 60 second recording is taken. Recordings can also be triggered directly as an agent Task. Both images and video are stored to disk in circular buffers which by default hold the most recent 2 days of snapshots and 120 minutes of triggered videos. Use of this agent requires the opencv / cv2 and imutils packages.

Note that each agent instance handles exactly one camera. This enables using different settings for different camera placements.

Motivation and Context

This agent was created to support the Dahua security cameras at the site. These are interior cameras designed to capture unauthorized access or theft.

How Has This Been Tested?

This agent has been tested on a local system (laptop) at the site. It has been run for several hours and successfully detected motion in one of the containers as people went in and out. Note that I only tested this running as a local agent on the host system. I verified that the CPU and memory use are not too dramatic. There is a brief spike at the end of a recording when the list of frames is encoded to mp4. Here is an example of motion detection, which draws a green box around the areas where a change was detected:

img_2023-12-30T16:54:53+00:00 img_2023-12-30T16:55:03+00:00

Types of changes

Checklist:

tskisner commented 6 months ago

Just a note: this agent does require the opencv and imutils packages. Let me know if you want me to add another "extra" key to setup.py for this case.

BrianJKoopman commented 5 months ago

This is great. Thanks for reviewing @davidvng, and thanks for the PR @tskisner!

Just a note: this agent does require the opencv and imutils packages. Let me know if you want me to add another "extra" key to setup.py for this case.

This would be good to do. If these will be used in the functions that @davidvng suggested get pulled out for use in the ACTi camera agent then I don't mind them going in the main install_requires, else a new extras_require group would be great.

Since I assume you're busy with other things now that you're back from the site @tskisner, let's go ahead and merge this as is (with added requirements to the setup.py though), and @davidvng will take over making these improvements in separate PRs. That'll allow us to stand-up the agent for the cameras already deployed on site, and move forward with these suggestions. Sound good?

tskisner commented 2 months ago

This is now ready for re-review @davidvng.