SmartBin WBC — case-study key art

Architflix Original

SmartBin WBC

2023AICase study

A dual-subsystem smart-bin project: a hardened Node/Express + SQLite QR-feedback dashboard, plus a Python OpenCV/TensorFlow ensemble that classifies waste as biodegradable vs non-biodegradable and drives an Arduino to sort it.

Overview

SmartBin WBC is a dual-subsystem smart-bin project that pairs a hardened Node/Express + SQLite QR-feedback dashboard with a Python OpenCV/TensorFlow ensemble which classifies waste as biodegradable vs non-biodegradable and drives an Arduino to sort it — real, CI-green engineering whose classification accuracy has not yet been formally benchmarked.

Season 1 · The Build5 episodes

A dual-subsystem smart-bin project: a hardened Node/Express + SQLite QR-feedback dashboard, plus a Python OpenCV/TensorFlow ensemble that classifies waste as biodegradable vs non-biodegradable and drives an Arduino to sort it.

Built with Python, OpenCV, TensorFlow, Node.js, Express, and 2 more.

PythonOpenCVTensorFlowNode.jsExpressSQLiteArduino

Smartbin-WBC bundles two halves of a "smart bin" idea. The first is a LAN-hosted feedback dashboard (Node.js + Express + WASM SQLite): scan a QR code on a bin, leave a thumbs-up/down and optional comment, and operators get per-bin sentiment, aggregate views, and CSV export — with a genuinely production-shaped backend (helmet, session auth, rate limiting, express-validator, XSS sanitization, SHA-256 IP hashing, morgan logging, a /health endpoint, and centralized error handling). The second is a Python computer-vision waste classifier that fuses an ML model with classical CV — HSV/LAB color masks, Canny/Sobel texture, contour shape features — via weighted fusion (ml 0.50 / color 0.20 / texture 0.15 / shape 0.15), smoothed over a 7-frame temporal window, then sends '1' or '2' over serial to an Arduino that drives LEDs and a sorting servo. The interesting engineering isn't the happy path; it's the two documented obstacles: a red segmentation tray that ironically blocked any object placed on it from being classified (fixed by masking the red background instead of waiting on it), and an empty-tray ZeroDivisionError that crashed the pipeline seconds after launch (fixed with a zero-score guard and per-frame try/except). Dual-language GitHub Actions CI (Node 16/18 supertest + Python 3.10/3.11 syntax check) runs green.

  • QR-code feedback flow: scan a bin's code, submit thumbs-up/down plus an optional comment (GET/POST /f/:binId).
  • Admin dashboard with per-bin counts, sentiment totals, and CSV export (/admin/export.csv) behind session auth.
  • Production-shaped Express backend: helmet, express-rate-limit (10 POST/min on feedback), express-validator, XSS sanitization, SHA-256 IP hashing, morgan, /health, centralized error + 404 handling.
  • WASM SQLite (sql.js) store with a CHECK constraint on sentiment, two indexes, and parameterized statements.
  • Hybrid waste classifier fusing ML predictions with HSV/LAB color, Canny/Sobel texture, and contour shape features via tuned weights, smoothed over a 7-frame temporal window.
  • Multiple speed/accuracy classifier variants (ensemble, binary_ensemble, fast_binary, ultrafast_cv, classifier_with_arduino) for different hardware budgets.
  • Real Arduino integration: pyserial sends '1'/'2' to firmware that drives green/red LEDs and a sorting servo (45 deg / 135 deg).
  • Tray calibration and troubleshooting tooling (calibrate_tray.py, test_red_tray_detection.py, fix_camera.py).
  • Dual-language GitHub Actions CI: Node 16.x/18.x supertest suite plus Python 3.10/3.11 compileall syntax check.

Every project hits walls. Here's what nearly broke SmartBin WBC — and how it shipped anyway.

  • Red-tray paradox: the tray used to segment objects also dominated the frame, so an object placed on it stayed stuck on 'WAITING' and was never classified — required inverting the logic to mask the red background rather than detect-and-wait.
  • Empty-tray ZeroDivisionError: with no object, both class score sums were 0.0 and the confidence calc divided by their sum, crashing the program ~2s after start; fixed with a near-zero guard and try/except around classification and decision-making.
  • Making a fused classifier stable frame-to-frame instead of flickering between labels — addressed with a deque-backed temporal smoother over a 7-frame window.
  • Keeping multiple speed/accuracy variants (full ensemble down to ultrafast_cv) coherent for constrained hardware.
  • Getting a two-language CI matrix (Node + Python) green in one workflow.
  • Real accuracy was never clearly measured — the quoted numbers read as expectations, not benchmarks (open gap).

Every build leaves residue. The takeaways from SmartBin WBC that carry forward.

  • A hybrid ML + classical-CV ensemble degrades more gracefully than a single model on cheap, dataset-poor setups — the CV signals are a cheap stability backstop.
  • Physical setup choices (a red tray) can silently sabotage a vision pipeline; the fix was a logic inversion, not more model tuning.
  • Guard every division that depends on runtime-variable sums, and wrap per-frame work in try/except so one bad frame can't kill a long-running loop.
  • Even a LAN-only web app benefits from real middleware discipline (rate limiting, validation, sanitization, IP hashing) — cheap to add, and it's the difference between a toy and something defensible.
  • Temporal smoothing over a short frame window is a simple, effective way to stop label flicker in live inference.
  • Publishing 'expected accuracy' without a measured test set is a credibility gap — numbers need a named dataset behind them.