✅ Complete browser-based webcam capture implementation
- Frontend captures video using browser's getUserMedia API
- Frames sent to backend for YOLO processing every 1 second
- Real-time seat detection and occupancy tracking
- Multi-page GUI with seat map and analytics
┌─────────────────────────────────────────────────┐
│ Browser (Your Computer) │
│ - Captures webcam via getUserMedia() │
│ - Triggers permission popup │
│ - Sends frames every 1 second │
└────────────────┬────────────────────────────────┘
│
│ POST /api/process/frame
│ (Base64 JPEG frame)
↓
┌─────────────────────────────────────────────────┐
│ Backend (Docker/Server) │
│ - Receives frame from browser │
│ - Runs YOLOv7 detection │
│ - SORT tracking for seat management │
│ - Returns detection results │
└────────────────┬────────────────────────────────┘
│
│ JSON response
│ {occupancy, detections}
↓
┌─────────────────────────────────────────────────┐
│ Browser UI │
│ - Updates stats display │
│ - Draws bounding boxes │
│ - Updates seat map (movie-style grid) │
│ - Shows analytics │
└─────────────────────────────────────────────────┘
api/main.py- Added webcam_browser routes (line 93)static/js/app.js- COMPLETED with all helper functionsstatic/js/app-browser.js- COMPLETED (same as app.js)
api/routes/webcam_browser.py- Browser frame processing endpointsapi/services/frame_processor.py- YOLOv7 + SORT processingstatic/app.html- Multi-page web interfacestatic/css/styles.css- Complete styling
python run_api.pyOr using uvicorn directly:
python -m uvicorn api.main:app --host 0.0.0.0 --port 8000 --reloadExpected output:
INFO: Started server process
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000
Open your browser and navigate to:
http://localhost:8000
- Click the "Start Camera" button
- You should see a browser permission popup asking:
http://localhost:8000 wants to use your camera [Block] [Allow] - Click "Allow"
This is the key test - if you see this popup, the browser-based capture is working!
After allowing camera access:
- Video feed should appear in the video container
- Status should change to "Camera Running" (green)
- Activity log should show "Camera started successfully"
Watch the terminal/console where the server is running:
INFO: Processing frame...
INFO: Detected 2 persons, 3 chairs
INFO: Tracked 3 seats
On the web interface, you should see updates every 1 second:
- Live Statistics cards updating
- Available/Occupied seat counts changing
- Activity log showing new entries
- Click "Seat Map" in the navigation
- Should see a grid of seats (movie-style booking interface)
- Colors:
- 🟢 Green = Available seat
- 🔴 Red = Occupied seat
- 🟠 Orange = Time exceeded
- Click "Analytics" in the navigation
- Should see:
- Occupancy percentage bar
- Average duration
- Peak usage time
- Detailed seat table
- ✅ Chrome 90+ (Recommended)
- ✅ Firefox 88+
- ✅ Edge 90+
- ✅ Safari 14+
Chrome: http://localhost:8000
Firefox: http://localhost:8000
Edge: http://localhost:8000
curl http://localhost:8000/healthExpected:
{
"status": "healthy",
"version": "1.0.0",
"timestamp": "2025-11-14T..."
}curl http://localhost:8000/api/process/statsExpected:
{
"success": true,
"occupancy": {
"total_seats": 0,
"occupied_seats": 0,
"available_seats": 0,
...
}
}Open browser console (F12) and run:
// Test 1: Check camera access
navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
console.log('✅ Camera access works!', stream);
stream.getTracks().forEach(track => track.stop()); // Stop test stream
})
.catch(err => console.error('❌ Camera error:', err));
// Test 2: Test backend API
fetch('/api/process/stats')
.then(res => res.json())
.then(data => console.log('✅ Backend API works:', data))
.catch(err => console.error('❌ API error:', err));- Button state changes: "Start Camera" → "Starting..." → disabled
- Permission popup appears (THIS IS KEY!)
- User clicks "Allow"
- Video feed appears
- Status badge: "Camera Stopped" → "Camera Running" (green)
- Console logs: "Requesting camera access..." → "Camera access granted!" → "Video playing"
- Activity log: "Camera started successfully"
- Frame processing starts (1 frame per second)
- Stats update every 1 second
- Bounding boxes appear on video (if detections found)
- Activity log shows seat changes
- Seat map updates in real-time
- Analytics page shows current metrics
- Button state: "Stop Camera" → "Stopping..." → disabled
- Video stops
- Camera light turns off (hardware indicator)
- Status: "Camera Running" → "Camera Stopped"
- Stats reset to 0
- Placeholder appears: "Click Start Camera to begin monitoring"
Cause: Camera already blocked or using wrong URL
Fix:
- Click camera icon in browser address bar
- Change to "Allow"
- Refresh page
- Ensure using
http://localhost:8000(not IP address)
Cause: User clicked "Block"
Fix:
- Chrome:
chrome://settings/content/camera - Firefox: Settings → Privacy & Security → Permissions → Camera
- Remove block for
http://localhost:8000 - Refresh page
Cause: Another app using camera
Fix:
- Close Zoom, Teams, Skype, etc.
- Close other browser tabs
- Restart browser
Check server logs for:
ModuleNotFoundError: No module named 'cv2'→ Runpip install opencv-python- Model loading errors → Check
yolov7.ptfile exists - CUDA errors → Set
MODEL_DEVICE=cpuin.env
Cause: Poor lighting or camera angle
Fix:
- Point camera at seating area
- Improve lighting
- Lower threshold:
MODEL_CONF_THRESHOLD=0.3in.env - Check console for detection logs
Check browser console (F12) for:
- Network errors (red in Network tab)
- JavaScript errors
- API response errors
Fix:
- Verify backend is running
- Check
/api/process/frameendpoint responds - Ensure no CORS errors
- Default: 1 FPS (1 frame per second)
- Adjustable in
app.jsline 250:setInterval(processFrame, 1000) - Faster:
setInterval(processFrame, 500)= 2 FPS - Slower:
setInterval(processFrame, 2000)= 0.5 FPS
- Default: 0.8 quality (80%)
- Adjustable in
app.jsline 277:toDataURL('image/jpeg', 0.8) - Higher quality:
0.9(larger file, slower) - Lower quality:
0.5(smaller file, faster)
✅ Camera permission popup appears ✅ Video feed displays in browser ✅ Stats update every 1 second ✅ Seat map shows colored seats ✅ Activity log shows real-time events ✅ No console errors ✅ Server processes frames successfully ✅ Works with Docker/remote deployment
If all tests pass:
-
Test with actual seating area:
- Position camera to view chairs
- Ensure good lighting
- Watch detections appear
-
Test seat tracking:
- Sit in a chair
- Verify seat changes to "occupied" (red)
- Stand up
- Verify seat changes to "available" (green)
-
Test duration tracking:
- Occupy a seat for 2+ minutes
- Check analytics page for duration
- Verify time exceeded warning (orange) after threshold
-
Deploy to production:
- Use HTTPS for remote access
- Configure camera angles
- Set appropriate confidence thresholds
If issues persist:
- Check browser console (F12) for errors
- Check server logs for backend errors
- Review
BROWSER_WEBCAM_SETUP.mdfor detailed architecture - Test API endpoints individually
- Verify camera works in other apps
The browser-based webcam capture system is complete and ready to test:
- ✅ Frontend captures webcam (triggers permission popup)
- ✅ Sends frames to backend every 1 second
- ✅ Backend processes with YOLOv7 + SORT
- ✅ Real-time UI updates (stats, seat map, analytics)
- ✅ Works with Docker deployment
- ✅ Multi-page GUI interface
- ✅ Movie-style seat visualization
Start testing now by running the server and opening http://localhost:8000!