Giter Site home page Giter Site logo

Comments (7)

josevalim avatar josevalim commented on May 31, 2024 1

{:error, "empty matrix"} love it! Or {:error, "null matrix"}. :)

from evision.

cocoa-xu avatar cocoa-xu commented on May 31, 2024

Massive thanks to @josevalim for the Errorize demo code. Works like a charm!

from evision.

cocoa-xu avatar cocoa-xu commented on May 31, 2024

Notes, for some functions, OpenCV decides to print warnings (tested on OpenCV 4.5.5) instead of reporting error to us, i.e., the NIFs.

For example, for the imread function

iex(1)> mat = OpenCV.imread!("/path/to/non/exist/image.png")
[ WARN:0@0.008] global /Users/cocoa/Git/evision/3rd_party/opencv/opencv-4.5.5/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_('/path/to/non/exist/image.png'): can't open/read file: check file path/integrity
iex(2)> mat
nil

from evision.

josevalim avatar josevalim commented on May 31, 2024

@cocoa-xu can you configure it to return an error instead? 🤔

from evision.

cocoa-xu avatar cocoa-xu commented on May 31, 2024

This seems to be its intended behaviour, according to their docs

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 )

And since everything is immutable in Erlang/Elixir, I think returning a nil instead of returning a reference to an empty mat is probably fine?

from evision.

josevalim avatar josevalim commented on May 31, 2024

I see, makes sense. It would be nice if we could return {:error, "no result"} in this case but I understand it may be hard to automate this.

from evision.

cocoa-xu avatar cocoa-xu commented on May 31, 2024

In C++, OpenCV returns a valid cv::Mat object but everything is 0.

cv::Mat img = cv::imread("/dev/null");
std::cout << img.cols << "\n";
// output: 0

In opencv-python, the result is None

>>> import cv2
>>> mat = cv2.imread("/dev/null")
>>> mat is None
True

But sure, I can return an error tuple for this. However, I can only do this for general like when converting from cv::Mat to ERL_NIF_TERM.

Perhaps we could return {:error, "empty matrix"}?

from evision.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.