Closed thbar closed 9 months ago
The best way is to check if the file exists before passing its path to Evision.imread
; and OpenCV does support relative file path and you can obtain current working path in Elixir via File.cwd
.
This is the default behaviour in OpenCV, returning an empty matrix if it cannot open the file. And as evision
is a binding between OpenCV and Erlang/Elixir, it would simply convert any cv::Mat
into a valid Erlang resource object or an error-tuple.
There is no special handling inside that conversion function because it's basically impossible to know why an OpenCV function decide to return an empty matrix. And that's why I would suggest to check if the file can be found in Elixir before calling Evision.imread
.
@cocoa-xu thanks for the input! It makes sense :smile:
I only realise now that the documentation at https://hexdocs.pm/evision/Evision.html#imread/2 states:
@anchor imread The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL )
So this is even documented.
I will read closer next round :smile: thank you!
Using an absolute path fixed it, but it took a good while before figuring things out.
I wonder if the error message could be made more user-friendly!