Skip to content

ADVERIE/chitragupt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Video Processing Service

A high-performance Go service that captures video frames from a camera, detects humans in real-time, and sends frames to a backend server using gRPC for efficient communication.

Features

  • High-Performance Video Capture: Uses Go bindings for OpenCV to efficiently capture video frames.
  • Real-time Human Detection: Implements lightweight object detection using YOLOv4-tiny model.
  • gRPC Frame Transmission: Efficiently streams frames with detected humans to a backend server using gRPC.
  • Modular Design: Components are designed to be easily replaceable and extensible.
  • Containerized Deployment: Docker and Docker Compose configuration for easy deployment.
  • Optimized for Performance: Designed for low latency, high speed, and efficient memory usage.

Requirements

  • Go 1.22 or higher
  • OpenCV 4.x
  • Docker and Docker Compose (for containerized deployment)
  • Protocol Buffer Compiler (protoc)

Installation

Installing Dependencies

On macOS

# Install OpenCV
brew install opencv

# Install Go
brew install go

# Install Protocol Buffer Compiler
brew install protobuf

Setting up the Project

  1. Clone the repository:
git clone https://github.com/adverie/videoservice.git
cd videoservice
  1. Install Go dependencies:
go mod tidy
  1. Generate gRPC code:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/gyandoot/gyandoot.proto
  1. Download YOLOv4-tiny model files:
# Create the configs directory if it doesn't exist
mkdir -p configs/detector

# Download YOLOv4-tiny weights
wget -O configs/detector/yolov4-tiny.weights https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights

# Download YOLOv4-tiny configuration
wget -O configs/detector/yolov4-tiny.cfg https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4-tiny.cfg

# Download COCO class names (or use the provided one)
wget -O configs/detector/coco.names https://raw.githubusercontent.com/AlexeyAB/darknet/master/data/coco.names

Usage

Running the Service Locally

  1. Ensure you have a gRPC backend server running and accessible.

  2. Set the GYANDOOT_ADDR environment variable to the address of your gRPC server (e.g., localhost:50051).

  3. In a separate terminal, start the video processing service:

GYANDOOT_ADDR=localhost:50051 go run cmd/videoservice/main.go

Running with Docker

... To be added.

Configuration

Camera Settings

You can adjust camera settings in cmd/videoservice/main.go or by setting environment variables:

  • CAMERA_ID: ID of the camera to use (default: 0)
  • CAMERA_WIDTH: Width of the camera frames (default: camera default)
  • CAMERA_HEIGHT: Height of the camera frames (default: camera default)
  • CAMERA_FPS: Frames per second (default: camera default)

Detection Settings

You can adjust detection settings by modifying the configuration in pkg/detector/detector.go or by setting environment variables:

  • CONFIDENCE_THRESHOLD: Confidence threshold for human detection (default: 0.7)
  • MODEL_PATH: Path to the model weights file (default: configs/detector/yolov4-tiny.weights)
  • CONFIG_PATH: Path to the model configuration file (default: configs/detector/yolov4-tiny.cfg)
  • CLASS_NAMES_PATH: Path to the class names file (default: configs/detector/coco.names)

gRPC Settings

  • GYANDOOT_ADDR: Address of the gRPC backend server (default: localhost:50051)
  • DEVICE_ID: Unique identifier for the video source (default: webcam-0)
  • SEND_INTERVAL_SECONDS: Minimum interval in seconds between sending frames when a human is detected (default: 5)

Architecture

The project is structured as follows:

  • cmd/videoservice: Main entry point for the video processing service
  • pkg/camera: Camera interface and implementation
  • pkg/detector: Human detection module
  • pkg/sender: Module for sending frames to the backend via gRPC
  • proto/gyandoot: Protocol buffer definitions for gRPC communication
  • configs: Configuration files for the services
  • docker: Docker-related files

Performance Considerations

  • The service is designed to be lightweight and efficient.
  • For optimal performance, consider the following:
    • Adjust frame resolution and frame rate according to your hardware capabilities
    • Use a more powerful machine for processing multiple video streams
    • Adjust JPEG compression quality for network transmission (configured in pkg/sender/grpc_sender.go)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

captures frames with humans

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages