Skip to content

hmazin/Camera_Streamer

Repository files navigation

Camera Streamer

A Python-based camera streaming and recording system that can connect to a camera, stream video in real-time, and automatically save video segments at regular intervals.

Quick Start with GUI

Easiest way to use all features: Launch the graphical control panel:

python camera_control_panel.py

This opens a settings window where you can:

  • Select which mode to run (streaming, detection, recording, etc.)
  • Configure all settings (camera, model, confidence, output directory, etc.)
  • Start/stop the camera with one click
  • No need to remember command-line arguments!

Features

Stage 1: Basic Camera Streaming

  • Connect to camera devices
  • Real-time video streaming with frame counter
  • Display camera properties (resolution, FPS)

Stage 2: Video Recording System

  • Continuous video recording from camera
  • Automatic segmentation (saves video every minute by default)
  • Timestamped filenames for easy organization
  • Preview window with recording status
  • Configurable segment duration and output directory

Person Detection with YOLO

  • Real-time person detection using YOLOv8
  • Draws bounding boxes around detected persons
  • Shows detection confidence scores
  • Multiple model sizes for speed/accuracy tradeoff
  • Configurable confidence threshold

Person-Activated Recording

  • Continuously monitors camera for persons
  • Automatically starts recording when person enters frame
  • Stops recording when person leaves frame
  • Saves video segments only when persons are detected
  • Prevents flickering with configurable grace period

Person with Cup Detection

  • Detects persons holding cups/mugs
  • Only records when a person with a cup is detected
  • Ignores persons without cups
  • Uses spatial proximity to determine if person is holding cup
  • Saves recordings to separate directory

Installation

  1. Install Python 3.7 or higher

  2. Install required dependencies:

pip install -r requirements.txt

Note: The GUI control panel uses tkinter, which is included with Python on most systems. If you get an error about tkinter, install it:

  • Ubuntu/Debian: sudo apt-get install python3-tk
  • macOS: Usually pre-installed
  • Windows: Usually pre-installed

Usage

GUI Control Panel (Recommended)

The easiest way to use all features is through the graphical control panel:

python camera_control_panel.py

Features:

  • Mode Selection: Choose from all available modes
    • Basic Streaming
    • Person Detection (view only)
    • Person Recording
    • Person with Cup Recording
  • Settings Configuration: Adjust all parameters through GUI
    • Camera index
    • YOLO model size and confidence
    • Output directory
    • Recording duration and grace periods
  • One-Click Control: Start/Stop buttons
  • Real-time Status: See current status of camera operations

Command Line Usage

For advanced users or scripting, you can also use the command-line interface:

Stage 1: Basic Streaming

To stream video from your camera:

python camera_stream.py

Or specify a different camera index:

python camera_stream.py --camera 1

Press 'q' to quit the stream.

Stage 2: Video Recording

To record video segments (saves every 60 seconds by default):

python camera_recorder.py

Command-line options:

  • --camera N: Specify camera index (default: 0)
  • --duration N: Segment duration in seconds (default: 60)
  • --output DIR: Output directory for video files (default: recordings)
  • --no-preview: Disable preview window (useful for headless operation)

Examples:

Record with 30-second segments:

python camera_recorder.py --duration 30

Record to a custom directory:

python camera_recorder.py --output /path/to/videos

Record without preview window:

python camera_recorder.py --no-preview

Person Detection

To detect persons in the camera stream with bounding boxes:

python person_detector.py

Command-line options:

  • --camera N: Specify camera index (default: 0)
  • --model SIZE: YOLO model size - nano (fastest), small, medium, large, xlarge (most accurate, default: nano)
  • --confidence FLOAT: Confidence threshold 0.0-1.0 (default: 0.25)

Examples:

Use a larger model for better accuracy:

python person_detector.py --model small

Adjust confidence threshold (higher = fewer false positives):

python person_detector.py --confidence 0.5

Use different camera:

python person_detector.py --camera 1

Note: On first run, the YOLO model will be automatically downloaded (this may take a moment).

Person-Activated Recording

Monitor camera and automatically record only when persons are detected:

python person_recorder.py

How it works:

  • Camera continuously monitors for persons
  • Recording starts automatically when a person enters the frame
  • Recording stops when no person is detected (after a short grace period)
  • Each recording is saved as a separate video file with timestamp in filename
  • Timestamp overlays: Every frame in recorded videos includes a timestamp overlay (top-right corner)
  • Recording log: All recording events are logged to recording_log.txt with precise timestamps

Command-line options:

  • --camera N: Camera index (default: 0)
  • --model SIZE: YOLO model size (default: nano)
  • --confidence FLOAT: Confidence threshold 0.0-1.0 (default: 0.25)
  • --output DIR: Output directory (default: person_recordings)
  • --min-frames N: Minimum frames before stopping (prevents flickering, default: 30)
  • --no-preview: Disable preview window

Examples:

Record with higher confidence threshold:

python person_recorder.py --confidence 0.5

Use more accurate model:

python person_recorder.py --model small

Custom output directory:

python person_recorder.py --output /path/to/recordings

Output:

  • Video files: Saved with timestamped filenames like:

    • person_20251208_143022.mp4 - Recording when person entered
    • person_20251208_143145.mp4 - Next recording when person entered again
  • Timestamp overlays: Each recorded video frame displays:

    • Current date and time (top-right corner)
    • Recording duration (elapsed time since recording started)
  • Recording log: recording_log.txt file contains:

    • Timestamp of each recording start
    • Timestamp of each recording stop
    • Duration and frame count for each recording
    • Session summary statistics

Person with Cup Detection

Monitor camera and record only when a person holding a cup is detected:

python person_cup_detector.py

How it works:

  • Continuously monitors for persons and cups
  • Uses spatial proximity to detect if a person is holding a cup
  • Only records when person + cup combination is detected
  • Ignores persons without cups
  • Saves recordings to separate directory (person_cup_recordings/)

Command-line options:

  • --camera N: Camera index (default: 0)
  • --model SIZE: YOLO model size (default: nano)
  • --confidence FLOAT: Confidence threshold 0.0-1.0 (default: 0.25)
  • --output DIR: Output directory (default: person_cup_recordings)
  • --min-frames N: Minimum frames before stopping (default: 30)
  • --no-preview: Disable preview window

Examples:

# Use more accurate model
python person_cup_detector.py --model small

# Adjust confidence threshold
python person_cup_detector.py --confidence 0.5

# Custom output directory
python person_cup_detector.py --output /path/to/cup_recordings

Visual indicators:

  • Blue boxes: Detected persons
  • Yellow boxes: Detected cups
  • Green boxes: Person with cup (recording trigger)
  • Green line: Connection between person and cup

Output:

  • Video files saved as: person_cup_YYYYMMDD_HHMMSS.mp4
  • Timestamp overlays on each frame
  • Recording log file: recording_log.txt

Output

Video segments are saved in the recordings directory (or your specified output directory) with filenames like:

  • segment_20240115_143022.mp4
  • segment_20240115_143122.mp4
  • etc.

Each filename includes a timestamp indicating when the recording started.

Notes

  • The system will automatically try alternative camera indices if the default camera (index 0) is not available
  • Video files are saved in MP4 format using the 'mp4v' codec
  • If the camera FPS cannot be detected, a default of 30 FPS is used
  • Press 'q' in the preview window to stop recording gracefully

Troubleshooting

Camera not detected:

  • Try different camera indices: --camera 1 or --camera 2
  • Check that your camera is properly connected
  • On Linux, you may need to check permissions: ls -l /dev/video*

Permission errors:

  • On Linux, you may need to add your user to the video group:
    sudo usermod -a -G video $USER
    Then log out and log back in.

Video playback issues:

  • If MP4 files don't play, you may need to install additional codecs
  • Consider using a different codec by modifying the fourcc parameter in camera_recorder.py

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published