Skip to content

corazon008/Detect-Portal-State

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Detect-Portal-State

A Python project to detect the state (open/closed) of a portal (gate/door) using a YOLO classifier and images from an RTSP camera stream or local files. The project provides an API for real-time state detection and tools for dataset preparation and model training.

Features

  • Real-time detection of portal state from RTSP camera streams or image files
  • REST API with Flask for integration with other systems
  • Tools for cropping images and extracting frames from videos
  • Easy integration with Home Assistant or other automation systems

Requirements

  • Python 3.10+
  • See requirements.txt for all dependencies

Installation

  1. Clone the repository:
    git clone <repo-url>
    cd Detect-Portal-State
  2. Run the docker-compose to set up the environment:
    docker-compose up -d --build

Usage

1. Create the config.yaml file

Create a config.yaml file with the following structure:

cameras:
  front:
    url: rtsp://viewer:[email protected]
    crop: # Top right corner here
      width:
        begin: 50 # percentage of the image
        end: 100
      height:
        begin: 0
        end: 50

settings:
  base_model: "yolo11n-cls.pt"
  training:
    epochs: 100
    batch_size: 16

2. Download a pre-trained YOLO model

Download a pre-trained YOLO classification model from the YOLO website

3. Run the docker container

docker-compose up -d --build

The API will be available at http://localhost:8080/state and will return the current portal state as JSON.

Project Structure

  • main.py — Launches the Flask API
  • api.py — API endpoints
  • detect.py — Detection logic using YOLO
  • crop_image.py — Image cropping utilities
  • train/extract-frame.py — Extracts frames from videos for dataset creation
  • models/ — Trained YOLO models
  • datasets/ — Raw and cropped datasets

Training

Train your own model using the scripts in the train/ directory. Place your images in the appropriate folders and follow the YOLO training workflow.

Example API Response

{
  "state": "open"
}

License

MIT

About

App which provide an API endpoint to watch for an object state from camera feed

Resources

Stars

Watchers

Forks

Contributors