Integrated Traffic Detection and Counting System with YOLOv8 Backend#4
Integrated Traffic Detection and Counting System with YOLOv8 Backend#4hardihardi wants to merge 15 commits into
Conversation
…tion - Implemented `backend/traffic_counter.py` for YOLOv8 object tracking and vehicle counting. - Implemented `backend/app.py` Flask API for video upload, URL processing, and MJPEG streaming. - Integrated `yt-dlp` for YouTube stream support. - Refactored `src/components/traffic/traffic-dashboard.tsx` to communicate with the backend. - Updated frontend charts and stats components to display live data from the backend. - Added secure file handling and memory management for stats history. - Verified backend logic with `backend/test_api.py`. Co-authored-by: hardihardi <99262645+hardihardi@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideIntroduces a new Flask-based YOLOv8 backend for real-time vehicle detection/counting and wires the existing Next.js traffic dashboard to consume live stats/streaming frames from this backend instead of using simulated data, including SKR calculations and moving-average volume charts. Sequence diagram for starting and running backend-powered traffic analysissequenceDiagram
actor User
participant TrafficDashboard
participant FlaskBackend
participant TrafficCounter
participant VideoSource
User->>TrafficDashboard: Select_source_and_click_Start
alt Source_is_URL
TrafficDashboard->>FlaskBackend: POST /process-url (url)
FlaskBackend->>FlaskBackend: stop_existing_processing
FlaskBackend->>TrafficCounter: reset()
FlaskBackend->>VideoSource: resolve_stream_url
FlaskBackend->>FlaskBackend: start_thread(process_video)
else Source_is_file
TrafficDashboard->>FlaskBackend: POST /upload-video (FormData(video))
FlaskBackend->>FlaskBackend: stop_existing_processing
FlaskBackend->>TrafficCounter: reset()
FlaskBackend->>VideoSource: save_file_and_open
FlaskBackend->>FlaskBackend: start_thread(process_video)
end
loop process_video_thread
FlaskBackend->>VideoSource: read_frame()
VideoSource-->>FlaskBackend: frame
FlaskBackend->>TrafficCounter: process_frame(frame)
TrafficCounter-->>FlaskBackend: processed_frame
FlaskBackend->>FlaskBackend: update_current_frame
end
loop every_2_seconds_while_analyzing
TrafficDashboard->>FlaskBackend: GET /traffic-stats
FlaskBackend->>TrafficCounter: get_stats()
TrafficCounter-->>FlaskBackend: counts_and_moving_average
FlaskBackend-->>TrafficDashboard: stats_json
TrafficDashboard->>TrafficDashboard: update_backendStats_and_charts
end
par Live_video_stream
TrafficDashboard->>FlaskBackend: GET /stream
loop while_processing
FlaskBackend-->>TrafficDashboard: multipart_jpeg_frame
end
and User_stops_analysis
User->>TrafficDashboard: Click_Stop
TrafficDashboard->>FlaskBackend: POST /stop
FlaskBackend->>FlaskBackend: is_processing = False
end
Class diagram for YOLOv8-based TrafficCounterclassDiagram
class TrafficCounter {
- YOLO model
- float line_y_ratio
- dict counts
- dict skr_coefficients
- dict track_history
- set counted_ids
- list history_data
+ TrafficCounter(model_path, line_y)
+ float get_skr(cls_name)
+ ndarray process_frame(frame)
+ dict get_stats()
+ reset()
}
class YOLO {
+ track(frame, persist, verbose)
}
TrafficCounter --> YOLO : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…tion - Implemented `backend/traffic_counter.py` for YOLOv8 object tracking and vehicle counting. - Implemented `backend/app.py` Flask API for video upload, URL processing, and MJPEG streaming. - Integrated `yt-dlp` for YouTube stream support. - Refactored `src/components/traffic/traffic-dashboard.tsx` to communicate with the backend. - Updated frontend charts and stats components to display live data from the backend. - Added secure file handling and memory management for stats history. - Verified backend logic with `backend/test_api.py`. - Updated documentation and added `backend/requirements.txt`. Co-authored-by: hardihardi <99262645+hardihardi@users.noreply.github.com>
This commit introduces a complete traffic monitoring solution consisting of: - A Flask backend powered by YOLOv8 for vehicle tracking and directional counting (Mendekat/Menjauh). - Automated SKR (PCU) calculation and rolling 15-minute moving average analytics. - Support for YouTube stream processing and local MP4 file uploads. - A highly responsive Next.js frontend with specialized layouts for Desktop (Grid) and Mobile (Tabs). - Dynamic ROI configuration and multi-format (XLSX/CSV) data export capabilities. Co-authored-by: hardihardi <99262645+hardihardi@users.noreply.github.com>
- Added `render.yaml` for automated deployment of Flask backend and Next.js frontend. - Created `.env.example` to document required environment variables. - Updated README.md with detailed deployment instructions to resolve Vercel-to-Backend connection issues. - Optimized frontend backend-discovery and connection error handling. - Cleaned up redundant model files and build artifacts. Co-authored-by: hardihardi <99262645+hardihardi@users.noreply.github.com>
This commit delivers the complete VisionPulse Traffic AI system: - **AI Backend**: Flask server with YOLOv8 tracking, directional counting, SKR (PCU) calculation, and 15-minute moving averages. - **Frontend**: Responsive Next.js 15 dashboard with dual layouts (Desktop Grid/Mobile Tabs), live chart integration, and MJPEG stream viewing. - **Robust Connectivity**: Implemented 'Simulation Mode' toggle and automated fallback to ensure UI functionality when the backend is offline. - **Deployment**: Added `render.yaml` Blueprint and `.env.example` for automated, multi-service deployment on Render/Vercel. - **Tools**: Integrated support for YouTube stream processing and multi-format (XLSX/CSV) data export. Co-authored-by: hardihardi <99262645+hardihardi@users.noreply.github.com>
This PR transitions the Traffic Detection System from a simulation-based prototype to a functional real-time analysis system.
Key changes:
Backend Development: Created a Python Flask backend in the
backend/directory.traffic_counter.py: Uses YOLOv8 (viaultralytics) to track vehicles and count them as they cross a virtual line. It supports two directions ('Mendekat' and 'Menjauh') and calculates SKR (Satuan Kendaraan Roda Empat) based on the PRD coefficients.app.py: Provides API endpoints for uploading videos, processing YouTube URLs (usingyt-dlp), and retrieving real-time statistics. It also serves a live MJPEG stream of processed frames.Frontend Integration:
TrafficDashboard: Connects to the Flask API, sends video/URL for processing, and displays the live/streamfrom the backend.VehicleVolume& Charts: Updated to usebackendStatsprovided by the dashboard's polling mechanism, showing real vehicle counts and SKR analysis.process.env.NEXT_PUBLIC_BACKEND_URLfor flexible backend configuration.Cleanup and Verification:
backend/test_api.py.To run the system:
pip install flask flask-cors opencv-python-headless ultralytics yt-dlp werkzeug.python3 backend/app.py.npm run dev -- -p 9002.PR created automatically by Jules for task 230004736315457304 started by @hardihardi
Summary by Sourcery
Integrate a YOLOv8-powered Flask backend for real-time traffic detection and counting and wire it into the existing traffic dashboard for live visualization.
New Features:
Enhancements:
Tests: