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.
- 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
- Python 3.10+
- See
requirements.txtfor all dependencies
- Clone the repository:
git clone <repo-url> cd Detect-Portal-State
- Run the docker-compose to set up the environment:
docker-compose up -d --build
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: 16Download a pre-trained YOLO classification model from the YOLO website
docker-compose up -d --buildThe API will be available at http://localhost:8080/state and will return the current portal state as JSON.
main.py— Launches the Flask APIapi.py— API endpointsdetect.py— Detection logic using YOLOcrop_image.py— Image cropping utilitiestrain/extract-frame.py— Extracts frames from videos for dataset creationmodels/— Trained YOLO modelsdatasets/— Raw and cropped datasets
Train your own model using the scripts in the train/ directory. Place your images in the appropriate folders and follow the YOLO training workflow.
{
"state": "open"
}MIT