Getting started
This page will cover the basics of using the Midas package.
Basic Usage
To start, create a new 'Midas' instance:
var midas = new Midas();
Then you can pass in a Texture2D to EstimateDepth(Texture, bool)
// Estimate depth from an input texture
midas.EstimateDepth(inputImage);
RenderTexture predictedDepth = midas.Result;
// ... use predictedDepth as needed
Finally, when you're done you should call 'Dispose()' to properly free up native memory resources.
midas.Dispose();
You can reuse the same 'Midas' instance for multiple inferences. But if you only need it once, you might want to use the 'using' statement, so you don't need to worry about disposing it:
using (Midas midas = new Midas()) {
// your code
}
A simple example on how to use the library can also be found in the 'Basic Sample' that can be imported via the Package Manager.
Choosing a Model Type
The default model is midas_v21_small_256. You can specify the model to be used in the Midas constructor.
var midas = new Midas(ModelType.dpt_beit_large_384);
You can also change the model on an existing 'Midas' instance through the ModelType property. Changing the model automatically disposes of the existing model and initializes the new one.
midas.ModelType = ModelType.dpt_beit_large_384;
Note, that different models can have different output sizes, so changing the model might change the dimensions of the predicted depth map.
For more information on available models and when to use which, see the Models page.
Choosing a Backend
Use the Backend property to set the desired backend for model execution (GPUCompute by default). Changing the backend automatically disposes of the existing model and initializes the new one.
midas.Backend = BackendType.CPU;
Normalizing Depth
Set the NormalizeDepth property to true if you want to normalize the estimated depth values between 0 and 1. This is mainly useful for visualization.