Skip to main content

Panopticon

Pynopticon

Pynopticon is a video recording utility that saves the last n frames before an interesting event to disk. This is an efficient way to monitor and record systems where you care only about certain moments, and only have information ex post facto (like a crash on a robotic system).

Using the server you can always see a live video feed.

import time
from pynopticon import Pynopticon

p = Pynopticon(
  record_frames=100,
  width=640,
  height=480,
  cam=0
)
p.start()
time.sleep(10)
p.save(
  outname="my_video.mp4",
  fps=30,
)

Features

YouTube Upload

Optionally, you can upload the video to YouTube. This requires a client_secrets.json file, see instructions here.

import time
from pynopticon import Pynopticon, get_authenticated_service

youtube = get_authenticated_service(client_secrets_file="./client_secrets.json") # initialize youtube
p = Pynopticon(record_frames=100, youtube=youtube)
p.start()
time.sleep(10)
p.save(upload=True, title="My Video", description="My Description")

Email Notification

If uploading to YouTube, you can also send an email when a video is saved.

import time
from pynopticon import Pynopticon, get_authenticated_service
import sendgrid

sg = sendgrid.SendGridAPIClient(api_key=sendgrid_api_key) # initialize sendgrid
youtube = get_authenticated_service(client_secrets_file="./client_secrets.json")

p = Pynopticon(record_frames=100, youtube=youtube, sg=sg)
p.start()
time.sleep(10)
p.save(
  upload=True,
  title="My Video", description="My Description",
  to_email=["me@example.com", "other@example.com"],from_email="you@sendgrid.com")

HTTP API

There is also a server that exposes an http api, in case if you want to run Pynopticon on an external device.

# without YouTube upload:
pynopticon-server

# with YouTube upload:
CLIENT_SECRETS_FILE="client_secrets.json" pynopticon-server

api:

  • /: visit in browser for live streaming.
  • POST /start: same as p.start() (after stop, server auto starts pynopticon instance).
  • POST /save: same as p.save().
    • Set ?upload=true to upload to YouTube. Only works if CLIENT_SECRETS_FILE is set.
    • Set ?emails=one@example.com,two@example.com to send an email to the given emails. Only works if SENDGRID_API_KEY, SENDGRID_FROM are set, and upload=true.
  • POST /stop: same as p.stop().

config:

  • RECORD_FRAMES: number of frames to record before an event. Default: 100
  • PORT: port to run server on. Default: 4004
  • HOST: host to run server on. Default: 0.0.0.0
  • CAM: camera index. Default: 0
  • WIDTH: width of camera. Default: 640
  • HEIGHT: height of camera. Default: 480

If you want to upload to YouTube, you should set the following environment variables:

  • CLIENT_SECRETS_FILE: path to client_secrets.json file. Default: None

If all three of the following are set, the server will send an email when a video is uploaded to YT. If just some are set, an error will be raised.

  • SENDGRID_API_KEY: sendgrid api key. Default: None
  • SENDGRID_FROM: sendgrid from email. Default: None
Live Streaming

See HTTP API section above.

Installation

Requires OpenCV!

  • from pip
pip install pynopticon            # basic
pip install 'pynopticon[all]'     # all
pip install 'pynopticon[mail]'    # mail
pip install 'pynopticon[yt]'      # yt
pip install 'pynopticon[server]'  # server
  • from source
git clone https://github.com/rickwierenga/pynopticon

Cameras

Plug in a webcam/camera to your computer. We use this one ($50) in lab, but you should be able to use any USB webcam / camera.

Tip: You can use v4l2-ctl --list-devices on Linux to find the value you need to pass to CAM. This is particularly useful if you're going to be running multiple instances of the Pynopticon.

Informative

Schematic of Pynopticon

Developed for the Sculpting Evolution Group at the MIT Media Lab

Release files for Pynopticon 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Pynopticon 0.0.8
File Size Uploaded
Pynopticon-0.0.8.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Pynopticon 0.0.8
File Interpreter ABI Platform
Pynopticon-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 19.3 kB

Release files / Pynopticon-0.0.8.tar.gz

Download URL Pynopticon-0.0.8.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2b879de3a7820d16b0e1e3adf648e26ef1b3d8a1f2dd567e6fc11409cb8a7b16
BLAKE2b-256 checksum
How to use checksums
5f2d0833a87c64b27c7c911b2a9c50bf4d4636e5afbbdd98957c6708b79fe785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / Pynopticon-0.0.8-py3-none-any.whl

Download URL Pynopticon-0.0.8-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e22fde5880b61818f4c551dd49703a1911ddc86ecfca65f288da28abaa17afe
BLAKE2b-256 checksum
How to use checksums
93eaa46a0a2330a6af050843672151be4dfa75dcfbbeac299779afda4d53f326
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

1 release file

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page