Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Agent to support RTSP compatible IP cameras #605

Merged
merged 31 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c91ed2b
Draft of RTSP camera agent
tskisner Dec 29, 2023
a1e8137
Implement motion detection and add a fake camera class.
tskisner Dec 30, 2023
2abeb2f
Add option to disable motion detection. Add documentation.
tskisner Dec 30, 2023
a3c9032
Add import test
tskisner Dec 30, 2023
c9a1e50
Small cleanup
tskisner Dec 30, 2023
1191385
Small tweak to docs
tskisner Dec 30, 2023
b18a97a
Fix typo in docs
tskisner Dec 30, 2023
30df262
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 30, 2023
cb45fd6
Add opencv to mock imports
tskisner Dec 30, 2023
a55c0e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 30, 2023
41e5f09
Address silly flake8 complaints
tskisner Dec 30, 2023
4c3ea62
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 30, 2023
79f89ae
Move common camera tools out of rtsp agent
tskisner Apr 24, 2024
4401b48
Rename rtsp camera directory
tskisner Apr 24, 2024
e445f1a
Rename agent to RTSPCameraAgent
tskisner Apr 24, 2024
f4d3d9d
Change name of snapshot interval argument
tskisner Apr 24, 2024
e0f666d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 24, 2024
93e5397
Clean up imports. First draft of motion detection start/stop times.
tskisner Apr 25, 2024
ab0224f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2024
6fd15c7
Update docs
tskisner Apr 25, 2024
c8fb070
Fix flake8 errors
tskisner Apr 25, 2024
068e66c
Apparently relative imports do not work here.
tskisner Apr 25, 2024
82f2b63
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2024
9753b5c
Fix name in plugin loader
tskisner Apr 25, 2024
3dd1252
Another naming fix
tskisner Apr 25, 2024
70c9589
Pass motion start / stop to agent class
tskisner Apr 25, 2024
be84975
Remove stale debug statement
tskisner Apr 25, 2024
f3f6d7b
Add agent to plugin.py
tskisner Nov 15, 2024
bfaf281
Fix sidebar link to agent docs
BrianJKoopman Nov 15, 2024
7e003fe
Add dependencies in other needed locations
BrianJKoopman Nov 15, 2024
d9339c6
Clean up examples in docs
BrianJKoopman Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions docs/agents/rtsp_camera.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.. highlight:: rst

.. _rtsp_camera:

====================
RTSP Camera Agent
====================

This OCS Agent which grabs screenshots and records video from IP cameras
supporting the RTSP streaming protocol.

.. argparse::
:filename: ../socs/agents/rtsp_camera/agent.py
:func: add_agent_args
:prog: python3 agent.py

Configuration File Examples
---------------------------

Below are configuration examples for the ocs config file and for running the
Agent in a docker container.

OCS Site Config
```````````````

To configure the RTSP Camera Agent we need to add a RTSPCameraAgent block to our
ocs configuration file. Here is an example configuration block using all of the
common arguments. Many options do not normally need to be changed::

{'agent-class': 'RTSPCameraAgent',
'instance-id': 'camera-c3',
'arguments': ['--mode', 'acq',
'--directory', '/camera',
'--address', 'camera-c3.example.org',
'--user', 'ocs',
'--password', '<password>',
'--motion_start', '19:00:00-04:00',
'--motion_stop', '07:00:00-04:00',
'--snapshot_seconds', '10',
'--record_duration', '120']},

Docker Compose
``````````````

The RTSP camera Agent should be configured to run in a Docker container. An
example docker-compose service configuration is shown here::

ocs-camera-c3:
image: simonsobs/socs:latest
hostname: ocs-docker
environment:
- INSTANCE_ID=camera-c3
- SITE_HUB=ws://127.0.0.1:8001/ws
- SITE_HTTP=http://127.0.0.1:8001/call
- LOGLEVEL=info
volumes:
- ${OCS_CONFIG_DIR}:/config:ro
- /so/cameras/c3:/camera
user: 9000:9000

The ``LOGLEVEL`` environment variable can be used to set the log level for
debugging. The default level is "info". The volume must mount to whatever
location inside the container that you specified in the config file. The user
must have permissions to write to the mounted local directory.

Description
-----------

The indoor IP cameras at the site support the RTSP protocol. These cameras are
mainly for security monitoring. The directory specified in the configuration is
the top level directory for storing files. Two subdirectories, "snapshots" and
"recordings" are created below this. Snapshots are saved every 10 seconds and a
couple days worth are kept in a circular buffer on disk. A symlink
("latest.jpg") is kept for the latest snapshot acquired, and this can be
displayed in a Grafana text panel using an HTML image tag.

By default, these snapshots are processed for motion detection. If motion is
detected, a 20fps video recording is triggered. During recording, further motion
detection is disabled. After the recording stops, motion detection resumes.
These recordings are also kept in a circular disk buffer in the "recordings"
subdirectory. These full video files are for manual download and viewing after a
security event. All image and video files contain the ISO timestamp when they
were acquired.

Agent API
---------

.. autoclass:: socs.agents.rtsp_camera.agent.RTSPCameraAgent
:members:
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
'sodetlib.det_config',
'src',
'src.pid_controller',
'cv2',
'imutils',
]
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ API Reference Full API documentation for core parts of the SOCS library.
agents/pfeiffer_tc400
agents/pysmurf-controller
agents/pysmurf-monitor
agents/rtsp_camera
agents/scpi_psu
agents/smurf_crate_monitor
agents/smurf_timing_card
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ acu = [
# Note: Not including the holography deps, which are Python 3.8 only. Also not
# including any dependencies with only direct references.
all = [
"imutils",
"labjack-ljm",
"numexpr",
"opencv-python",
"pandas",
"pfeiffer-vacuum-protocol==0.4",
"pixell",
Expand All @@ -78,6 +80,11 @@ magpie = [
"scipy",
"so3g",
]
# Camera control
camera = [
"opencv-python",
"imutils",
]
# Pfeiffer TC 400 Agent
pfeiffer = [
"pfeiffer-vacuum-protocol==0.4",
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ labjack-ljm
scipy
pandas

# camera control
imutils
opencv-python

# pfeiffer tc 400
pfeiffer-vacuum-protocol==0.4

Expand Down
1 change: 1 addition & 0 deletions socs/agents/ocs_plugin_so.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
('PfeifferTC400Agent', 'pfeiffer_tc400/agent.py'),
('PysmurfController', 'pysmurf_controller/agent.py'),
('PysmurfMonitor', 'pysmurf_monitor/agent.py'),
('RTSPCameraAgent', 'rtsp_camera/agent.py'),
('ScpiPsuAgent', 'scpi_psu/agent.py'),
('SmurfFileEmulator', 'smurf_file_emulator/agent.py'),
('SmurfStreamSimulator', 'smurf_stream_simulator/agent.py'),
Expand Down
4 changes: 4 additions & 0 deletions socs/agents/rtsp_camera/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (C) 2023-2024 Simons Observatory Collaboration
# See top-level LICENSE.txt file for more information.
"""Agent to capture images from cameras which support the RTSP protocol.
"""
Loading