Show / Hide Table of Contents

Class Midas

A class that allows to run Midas models to do monocular depth estimation.

Inheritance
object
Midas
Implements
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Doji.AI.Depth
Assembly: .dll
Syntax
public class Midas : IDisposable

Constructors

Midas(ModelType)

Initializes a new instance of MiDaS.

Declaration
public Midas(ModelType modelType = ModelType.midas_v21_small_256)
Parameters
Type Name Description
ModelType modelType

Midas(ModelAsset)

Declaration
public Midas(ModelAsset modelAsset)
Parameters
Type Name Description
ModelAsset modelAsset

Properties

AutoResize

Whether to automatically resize the texture passed to EstimateDepth(Texture) to the resolution that the specific neural network expects.

Declaration
public bool AutoResize { get; set; }
Property Value
Type Description
bool

Backend

Which BackendType to run the model with.

Declaration
public BackendType Backend { get; set; }
Property Value
Type Description
BackendType

ModelType

Which of the MiDaS models to run.

Declaration
public ModelType ModelType { get; set; }
Property Value
Type Description
ModelType

NormalizeDepth

Whether to normalize the estimated depth.

Declaration
public bool NormalizeDepth { get; set; }
Property Value
Type Description
bool
Remarks

MiDaS predicts depth values as inverse relative depth. (small values for far away objects, large values for near objects) If NormalizeDepth is enabled, these values are mapped to the (0, 1) range, which is mostly useful for visualization.

Result

A RenderTexture that contains the estimated depth.

Declaration
public RenderTexture Result { get; set; }
Property Value
Type Description
RenderTexture

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

EstimateDepth(Texture)

Run depth estimation on the given input texture.

Declaration
public void EstimateDepth(Texture input)
Parameters
Type Name Description
Texture input

EstimateDepth(Texture, object)

Declaration
public void EstimateDepth(Texture webCam, object onNewDepthPredicted)
Parameters
Type Name Description
Texture webCam
object onNewDepthPredicted

EstimateDepthAsync(Texture, EstimationFinished, int)

Runs depth estimation, but distributes the computation over several frames. This is done by running only the given number of layers of the neural network per frame.

Declaration
public void EstimateDepthAsync(Texture input, EstimationFinished callback, int numLayersPerFrame = 20)
Parameters
Type Name Description
Texture input
EstimationFinished callback
int numLayersPerFrame

GetMinMax()

Returns the minimum and maximum values of the last depth prediction.

Declaration
public (float min, float max) GetMinMax()
Returns
Type Description
(float min, float max)
Remarks

Keep in mind that the predictions are relative inverse depth values, i.e. min refers to the furthest away point and max to the closest point.

_EstimateDepth(Texture, EstimationFinished, int)

Runs depth estimation, but distributes the computation over several frames. This is done by running only the given number of layers of the neural network at a time. To call this method use MonoBehaviour.StartCoroutine.

Declaration
public IEnumerator _EstimateDepth(Texture input, EstimationFinished callback = null, int numLayersPerFrame = 20)
Parameters
Type Name Description
Texture input
EstimationFinished callback
int numLayersPerFrame
Returns
Type Description
IEnumerator

Implements

IDisposable
In this article
Back to top Generated by DocFX