Anaquel Inteligente 3B is designed for local or intranet deployment where the camera and the server machine share the same network. The backend is a single Python process that streams video, runs YOLOv8 inference, and serves both a REST API and a Socket.IO WebSocket — all on port 8000. The React dashboard can be served as a Vite dev server on port 3000, or built into a static bundle and hosted anywhere.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/elzackarias/Hackaton3B-Reto1/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
Before installing, verify that your environment meets the following prerequisites:- Python 3.10 or later (3.11 recommended)
- Node.js 18 or later (for the React frontend)
- Camera: USB webcam (device index
0or1) or an IP camera with a valid RTSP URL - RAM: 4 GB minimum; 8 GB recommended when running YOLO inference continuously
- CPU: AVX2 instruction support required by PyTorch / YOLOv8
- GPU: Optional — YOLOv8 via Ultralytics will automatically use CUDA if a compatible NVIDIA GPU and driver are present; falls back to CPU otherwise
The backend dependencies include
opencv-python-headless, which does not require a display server. The system can run on a headless server and stream video to remote dashboard clients.Installation
fastapiuvicorn[standard]python-socketioultralyticsopencv-python-headlessnumpypydanticaiofilesIf the file is missing, obtain it from your team (it is the output of training with
backend/dataset.yaml) or retrain using:Starting the System
Using the Setup Scripts
The repository ships with convenience scripts that install all dependencies in a single step:Starting the Backend
DetectionEngine performs three dummy warm-up inferences so the first real frame is processed without latency spikes.
Starting the Frontend
Camera Setup
USB Webcam
The defaultCameraCapture() constructor uses an RTSP URL as the primary source and automatically falls back to USB device 0 if the RTSP connection fails. To use a USB camera directly, pass the device index when instantiating CameraCapture in your code:
RTSP IP Camera
Provide a full RTSP URL as the source string:cv2.CAP_FFMPEG with a TCP transport and a 5-second open/read timeout. It retries up to 5 times before falling back to USB.
Testing Camera Access
Before launching the full server, confirm the camera is accessible:Camera open: True. If it prints False, try device index 1 or 2, or check USB connection and driver installation.
Demo Checklist
Use this checklist to verify the end-to-end system is fully functional before a live demonstration:- Camera connected and streaming live video to the dashboard
- YOLOv8 detecting all 7 products on the shelf (
agua_burst,burst_energetica_roja,burst_energy,nachos_naturasol,nebraska_mango,sisi_cola,sun_paradise_naranja) - Dashboard showing real-time stock counts per SKU
- Product removal triggers automatic stock count decrement visible on the dashboard
- Alerts appear when a SKU’s stock drops below 20 % of initial stock (
MIN_THRESHOLD = 0.20) - Prediction panel shows estimated time to stockout (requires ≥ 2 removal events per SKU)
- Heatmap panel highlights active shelf slots
- Narrative messages (in Spanish) appearing in the dashboard feed
- Video overlay with bounding boxes and stock-level colour coding (green / yellow / red) visible on the live feed panel
Ports & Endpoints Summary
| Service | Port | URL | Notes |
|---|---|---|---|
| Backend API | 8000 | http://localhost:8000 | FastAPI + Socket.IO combined ASGI app |
| API Docs (Swagger) | 8000 | http://localhost:8000/docs | Auto-generated interactive API documentation |
| Embedded Dashboard | 8000 | http://localhost:8000/dashboard | Minimal HTML dashboard served directly by FastAPI |
| Frontend Dev Server | 3000 | http://localhost:3000 | React + Vite development server |
Troubleshooting
Camera not detected — VideoCapture returns False
Camera not detected — VideoCapture returns False
- Confirm the USB cable is securely connected and the camera powers on.
- Run the quick test:
python -c "import cv2; cap = cv2.VideoCapture(0); print(cap.isOpened())". Try indices0,1, and2if the first fails. - On Linux, ensure your user is in the
videogroup:sudo usermod -aG video $USER(log out and back in). - On Windows, check Device Manager to confirm the camera driver is installed and the device is not in an error state.
- If using an RTSP camera, verify the URL, credentials, and that the camera is on the same network. Use VLC (
Media > Open Network Stream) to test the RTSP URL independently.
YOLOv8 model not found — FileNotFoundError on startup
YOLOv8 model not found — FileNotFoundError on startup
- Confirm
models/best3.ptexists at the repository root:ls models/best3.pt. - If missing, obtain the trained weights from your team or retrain:
python backend/train_model.py. Training requires the dataset described inbackend/dataset.yaml. - Do not rename the file — the path is hardcoded in
detection_engine.pyasROOT / "models" / "best3.pt". - If you have a different model file, update the
MODEL_PATHconstant indetection_engine.pybefore starting.
Frontend can't connect to backend — dashboard shows mock data
Frontend can't connect to backend — dashboard shows mock data
- Confirm the backend is running:
curl http://localhost:8000/api/healthshould return{"status":"ok",...}. - Check that the backend is bound to
0.0.0.0(not127.0.0.1) if the frontend runs on a different machine. - Open browser developer tools (F12 → Console) and look for WebSocket or CORS errors.
- Verify
BACKEND_URLinfrontend/src/hooks/useSocket.tsmatches the backend’s actual address and port. - In production, update
allow_originsinmain.py’sCORSMiddlewareandcors_allowed_originsin thesocketio.AsyncServercall to include your frontend’s exact origin.
False positives or double-decrement events
False positives or double-decrement events
- Increase the YOLO confidence threshold by editing
confinDetectionEngine.__init__(default0.1). Try0.3or0.4. - Increase
cooldown_secondson theDetectionEngineinstance (default3.0). A value of5.0–10.0suppresses repeated events from the same shelf slot. - Increase
consistency_frames(default3) to require more consecutive frames of agreement before an event is emitted. Try5. - If removal events fire twice per product pick, the
consistency_framesanti-flicker filter may not be catching the oscillation fast enough — increase bothcooldown_secondsandconsistency_framestogether.
Slow inference — high latency or low effective FPS
Slow inference — high latency or low effective FPS
- Reduce
imgszfrom640to416or320in theDetectionEngineconstructor. Smaller images run significantly faster at a slight accuracy cost. - Set
detect_every=3ordetect_every=4in thestream_loopcall in_run_camera_loop(default is2) to run YOLO on fewer frames. - If a CUDA-capable GPU is available, ensure the correct CUDA toolkit and PyTorch GPU build are installed. Ultralytics will use
cuda:0automatically when available. - Reduce
max_fpsin thestream_loopcall if you only need a slower update rate (e.g.,max_fps=2). - On CPU-only machines, consider using a smaller YOLOv8 variant (
yolov8nnano) for retraining if latency is critical.