This project provides a web-based service for generating high-quality depth maps from images and videos using the state-of-the-art Depth Anything V2 (DAV2) model. The generated depth maps are used to create a compelling, interactive 3D parallax effect in a real-time web viewer built with Three.js.
SAVE_DEPTH_RG16). This offers 65,536 depth levels instead of the standard 256, significantly reducing banding artifacts.USE_TILED) to handle very high-resolution images without running out of GPU memory, by processing the image in overlapping chunks.The core of this project is Depth Anything V2 (DAV2), a powerful foundation model for monocular depth estimation. It excels at understanding scene geometry from a single 2D image and produces robust depth maps that generalize well to a wide variety of contexts.
Depth-Anything-V2-Large model is used for maximum detail.Depth-Anything-V2-Small model is used for frame-by-frame processing. This can be overridden to use the Large model for higher-quality video output at the cost of speed.Clone the Repository
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
Create and Activate a Virtual Environment (Recommended)
# For Windows
python -m venv venv
.\venv\Scripts\activate
# For macOS/Linux
python3 -m venv venv
source venv/bin/activate
Install Dependencies
The project's dependencies are listed in requirements.txt.
pip install -r requirements.txt
Note: For optimal performance with a GPU, consider installing the CUDA-enabled version of PyTorch by following the instructions on the official PyTorch website.
Hugging Face Authentication (Optional) To prevent potential rate-limiting when downloading models from the Hugging Face Hub, it is recommended to authenticate. Create an access token on huggingface.co and set it as an environment variable.
Create a .env file in the project root and add your token:
HUGGINGFACE_HUB_TOKEN="hf_YourTokenGoesHere"
The application will automatically load this variable.
The application can be configured using environment variables. You can set them in your shell or add them to the .env file.
| Variable | Default | Description |
|---|---|---|
DAV2_MAX_EDGE | 2048 | Maximum resolution edge for image processing. |
DAV2_VIDEO_MAX_EDGE | 1024 | Maximum resolution edge for video frame processing. |
USE_LARGE_FOR_VIDEO | 0 | Set to 1 to use the higher-quality Large model for videos (slower). |
DAV2_TILED | 0 | Set to 1 to enable tiled inference for very high-resolution images. |
DEPTH_PNG_RG16 | 1 | Set to 1 to save image depth maps in high-precision 16-bit format. |
VIDEO_CALIBRATE | 1 | Set to 1 to enable the anti-flicker calibration pre-pass for videos. |
VIDEO_CRF | 14 | The CRF (Constant Rate Factor) for ffmpeg video transcoding. Lower is higher quality. |
Once the setup is complete, run the web server using Uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000
main: Refers to the main.py file.app: Refers to the FastAPI instance named app inside main.py.The server will be available at http://127.0.0.1:8000.
http://127.0.0.1:8000 in your web browser.To get started quickly, this repository includes a demos/ directory containing sample images that you can use to test the application immediately.
This project provides a web-based service for generating high-quality depth maps from images and videos using the state-of-the-art Depth Anything V2 (DAV2) model. The generated depth maps are used to create a compelling, interactive 3D parallax effect in a real-time web viewer built with Three.js.
SAVE_DEPTH_RG16). This offers 65,536 depth levels instead of the standard 256, significantly reducing banding artifacts.USE_TILED) to handle very high-resolution images without running out of GPU memory, by processing the image in overlapping chunks.The core of this project is Depth Anything V2 (DAV2), a powerful foundation model for monocular depth estimation. It excels at understanding scene geometry from a single 2D image and produces robust depth maps that generalize well to a wide variety of contexts.
Depth-Anything-V2-Large model is used for maximum detail.Depth-Anything-V2-Small model is used for frame-by-frame processing. This can be overridden to use the Large model for higher-quality video output at the cost of speed.Clone the Repository
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
Create and Activate a Virtual Environment (Recommended)
# For Windows
python -m venv venv
.\venv\Scripts\activate
# For macOS/Linux
python3 -m venv venv
source venv/bin/activate
Install Dependencies
The project's dependencies are listed in requirements.txt.
pip install -r requirements.txt
Note: For optimal performance with a GPU, consider installing the CUDA-enabled version of PyTorch by following the instructions on the official PyTorch website.
Hugging Face Authentication (Optional) To prevent potential rate-limiting when downloading models from the Hugging Face Hub, it is recommended to authenticate. Create an access token on huggingface.co and set it as an environment variable.
Create a .env file in the project root and add your token:
HUGGINGFACE_HUB_TOKEN="hf_YourTokenGoesHere"
The application will automatically load this variable.
The application can be configured using environment variables. You can set them in your shell or add them to the .env file.
| Variable | Default | Description |
|---|---|---|
DAV2_MAX_EDGE | 2048 | Maximum resolution edge for image processing. |
DAV2_VIDEO_MAX_EDGE | 1024 | Maximum resolution edge for video frame processing. |
USE_LARGE_FOR_VIDEO | 0 | Set to 1 to use the higher-quality Large model for videos (slower). |
DAV2_TILED | 0 | Set to 1 to enable tiled inference for very high-resolution images. |
DEPTH_PNG_RG16 | 1 | Set to 1 to save image depth maps in high-precision 16-bit format. |
VIDEO_CALIBRATE | 1 | Set to 1 to enable the anti-flicker calibration pre-pass for videos. |
VIDEO_CRF | 14 | The CRF (Constant Rate Factor) for ffmpeg video transcoding. Lower is higher quality. |
Once the setup is complete, run the web server using Uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000
main: Refers to the main.py file.app: Refers to the FastAPI instance named app inside main.py.The server will be available at http://127.0.0.1:8000.
http://127.0.0.1:8000 in your web browser.To get started quickly, this repository includes a demos/ directory containing sample images that you can use to test the application immediately.