View Source Evision.Nx (Evision v0.1.12)

Conversion functions between Evision.Mat and Nx.tensor.

Link to this section Summary

Link to this section external

@spec to_mat(Nx.t()) :: Evision.Mat.t() | {:error, String.t()}

Converts a tensor from Nx.Tensor to Evision.Mat.

@spec to_mat(Nx.Tensor.t(), any()) :: Evision.Mat.t() | {:error, String.t()}
Link to this function

to_mat(binary, type, rows, cols, channels)

View Source
@spec to_mat_2d(Nx.t()) :: Evision.Mat.t() | {:error, String.t()}

Converts a tensor from Nx.Tensor to Evision.Mat.

If the tuple size of the shape is 3, the resulting Evision.Mat will be a c-channel 2D image, where c is the last number in the shape tuple.

If the tuple size of the shape is 2, the resulting Evision.Mat will be a 1-channel 2D image.

Otherwise, it's not possible to convert the tensor to a 2D image.

Link to this function

to_nx(mat, backend \\ Evision.Backend)

View Source
@spec to_nx(Evision.Mat.t(), module()) :: Nx.Tensor.t() | {:error, String.t()}

Transform an Evision.Mat reference to Nx.tensor.

The resulting tensor is in the shape {height, width, channels}.

example

Example

iex> mat = %Mat{} = Evision.imread("/path/to/exist/img.png")
iex> nx_tensor = Evision.Nx.to_nx(mat)
#Nx.Tensor<
  u8[1080][1920][3]
  [[ ... pixel data ... ]]
>