How kaz-py/deteccion-de-caidas works
Purpose and Entry Point
This is a local, real-time fall-detection program. It captures frames from the computer camera, applies Ultralytics YOLO person detection through OpenCV processing, and displays the live result until the user presses q.
Primary executable entry point:
• src/deteccion_de_caidas/deteccion.py
The package namespace is:
• src/deteccion_de_caidas/__init__.py
Runtime and Dependency Boundary
The application runs on Python 3.12+ and is managed with uv; resolved dependency versions are captured in:
• pyproject.toml
• uv.lock
It depends materially on:
• OpenCV for camera access, frame handling, visualization, and keyboard input.
• Ultralytics YOLO for object/person inference.
• A locally available camera device.
There is no indicated server, database, browser client, cloud service, or persistent storage boundary.
Camera Capture Stage
The detection loop begins by opening the default local camera and repeatedly reading image frames. Camera availability is an operational prerequisite; failure to access it prevents live inference.
This hardware/OS boundary is implemented in:
• src/deteccion_de_caidas/deteccion.py
Frames flow in-memory from the camera directly into the model-processing stage rather than through files or network transport.
YOLO Inference Stage
Each captured frame is passed to an Ultralytics YOLO model. The model produces detections, including bounding-box geometry and class/confidence metadata used by the fall-detection decision logic.
The inference integration and frame-level orchestration reside in:
• src/deteccion_de_caidas/deteccion.py
Model loading is a key startup boundary: its weights may need to be available locally or be obtained by the Ultralytics runtime, depending on the implementation.
Fall Classification Logic
The core domain decision is derived from detected person geometry: the program distinguishes a potential fall using the dimensions/orientation of a detected bounding box, rather than a temporal pose-tracking pipeline.
This means the decision is frame-local and heuristic-driven; it does not imply identity tracking, event persistence, alert delivery, or video recording.
Core logic location:
• src/deteccion_de_caidas/deteccion.py
Visualization and User Control
Processed frames are annotated and rendered in an OpenCV display window so the operator can observe detections and fall status in real time. The same loop listens for the q key as its explicit shutdown control.
UI/output and lifecycle handling are in:
• src/deteccion_de_caidas/deteccion.py
On exit, the application should release the camera and close OpenCV windows, returning control to the terminal.
Control Flow Summary
1. Start the Python script through uv.
2. Initialize YOLO and open the local camera.
3. Read one frame at a time.
4. Run YOLO inference on the frame.
5. Evaluate person-box geometry for a fall condition.
6. Draw/display results.
7. Continue until q, then clean up camera/display resources.
The repository is intentionally compact: nearly all application architecture is concentrated in:
• src/deteccion_de_caidas/deteccion.py
Main entry points: deteccion.py Frame capture · pyproject.toml Dependencies · __init__.py Package namespace · uv.lock Resolved lockfile
Components 12
Local runtime
- Detection executable · Starts initialization and the live frame loop.
src/deteccion_de_caidas/deteccion.py - Package namespace
src/deteccion_de_caidas/__init__.py - Dependencies · Pins Python, OpenCV, and Ultralytics dependencies.
pyproject.toml - Resolved lockfile
uv.lock
Live detection loop
- Local camera · Default camera supplies in-memory frames.
- Frame capture
src/deteccion_de_caidas/deteccion.py - YOLO model · Loads weights and produces person detections.
src/deteccion_de_caidas/deteccion.py - Person boxes · Bounding boxes include geometry, class, and confidence.
src/deteccion_de_caidas/deteccion.py - Fall heuristic · Classifies a potential fall from person-box orientation and dimensions.
src/deteccion_de_caidas/deteccion.py - Annotated display · Renders live detections and fall status.
src/deteccion_de_caidas/deteccion.py - q shutdown control · Ends the loop when q is pressed.
src/deteccion_de_caidas/deteccion.py - Resource cleanup · Releases camera and closes display windows.
src/deteccion_de_caidas/deteccion.py
Connections 13
- Dependencies → Detection executable: defines runtime
- Resolved lockfile → Dependencies: resolves versions
- Package namespace → Detection executable: contains
- Detection executable → Local camera: opens
- Local camera → Frame capture: frames
- Frame capture → YOLO model: frame
- YOLO model → Person boxes: inference output
- Person boxes → Fall heuristic: box geometry
- Fall heuristic → Annotated display: annotations and status
- Frame capture → Annotated display: source frame
- Annotated display → q shutdown control: polls input
- q shutdown control → Resource cleanup: q exits loop
- Resource cleanup → Local camera: releases