← Back

ofxDepthAnything

github.com/2bbb/ofxDepthAnything · @2bbb
OF 0.12 Computer Vision Depth Sensing Machine Learning

openFrameworks wrapper around the depth-anything.cpp library for monocular depth estimation.

1 0 Last commit 3mo ago Created 3mo ago

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.sh


Build backend library



From an OF app that has this addon under local_addons/ofxDepthAnything:

./local_addons/ofxDepthAnything/scripts/build_depth_anything_lib.sh


The 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.a


CPU/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.gguf


Do 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:

<https://huggingface.co/mudler/depth-anything.cpp-gguf> <https://github.com/mudler/depth-anything.cpp> <https://huggingface.co/depth-anything>

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.gguf


Minimal 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.

Get this addon

HTTPS
SSH