Live color tracking — computer vision in the browser
Track a coloured object in real time: convert each webcam frame to HSV, threshold a colour range with cv2.inRange, and box the biggest blob — the basis of colour-based object tracking in computer vision. Runs client-side (nothing uploaded). Press Run, allow the camera, and tweak the colour bounds for your object.
Example code (Python / OpenCV)
"""
Live color tracking
Track a coloured object in real time: convert each webcam frame to HSV, threshold a colour range with cv2.inRange, and box the biggest blob — the basis of colour-based object tracking in computer vision. Runs client-side (nothing uploaded). Press Run, allow the camera, and tweak the colour bounds for your object.
"""
import cv2
import numpy as np
# The camera starts automatically on Run — allow access when prompted.
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
print("No camera frame — allow camera access when prompted.")
break
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Track a colour — default: blues. Tweak the bounds for your object.
mask = cv2.inRange(hsv, (95, 90, 60), (130, 255, 255))
cnts, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
if cnts:
c = max(cnts, key=cv2.contourArea)
if cv2.contourArea(c) > 500:
x, y, w, h = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("tracking", frame)
cv2.imshow("mask", mask)
if cv2.waitKey(1) == 27: # Esc / Stop
break