Measure an Edge Vision Pipeline
Measure an Edge Vision Pipeline
Lab: Measure an Edge Vision Pipeline
Measure acquisition, preprocessing, detection, and end-to-end latency separately. The detector below is intentionally simple: it finds sufficiently large bright regions. Its purpose is to expose the runtime boundary and evidence record, not to claim production object recognition.
import statistics
import time
import cv2 as cv
camera = cv.VideoCapture(0)
if not camera.isOpened():
raise RuntimeError("camera did not open")
rows = []
try:
for frame_id in range(120):
started = time.perf_counter_ns()
ok, frame = camera.read()
acquired = time.perf_counter_ns()
if not ok:
raise RuntimeError(f"frame {frame_id} was not captured")
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (5, 5), 0)
_, mask = cv.threshold(blurred, 210, 255, cv.THRESH_BINARY)
preprocessed = time.perf_counter_ns()
contours, _ = cv.findContours(mask, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
detections = [cv.boundingRect(c) for c in contours if cv.contourArea(c) >= 400]
finished = time.perf_counter_ns()
rows.append({
"capture_ms": (acquired - started) / 1e6,
"preprocess_ms": (preprocessed - acquired) / 1e6,
"detect_ms": (finished - preprocessed) / 1e6,
"total_ms": (finished - started) / 1e6,
"detections": len(detections),
})
finally:
camera.release()
for field in ("capture_ms", "preprocess_ms", "detect_ms", "total_ms"):
samples = sorted(row[field] for row in rows[20:]) # discard warm-up
p95 = samples[int(0.95 * (len(samples) - 1))]
print(field, {"mean": round(statistics.mean(samples), 2), "p95": round(p95, 2)})
print("detection_count_range", min(r["detections"] for r in rows), max(r["detections"] for r in rows))Run the same recorded frame set for every comparison. For the edge path, record the four timings above plus device temperature, CPU load, power mode, frame size, OpenCV version, and dropped frames. For a controlled cloud path, add encode time, payload bytes, upload time, queue time, remote inference time, return time, and failure/retry status. Report mean and p95, not one favourable sample.
| Placement | Latency equation | Failure and privacy evidence |
|---|---|---|
| Device/edge | capture + preprocess + detect + local action | thermal throttling, memory/CPU contention, fallback, retained frames |
| Cloud | capture + encode + upload + queue + inference + response + action | disconnect, timeout, duplicate request, region/data purpose, deletion proof |
Do not send identifiable camera frames to a public endpoint for this exercise. Use consented or synthetic footage and an organisation-controlled test service. An edge result is not automatically faster or more private; a cloud result is not automatically more accurate. Compare the same input, model/detector, threshold, decision deadline, and failure policy, then record which boundary owns fallback.