Packages
evision
0.1.36
1.0.1-rc.0
1.0.0
1.0.0-rc.0
0.2.17
0.2.17-rc2
0.2.17-rc1
0.2.16
0.2.16-pre.2
0.2.16-pre
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.2-rc2
0.2.1
0.2.0
0.1.39
0.1.38
0.1.37
0.1.36
0.1.35
0.1.34
0.1.33
0.1.32
retired
0.1.31
0.1.30
0.1.29
0.1.28
0.1.27
0.1.26
0.1.26-rc3
0.1.26-rc2
0.1.26-rc1
0.1.26-rc0
0.1.25
0.1.24
0.1.23
0.1.22
0.1.21
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
OpenCV-Erlang/Elixir binding.
Current section
Files
Jump to
Current section
Files
lib/evision_structurise.ex
defmodule Evision.Internal.Structurise do
@moduledoc false
@spec to_struct(term()) :: {:ok, term()} | {:error, String.t()} | term()
def to_struct(any)
def to_struct({:ok, ret}), do: to_struct_ok(ret)
def to_struct(ret = %{:class => module_name}) when is_atom(module_name) do
if Code.ensure_loaded?(module_name) do
module_name.__to_struct__(ret)
else
ret
end
end
def to_struct(tuple) when is_tuple(tuple) do
Enum.map(Tuple.to_list(tuple), fn elem ->
to_struct(elem)
end)
|> List.to_tuple()
end
def to_struct(list) when is_list(list) do
Enum.map(list, fn elem ->
to_struct(elem)
end)
end
def to_struct(pass_through), do: pass_through
@spec to_struct_ok(term()) :: {:ok, term()}
def to_struct_ok(any)
def to_struct_ok(ret = %{:class => _module_name}) do
{:ok, to_struct(ret)}
end
def to_struct_ok(tuple) when is_tuple(tuple) do
{:ok, to_struct(tuple)}
end
def to_struct_ok(list) when is_list(list) do
{:ok, to_struct(list)}
end
def to_struct_ok(pass_through), do: {:ok, pass_through}
@spec from_struct(Nx.Tensor.t()) :: reference()
def from_struct(%Nx.Tensor{} = tensor) do
case Evision.Mat.from_nx(tensor) do
{:error, msg} ->
raise RuntimeError, msg
%Evision.Mat{ref: ref} ->
ref
end
end
@spec from_struct(%{ref: reference()}) :: reference()
def from_struct(%{ref: ref}) do
ref
end
@spec from_struct(tuple()) :: tuple()
def from_struct(tuple) when is_tuple(tuple) do
from_struct(Tuple.to_list(tuple))
|> List.to_tuple()
end
@spec from_struct(list()) :: list()
def from_struct(list) when is_list(list) do
if Keyword.keyword?(list) do
Enum.map(Keyword.keys(list), fn key ->
{key, from_struct(Keyword.fetch!(list, key))}
end)
|> Keyword.new()
else
Enum.map(list, fn elem ->
from_struct(elem)
end)
end
end
@spec from_struct(term()) :: term()
def from_struct(pass_through), do: pass_through
end