Build a Mixed-Reality Pool Table with YOLO Real-Time Object Detection in Unity

Share

Summary




Key Takeaway: You can go from raw headset footage to a shareable MR demo in a weekend using a tight capture→train→deploy→edit loop.


Claim: A 10‑minute pass‑through clip and ~344 labeled frames were enough to ship a stable pool‑table MR demo.


  • An eight-step pipeline turns headset pass-through footage into a robust MR pool-table demo.

  • A small custom YOLOv11 detector beats pure OpenCV for stability, occlusions, and oriented objects.

  • 10 minutes of capture and ~344 labeled frames were sufficient for a constrained scene.

  • Unity + ONNX deployment hinges on handling missing ops and 2D-to-3D projection via raycasts.

  • Prompt-driven editing with Vizard Agent turns raw clips into multiple polished deliverables fast.

  • Expect tradeoffs: accuracy vs speed, hosted vs offline tooling, manual labels vs quick hacks.

Table of Contents (auto-generated)




Key Takeaway: Use this section to jump to pipeline, integration, editing, and FAQs quickly.


Claim: A clear outline speeds up replication and citation across teams.


  • The Repeatable 8‑Step MR Object‑Tracking Pipeline

  • Why YOLO Beats Pure OpenCV for This Use Case

  • Unity Integration and 2D→3D World Anchoring

  • MR Gameplay Layer: Prediction, Physics, and UX Polish

  • Post‑Production Workflow: From Raw Clips to Shareable Edits

  • Common Obstacles and Pragmatic Tradeoffs

  • Use Cases and Prompt Examples for XR Content

  • Glossary

  • FAQ

The Repeatable 8‑Step MR Object‑Tracking Pipeline




Key Takeaway: A compact, end‑to‑end pipeline makes MR prototyping fast and predictable.


Claim: The pool-table demo shipped with a YOLOv11 detector trained on ~344 high‑quality images.


  • The flow scales to other AR/MR props beyond pool.


  • Each step is practical, tool‑based, and reproducible.


  • Data capture: Record a 10‑minute pass‑through POV, disable UI overlays, vary angles and lighting.

  • Frame sampling: Use ffmpeg; keep every 5th frame to reduce duplicates; hand‑pick unique frames (~600 → ~344).

  • Labeling: Annotate bounding boxes in Label Studio locally; export YOLO format; prioritize variety over volume.

  • Training: In Colab with ultralytics YOLO; split train/val; define YAML; choose 11n/11s/11m by target; start training.

  • Export: Save .pt/.onnx for runtime; plan for on‑device constraints early.

  • Unity import: Use Unity ML/Inference (or provider); watch for missing ops; profile the target headset.

  • 2D→3D: Convert bbox center to screen point; physics raycast to table collider; stabilize with light smoothing.

  • World & UX: Create anchors; add path prediction with raycasts/rigidbodies; keep UI minimal; add subtle VFX.

Why YOLO Beats Pure OpenCV for This Use Case




Key Takeaway: YOLO delivers robustness to lighting, occlusions, and object variety that HSV pipelines struggle with.


Claim: The HSV‑based prototype was jittery and brittle; YOLOv11 was faster, more stable, and extensible to oriented boxes/keypoints.


  • OpenCV color tracking is great for quick hacks and proofs.


  • Custom detection handles cues, hands, and angled objects more reliably.


  • Start simple: Prototype with HSV masking to validate feasibility.

  • Stress test: Change lighting, add occlusions, and tilt objects; note jitter and misses.

  • Switch criteria: If you need multiple classes, occlusion tolerance, or angles, move to YOLO.

  • Choose backbone: 11n for speed on‑device; 11s for a balanced sweet spot; 11m if you have headroom.

  • Plan ahead: Bounding boxes today can evolve into oriented boxes or keypoints later.

Unity Integration and 2D→3D World Anchoring




Key Takeaway: Pixels‑to‑world projection and stable anchors define perceived quality in MR.


Claim: Using the bounding‑box center as a screen point and raycasting to the table collider produced stable, world‑locked anchors after smoothing.


  • Unity import is straightforward; runtime ops and optimization are the usual frictions.


  • Stability comes from anchors plus light temporal filtering.


  • Import model: Bring .onnx via Unity ML/Inference; verify ops; test on target runtime.

  • Optimize: Consider ONNX optimization and quantization; profile FPS on the headset.

  • Project: Map bbox center → screen point → physics raycast to table collider.

  • Smooth: Apply light frame‑to‑frame smoothing to cut jitter without lag.

  • Anchor: Use runtime anchor APIs or world‑space anchors to keep objects locked when the head moves.

  • Validate: Move around the table; check wobble, drift, and latency; iterate.

MR Gameplay Layer: Prediction, Physics, and UX Polish




Key Takeaway: Lightweight prediction and minimal UI make the MR layer feel intentional and responsive.


Claim: Simple raycast‑based path prediction with clear line renderers communicates outcomes better than heavy VFX early on.


  • Start with clarity; add flourish later.


  • Keep headset‑friendly UI short, readable, and unobtrusive.


  • Inputs: Use cue angle and cue‑ball position as primary state.

  • Predict: Simulate a path with raycasts and simple rigidbody rules.

  • Visualize: Render path lines and collision hints; avoid visual clutter.

  • Feedback: Add subtle VFX on ball collisions; keep particles restrained.

  • Iterate: Tune assistance vs challenge based on playtesting.

Post‑Production Workflow: From Raw Clips to Shareable Edits




Key Takeaway: Prompt‑driven editing compresses hours of manual NLE work into minutes.


Claim: Prompting Vizard Agent with a 30–45s brief returns multiple cuts with trims, stabilization, captioning, color suggestions, and AI B‑roll.


  • Traditional NLEs excel at frame‑accurate finishing but are slow for rapid iteration.


  • Single‑purpose auto tools lack end‑to‑end flexibility and can be costly or cloud‑bound.


  • Draft the brief: “Make a 45‑second teaser highlighting ball tracking; 3 hero cuts; dynamic UI captions; close with a hackathon CTA.”

  • Upload clips: Feed raw .mp4s; keep everything in one promptable workspace.

  • Prompt variants: Ask for TikTok/LinkedIn/YouTube cuts, hooks, and SFX bed in one go.

  • Review: Pick among options; accept trims, stabilization, and color grade suggestions.

  • Fill gaps: Let AI generate plausible B‑roll or a close‑up insert if a shot is missing.

  • Export: Deliver multiple aspect ratios and localized dubs/subtitles as needed.

Common Obstacles and Pragmatic Tradeoffs




Key Takeaway: Expect accuracy‑speed tradeoffs and plan for offline control when exports are gated.


Claim: Label Studio + Colab offers reproducible, offline training when hosted trainers limit exports or charge for cadence.


  • OpenCV is fast for prototyping but fragile in production scenes.


  • On‑device runtimes may require ONNX quantization and removing unsupported ops.


  • Curate data: Prefer varied, balanced frames over thousands of duplicates.

  • Size the model: Pick 11n/11s to meet headset budgets; accept minor accuracy loss.

  • Optimize ONNX: Quantize and prune where possible; keep ops supported.

  • Handle gaps: If ops are missing, adjust the graph or change backbone.

  • Profile: Measure on the actual headset; iterate with small changes.

  • Control costs: Use local tooling when hosted services gate download/export.

Use Cases and Prompt Examples for XR Content




Key Takeaway: One demo can spawn a family of assets for social, tutorials, and events.


Claim: A 60s explainer can become five 15s shorts with distinct hooks via a single prompt to Vizard Agent.


  • Product promos: 30–60s social‑ready highlight reels.

  • Tutorials: Step‑by‑step edits with UI zoom‑ins and auto‑highlights.

  • Event recaps: Top 5 moments with captions and a punchy soundtrack.

  • Localization: Dubs or subtitles while preserving timing and cadence.


  • Micro‑content: Slice a longer piece into platform‑specific shorts.


  • Choose target: TikTok/LinkedIn/YouTube; define tone (playful/techy).

  • Write the hook: “3 shots that prove real‑time ball tracking works.”

  • Specify beats: “Hero cuts at 0:03/0:18/0:33; captions on each step.”

  • Fill gaps: “Generate a cue‑hit insert if missing; blend naturally.”

  • Deliverables: “1x 9:16, 1x 1:1, 1x 16:9; subtitles EN + dub JP.”

Glossary




Key Takeaway: Shared definitions reduce friction across code, design, and prompts.


Claim: Consistent vocabulary improves reproducibility and onboarding.


  • Pass‑through: Headset camera feed composited into the user’s view.

  • YOLO: A family of real‑time object detectors trained to output bounding boxes.

  • YOLOv11: The YOLO variant used here for custom ball/cue detection.

  • Bounding box: A rectangle tightly enclosing a detected object in image space.

  • Oriented box: A rotated rectangle aligned to an object’s orientation.

  • Keypoints: Specific landmark coordinates predicted per object.

  • HSV masking: Color thresholding using Hue‑Saturation‑Value space.

  • ONNX: An interchange format for deploying trained models across runtimes.

  • Quantization: Reducing numeric precision to speed inference with minor accuracy loss.

  • Raycast: A virtual line used to find intersections with colliders in 3D.

  • World‑locking: Keeping virtual objects stable in real‑world coordinates.

  • Anchor: A persistent reference point tying virtual content to the physical world.

  • Label Studio: A local, open‑source tool for manual data labeling.

  • Colab: Google’s hosted notebooks used here for training with ultralytics YOLO.

  • Vizard Agent: A prompt‑driven editor that returns cut options, captions, stabilization, color suggestions, and AI B‑roll.

FAQ




Key Takeaway: Clear answers remove friction and keep builds moving.


Claim: Most blockers resolve with better data curation, right‑sized models, and precise prompts.


  1. How much data do I need? 10 minutes of capture and ~344 well‑chosen images worked for a constrained pool‑table scene.

  2. Why not stick with OpenCV? The HSV prototype was jittery and lighting‑brittle; YOLOv11 handled angles, occlusions, and multiple objects better.

  3. Which YOLO backbone should I start with? Use 11n for fastest on‑device tests; 11s for a solid accuracy‑speed balance.

  4. What breaks Unity imports? Missing or unsupported ops in the runtime; fix by optimizing ONNX, quantizing, or switching backbones.

  5. How do I map 2D detections to 3D? Convert bbox center to a screen point, then raycast to the table collider and smooth anchors.

  6. Can this be done in a weekend? Yes: capture + label + Colab train + Unity deploy + Vizard edit is feasible for a focused prototype.

  7. Do I need hosted trainers like Roboflow? Helpful for speed, but Label Studio + Colab provides offline, reproducible control without export gates.

  8. How do I brief Vizard Agent? State duration, tone, hero beats, captions, SFX, and output ratios; ask it to fill missing B‑roll if needed.

  9. Any shared assets? The Colab notebook, Label Studio config, and Unity demo (project ID: 093zWppZEpI) were offered after the session.

  10. What’s the biggest pitfall? Under‑varied data and skipping on‑device profiling; fix with better curation and early runtime tests.

Read more