Add depth estimation to your Blazor WebAssembly project with Transformers.js and Depth Anything V2 Small for Blazor WebAssembly. Includes fp16 and fp32 models.
Add the package to your Blazor WebAssembly project using NuGet:
dotnet add package SpawnDev.BlazorJS.TransformersJS.DepthAnythingV2
Example Program.cs
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using SpawnDev.BlazorJS;
using SpawnDev.BlazorJS.TransformersJS.DepthAnythingV2;
using SpawnDev.BlazorJS.TransformersJS.DepthAnythingV2.Demo;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
// Add SpawnDev.BlazorJSRuntime
builder.Services.AddBlazorJSRuntime();
// Add DepthAnythingService
builder.Services.AddDepthAnything();
// Initialize BlazorJSRuntime and start the application
await builder.Build().BlazorJSRunAsync();
Inject the DepthAnythingService
into your Blazor components or services to use the DepthAnything functionality.
[Inject]
DepthAnythingService DepthAnythingService { get; set; } = default!;
DepthEstimationPipeline pipeline = await DepthAnythingService.GetDepthEstimationPipeline();
...