Skip to content

thanthanh113366/SmartParking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

67 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Smart Parking System ๐Ÿš—

AI-powered parking management system with real-time object detection and license plate recognition.

๐Ÿ—๏ธ System Architecture

Simple Overview: Who Calls Who?

User Browser
    โ†“ Opens webpage
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   FRONTEND (Port 5169)      โ”‚  React App
โ”‚   - Displays UI             โ”‚
โ”‚   - Shows video stream      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ†“ Makes HTTP requests
    โ†“ GET /stream/detect
    โ†“ POST /api/plate-detect
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   BACKEND (Port 8069)       โ”‚  FastAPI Server
โ”‚   - Runs AI models (YOLO)   โ”‚
โ”‚   - Processes video frames  โ”‚
โ”‚   - Stores to Firebase      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ†“ Fetches stream
    โ†“ GET /stream
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   ESP32 SERVER (Port 5069)  โ”‚  Video Source
โ”‚   - Provides MJPEG stream   โ”‚
โ”‚   - Dev: Video files        โ”‚
โ”‚   - Prod: Real camera       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Component Responsibilities

1๏ธโƒฃ Frontend (React on port 5169)

What it does:

  • Shows web interface to user
  • Displays video stream using <img> tag
  • Lets user adjust detection settings
  • Makes API calls to backend

What it DOESN'T do:

  • No AI processing
  • No video file handling
  • No direct ESP32 connection (goes through backend)

Example calls:

// Display stream with detection
<img src="http://localhost:8069/stream/detect?conf=0.25" />

// Detect license plate
fetch('http://localhost:8069/api/plate-detect', {
  method: 'POST',
  body: JSON.stringify({ imageData: '...' })
})

2๏ธโƒฃ Backend (FastAPI on port 8069)

What it does:

  • Runs YOLO AI model (with CUDA)
  • Processes video frames in real-time
  • Adds bounding boxes to detections
  • Proxies stream from ESP32 server
  • Saves detection results to Firebase

What it DOESN'T do:

  • No user interface
  • No video file storage
  • No direct browser interaction

How it processes a frame:

1. Frontend requests: GET /stream/detect
2. Backend connects to: http://localhost:5069/stream
3. For each frame:
   a. Read JPEG frame from ESP32
   b. Run YOLO detection (GPU accelerated)
   c. Draw bounding boxes + labels
   d. Send annotated frame to frontend
4. Loop continuously

APIs it provides:

  • GET /stream โ†’ Raw stream proxy (no AI)
  • GET /stream/detect โ†’ Stream with AI detection
  • POST /api/plate-detect โ†’ Detect license plates
  • POST /api/object-tracking โ†’ Track objects in video
  • GET /health โ†’ Check if backend is alive

3๏ธโƒฃ ESP32 Server (Port 5069)

What it does:

  • Provides raw video stream (MJPEG format)
  • In development: Streams from video files
  • In production: Streams from real ESP32-CAM camera

What it DOESN'T do:

  • No AI processing
  • No detection or tracking
  • No data storage
  • Just streams video

How to switch modes:

# Development (video files)
python start_mock.py --video parking.mp4 --port 5069

# Production (real hardware)
# Flash ESP32-CAM firmware, it runs on port 81
# Update backend: VITE_ESP32_URL=http://192.168.33.122:81

Complete Request Flow Example

Scenario: User views stream with object detection

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  User    โ”‚ Opens browser โ†’ http://localhost:5169
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚
     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  FRONTEND (React)                        โ”‚
โ”‚  StreamViewerPageESP32.tsx               โ”‚
โ”‚                                          โ”‚
โ”‚  <img src="http://localhost:8069/       โ”‚
โ”‚            stream/detect?conf=0.25" />   โ”‚
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚ HTTP GET Request
     โ”‚ (Browser automatically requests image)
     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  BACKEND (FastAPI)                       โ”‚
โ”‚  main_fastapi.py                         โ”‚
โ”‚                                          โ”‚
โ”‚  @app.get("/stream/detect")              โ”‚
โ”‚  1. Connect to ESP32                     โ”‚ โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  2. Read frame from ESP32                โ”‚      โ”‚
โ”‚  3. Run YOLO model (GPU)                 โ”‚      โ”‚
โ”‚  4. Draw bounding boxes                  โ”‚      โ”‚
โ”‚  5. Send back to frontend                โ”‚      โ”‚
โ”‚  6. Repeat for next frame                โ”‚      โ”‚
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
     โ”‚                                            โ”‚
     โ”‚ HTTP GET /stream                           โ”‚
     โ”‚                                            โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                   โ–ผ
                                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                    โ”‚  ESP32 SERVER            โ”‚
                                    โ”‚  mock_esp32_server.py    โ”‚
                                    โ”‚                          โ”‚
                                    โ”‚  Reads video file        โ”‚
                                    โ”‚  Sends MJPEG frames      โ”‚
                                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Scenario: User detects license plate

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  User    โ”‚ Clicks "Detect Plate" button
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚
     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  FRONTEND                                โ”‚
โ”‚  Captures current frame                  โ”‚
โ”‚  Converts to base64                      โ”‚
โ”‚  fetch('http://localhost:8069/           โ”‚
โ”‚        api/plate-detect', {              โ”‚
โ”‚    body: { imageData: 'base64...' }      โ”‚
โ”‚  })                                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚ HTTP POST
     โ”‚ { imageData: "data:image/jpeg;base64,..." }
     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  BACKEND                                 โ”‚
โ”‚  1. Decode base64 image                  โ”‚
โ”‚  2. Run YOLO (detect vehicles)           โ”‚
โ”‚  3. Run ALPR (read plate text)           โ”‚
โ”‚  4. Save to Firebase                     โ”‚ โ”€โ”€โ†’ Firebase
โ”‚  5. Return results                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚ Response
     โ”‚ { plates: [{ text: "ABC123", confidence: 0.95 }] }
     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  FRONTEND                                โ”‚
โ”‚  Displays plate number to user           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Why This Architecture?

Separation of Concerns

  • Frontend: User interface only (React is good at this)
  • Backend: Heavy AI processing (Python is good at this)
  • ESP32: Video streaming only (cheap hardware)

Advantages

  1. โœ… Frontend stays simple - No AI models to download
  2. โœ… Backend can use GPU - Fast CUDA processing
  3. โœ… ESP32 is lightweight - Just streams video
  4. โœ… Easy to scale - Add more backends for load balancing
  5. โœ… Development friendly - Can use video files instead of real hardware

Why Backend is the Middleman?

  • CORS: Browsers block direct camera connections
  • Processing: Need server-side GPU for AI
  • Security: Don't expose ESP32 directly to internet
  • Flexibility: Can switch between dev/prod streams easily

Communication Protocols

Connection Protocol Format Purpose
Browser โ†’ Frontend HTTP/HTTPS HTML/JS/CSS Load webpage
Frontend โ†’ Backend HTTP REST JSON API calls, commands
Frontend โ† Backend HTTP MJPEG JPEG frames Video stream
Backend โ†’ ESP32 HTTP MJPEG Fetch video
Backend โ†’ Firebase HTTPS JSON Store data

Port Summary

localhost:5169  โ†’  Frontend (React dev server)
localhost:8069  โ†’  Backend (FastAPI + AI)
localhost:5069  โ†’  ESP32 Server (Video source)

Key Point: Frontend NEVER talks to ESP32 directly. Always goes through Backend.


Data Flow for Real-Time Detection

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Video File  โ”‚ (parking.mp4)
โ”‚ or Camera   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚ 30 FPS
       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ESP32 Server   โ”‚  Encodes frames โ†’ MJPEG
โ”‚  (Port 5069)    โ”‚  Sends continuous stream
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚ MJPEG Stream (~30 FPS)
       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Backend (Port 8069)            โ”‚
โ”‚                                 โ”‚
โ”‚  For each frame:                โ”‚
โ”‚  1. Decode JPEG                 โ”‚  โ† 10ms (CPU)
โ”‚  2. Run YOLO detection          โ”‚  โ† 10ms (GPU) โšก
โ”‚  3. Draw bounding boxes         โ”‚  โ† 2ms (CPU)
โ”‚  4. Encode back to JPEG         โ”‚  โ† 5ms (CPU)
โ”‚  Total: ~27ms = ~37 FPS         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚ MJPEG with annotations (~30 FPS)
       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Frontend       โ”‚  Browser decodes & displays
โ”‚  (Port 5169)    โ”‚  User sees annotated video
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Note: GPU processes ~100 FPS but stream is 30 FPS, so detection is real-time with overhead.


Quick Architecture Check

To verify everything is connected correctly:

# 1. Check ESP32 is streaming
curl http://localhost:5069/status
# Expected: {"device":"ESP32-CAM Mock","status":"idle",...}

# 2. Check backend can reach ESP32
curl http://localhost:8069/stream | head -c 1000
# Expected: Binary JPEG data (should show bytes)

# 3. Check frontend can reach backend
curl http://localhost:8069/health
# Expected: {"status":"ok","models_loaded":true,...}

# 4. Check frontend is running
curl http://localhost:5169
# Expected: HTML content

If all 4 work โ†’ Architecture is correctly set up! โœ…

๏ฟฝ Port Configuration

Service Port URL Purpose
Frontend 5169 http://localhost:5169 React Vite dev server
Backend 8069 http://localhost:8069 FastAPI REST API + AI
ESP32 Dev 5069 http://localhost:5069 Development streaming
ESP32 Prod 81 http://192.168.x.x:81 Real hardware streaming

๐Ÿ“ Project Structure

SmartParking/
โ”œโ”€โ”€ frontend/              # React + TypeScript frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ pages/        # Page components
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ StreamViewerPageESP32.tsx  # Main stream viewer
โ”‚   โ”‚   โ”œโ”€โ”€ components/   # Reusable components
โ”‚   โ”‚   โ”œโ”€โ”€ config/       # API configuration
โ”‚   โ”‚   โ””โ”€โ”€ services/     # API services
โ”‚   โ”œโ”€โ”€ .env             # Environment variables
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ server/               # FastAPI backend
โ”‚   โ”œโ”€โ”€ main_fastapi.py  # Main API server (CUDA enabled)
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”‚   โ”œโ”€โ”€ ai_service.py        # YOLO + ALPR (GPU accelerated)
โ”‚   โ”‚   โ””โ”€โ”€ firebase_service.py  # Firebase integration
โ”‚   โ”œโ”€โ”€ yolov8s_car_custom.pt   # Custom trained model
โ”‚   โ”œโ”€โ”€ yolov8n.pt              # Default YOLO model
โ”‚   โ””โ”€โ”€ requirements.txt
โ”‚
โ”œโ”€โ”€ ESP32/                # ESP32-CAM integration
โ”‚   โ”œโ”€โ”€ mock_esp32_server.py    # Development server
โ”‚   โ”œโ”€โ”€ esp32_cam_firmware.ino  # Real hardware firmware
โ”‚   โ”œโ”€โ”€ esp32_client.py         # Python client library
โ”‚   โ”œโ”€โ”€ start_mock.py           # Quick start script
โ”‚   โ”œโ”€โ”€ test_esp32_connection.py # Testing utilities
โ”‚   โ”œโ”€โ”€ stream/                  # Video files (dev)
โ”‚   โ””โ”€โ”€ HARDWARE_SETUP.md
โ”‚
โ””โ”€โ”€ docs/                 # Documentation
    โ”œโ”€โ”€ QUICK_START_OBJECT_TRACKING.md
    โ”œโ”€โ”€ PORT_CONFIGURATION.md
    โ”œโ”€โ”€ ENVIRONMENT_VARIABLES.md
    โ””โ”€โ”€ ESP32_REFACTOR.md

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10+ (conda environment: scheduler)
  • Node.js 18+
  • CUDA 11.8+ (for GPU acceleration)
  • NVIDIA GPU with 4GB+ VRAM (recommended)

1. Start ESP32 Streaming Server

cd ESP32
python start_mock.py --video videos/parking_c.mp4 --port 5069

2. Start Backend (with CUDA)

cd server
eval "$(conda shell.bash hook)" && conda activate scheduler
python main_fastapi.py

Expected output:

๐Ÿš€ Starting FastAPI SmartParking Server...
๐Ÿ“ฆ Loading AI models...
๐Ÿ”ฅ Using CUDA device: NVIDIA GeForce RTX 3090
โœ… YOLO model loaded on cuda:0
โœ… ALPR model loaded
๐Ÿ“น Connecting to ESP32: http://localhost:5069
โœ… ESP32 connected

3. Start Frontend

cd frontend
npm install  # First time only
npm run dev

4. Open Browser

Navigate to: http://localhost:5169

Select viewing mode:

  • ๐ŸŽฏ Object Detection - Real-time YOLO detection with bounding boxes
  • ๐Ÿ“น Raw Stream - Original stream without processing
  • โšก Direct Stream - Bypass backend proxy

๐ŸŽฏ Features

AI-Powered Detection

  • โœ… YOLOv8s Custom Model - Trained on parking lot dataset (mAP50: 99.49%)
  • โœ… CUDA Acceleration - 10-30x faster inference on GPU
  • โœ… Real-time Object Detection - Cars, motorcycles, persons
  • โœ… Object Tracking - ByteTrack algorithm for consistent IDs
  • โœ… License Plate Recognition - Fast-ALPR with ONNX runtime

Streaming Modes

  • ๐ŸŽฏ Object Detection Mode - Annotated stream with bounding boxes
  • ๐Ÿ“น Raw Stream Mode - Original video feed
  • โšก Direct Stream Mode - Direct ESP32 connection
  • โš™๏ธ Adjustable Settings - Confidence threshold, labels on/off

Development Features

  • ๐Ÿ”„ Hot Reload - Frontend and backend auto-reload on changes
  • ๐ŸŽฌ Mock Streaming - Test without ESP32 hardware
  • ๐Ÿ“Š API Documentation - Auto-generated at /docs
  • ๐Ÿ” Health Checks - Monitor service status

๐ŸŽฎ API Endpoints

Streaming

# Raw stream proxy
GET http://localhost:8069/stream

# Stream with real-time detection
GET http://localhost:8069/stream/detect?conf=0.25&show_labels=true

# Parameters:
#   conf: Confidence threshold (0.1-0.9, default: 0.25)
#   show_labels: Show detection labels (true/false, default: true)

Detection APIs

# License plate detection
POST http://localhost:8069/api/plate-detect
Body: { "imageData": "data:image/jpeg;base64,..." }

# Object tracking on video
POST http://localhost:8069/api/object-tracking
Body: { 
  "videoData": "data:video/mp4;base64,...",
  "confThreshold": 0.25,
  "iouThreshold": 0.45
}

# ESP32 snapshot
GET http://localhost:8069/api/esp32/snapshot

# ESP32 status
GET http://localhost:8069/api/esp32/status

Health & Testing

# Backend health check
GET http://localhost:8069/health

# Test ESP32 connection
GET http://localhost:8069/test/esp32

# API documentation (Swagger)
GET http://localhost:8069/docs

โš™๏ธ Configuration

Frontend (.env)

# Backend API
VITE_BACKEND_URL=http://localhost:8069

# ESP32-CAM URL (development or production)
VITE_ESP32_URL=http://localhost:5069

# Firebase (optional)
VITE_FIREBASE_API_KEY=your_key
VITE_FIREBASE_AUTH_DOMAIN=your_domain
VITE_FIREBASE_PROJECT_ID=your_project_id

Backend (environment variables)

# ESP32 Configuration
USE_MOCK_ESP32=true                          # false for real hardware
MOCK_ESP32_URL=http://localhost:5069         # Development server
ESP32_URL=http://192.168.33.122:81           # Real ESP32-CAM IP

# CUDA Configuration (automatic detection)
# Set CUDA_VISIBLE_DEVICES=0 to select GPU
# Model automatically uses CUDA if available

๐ŸŽฏ Object Tracking Performance

Model Specifications

  • Model: YOLOv8s Custom (parking lot trained)
  • mAP50: 99.49%
  • Classes: Car, Motorcycle, Person, Truck
  • Input Size: 640x640
  • Framework: Ultralytics YOLO

Performance Benchmarks

Hardware FPS (Detection) Latency VRAM Usage
NVIDIA RTX 3090 ~100 FPS 10ms 2.5GB
NVIDIA RTX 3080 ~80 FPS 12ms 2.5GB
NVIDIA GTX 1080 ~50 FPS 20ms 2.0GB
CPU (16 cores) ~8 FPS 125ms N/A

๐Ÿ”ง Troubleshooting

No stream visible

  1. Check ESP32 server: curl http://localhost:5069/status
  2. Check backend: curl http://localhost:8069/health
  3. Test stream: curl http://localhost:8069/stream | head -c 1000
  4. Restart services in order: ESP32 โ†’ Backend โ†’ Frontend

CUDA not detected

# Check CUDA availability
python -c "import torch; print(torch.cuda.is_available())"

# Check GPU
nvidia-smi

# Install CUDA-enabled PyTorch
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118

Slow detection speed

  • Verify CUDA is enabled (check backend startup logs)
  • Lower confidence threshold
  • Use smaller model (yolov8n.pt instead of yolov8s)
  • Reduce input resolution

Port conflicts

# Check what's using ports
lsof -i :5069  # ESP32
lsof -i :8069  # Backend
lsof -i :5169  # Frontend

# Kill process on port
kill -9 $(lsof -ti :5069)

๐Ÿ“š Documentation

Detailed guides available in project root:

  • QUICK_START_OBJECT_TRACKING.md - Complete setup guide
  • PORT_CONFIGURATION.md - Port management and troubleshooting
  • ENVIRONMENT_VARIABLES.md - Configuration reference
  • ESP32/README.md - ESP32 integration guide
  • ESP32/HARDWARE_SETUP.md - Hardware wiring and setup
  • ESP32_REFACTOR.md - Architecture overview

๐Ÿ”’ Security Notes

  • Frontend .env variables are PUBLIC (embedded in JS bundle)
  • Never put secrets in VITE_* variables
  • Firebase config is safe to expose (protected by Security Rules)
  • Backend environment variables are PRIVATE (server-only)
  • Add .env to .gitignore

๐Ÿš€ Production Deployment

With Real ESP32-CAM Hardware

  1. Flash ESP32 firmware (see ESP32/HARDWARE_SETUP.md)
  2. Configure production URLs:
    # Frontend .env
    VITE_BACKEND_URL=https://api.yourserver.com
    VITE_ESP32_URL=http://192.168.33.122:81
    
    # Backend
    export USE_MOCK_ESP32=false
    export ESP32_URL=http://192.168.33.122:81
  3. Build frontend: npm run build
  4. Deploy frontend/dist/ to web server
  5. Run backend with production settings

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch: git checkout -b feature/YourFeature
  3. Commit changes: git commit -m 'Add YourFeature'
  4. Push to branch: git push origin feature/YourFeature
  5. Open Pull Request

๐Ÿ“„ License

[Your License Here]

๐Ÿ‘ฅ Team

[Your Team Info]


Tech Stack: React ยท TypeScript ยท Vite ยท Python ยท FastAPI ยท YOLOv8 ยท PyTorch ยท CUDA ยท OpenCV ยท Firebase ยท ESP32-CAM

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •