openFrameworks wrapper around the depth-anything.cpp library for monocular depth estimation.
README
ofxDepthAnything
ofxDepthAnything is an openFrameworks addon wrapper around mudler/depth-anything.cpp. The upstream project provides C++17/ggml GGUF inference and a flat C API (include/da_capi.h); this addon wraps that C API in an OF-friendly class.Layout
ofxDepthAnything/
src/ofxDepthAnything.h|cpp # OF wrapper
exampleApp/ # minimal OF example
libs/depth-anything.cpp/ # upstream submodule
libs/depthanything/lib/osx/ # generated merged static backend
scripts/build_depth_anything_lib.shBuild backend library
From an OF app that has this addon under
local_addons/ofxDepthAnything:./local_addons/ofxDepthAnything/scripts/build_depth_anything_lib.shThe script builds upstream with
DA_BUILD_CLI=OFF, DA_BUILD_TESTS=OFF, and merges libdepthanything.a + required ggml static libraries into:libs/depthanything/lib/osx/libofxDepthAnythingBackend.aCPU/Accelerate is the default path on macOS.
DA_GGML_METAL=ON can be tried, but the addon currently targets the CPU backend by default for predictable OF linking.Model files
GGUF model files are not included. Generate or download them with the upstream scripts/documentation and place one in your app data folder, e.g.:
bin/data/model.ggufDo not commit model weights into addon/app repositories. For dev apps, add
*.gguf or the app's bin/data/models/ directory to .gitignore.Useful model/runtime links:
- Pre-converted GGUF weights:
- Upstream C++/ggml runtime and converters:
- Official Depth Anything checkpoints:
For a quick DA3-BASE CPU smoke test, the upstream model card recommends the quantized
depth-anything-base-q4_k.gguf variant:mkdir -p bin/data/models
curl -L \
https://huggingface.co/mudler/depth-anything.cpp-gguf/resolve/main/depth-anything-base-q4_k.gguf \
-o bin/data/models/depth-anything-base-q4_k.ggufMinimal usage
#include "ofxDepthAnything.h"
ofxDepthAnything depth;
ofxDepthAnything::Result result;
void ofApp::setup(){
depth.setup("model.gguf"); // relative to bin/data
}
void ofApp::update(){
ofImage img;
img.load("input.jpg");
if(depth.infer(img, result)){
result.depthTexture.draw(0, 0);
}
}Example app
exampleApp/ is a small image-input example. It loads a GGUF model from exampleApp/bin/data/models/ or exampleApp/bin/data/model.gguf, generates a simple fallback image when no input image is present, runs inference, and draws the source image beside the normalized depth preview.Model files are ignored by git; place them under the example app's
bin/data/models/ directory locally.
ofxAddons