View Source Evision.Nx (Evision v0.1.12)
Conversion functions between Evision.Mat
and Nx.tensor
.
Link to this section Summary
external
Converts a tensor from Nx.Tensor
to Evision.Mat
.
Converts a tensor from Nx.Tensor
to Evision.Mat
.
Transform an Evision.Mat
reference to Nx.tensor
.
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()}
@spec to_mat( binary(), Evision.Mat.mat_type(), non_neg_integer(), non_neg_integer(), non_neg_integer() ) :: Evision.Mat.maybe_mat_out()
@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.
@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 ... ]]
>