C++ computer-vision playground — Bazel 9 + Bzlmod + OpenCV 5.
ml/
├── app/ # binaries
│ └── ml # camera preview
├── camera/ # capture + display
└── libs/
└── opencv/ # system OpenCV → Bazel cc_library
| Tool | Notes |
|---|---|
| Bazel | 7+ (via Bazelisk) |
| OpenCV | 4/5 — brew install opencv |
| macOS | Camera permission for Terminal / IDE |
Optional override if OpenCV is non-standard:
export OPENCV_PREFIX="$(brew --prefix opencv)"# build
bazel build //app:ml
# run preview (default device 0)
bazel run //app:ml
# another device index
bazel run //app:ml -- 1Press q or Esc to quit.
If capture fails with “not authorized”, open
System Settings → Privacy & Security → Camera and allow your terminal.
| Target | Role |
|---|---|
//app:ml |
Entry binary |
//camera |
Thin OpenCV capture loop |
//libs/opencv |
Alias to @opencv (system install) |
@opencv |
Auto-discovered via pkg-config / Homebrew |
OpenCV is not built from source. A local repository rule finds headers and
dylibs and exposes them as a normal cc_library — fast, hermetic enough for
local work, and tracks OpenCV 5 from Homebrew.
- C++20 (
--cxxopt=-std=c++20in.bazelrc) clang-formatstyle in.clang-formatMODULE.bazelonly — noWORKSPACE