cocoa-xu / evision

Evision: An OpenCV-Erlang/Elixir binding
https://evision.app
Apache License 2.0
337 stars 22 forks source link

Wrap Evision.Mat as a struct? #76

Closed kipcole9 closed 2 years ago

kipcole9 commented 2 years ago

@cocoa-xu, thanks for this great library.

I'm just now working on zero-copy integration between Image and eVision (with all the hard work on my side done by @akash-akya).

I'm wondering if in the future you intend to wrap the NIF reference to an Evision.Mat into an Elixir struct? With the current type being a naked reference its not possible to pattern match on the type and I don't think there is a way to safely identify if the reference is an Evision.Mat?

cocoa-xu commented 2 years ago

Hi @kipcole9, thanks for bringing this up. I've been thinking about this issue for a while, and what I have in my mind now is that:

The simplest way is perhaps to make the result as a map with two entries (or as a 2-tuple)

This will be applied to all functions that return a Mat (or for any result that is a resource).

Then this resulting map/tuple goes to another elixir function and gets wrapped as its corresponding struct in Elixir.

kipcole9 commented 2 years ago

That sounds great @cocoa-xu - look forward to that whenever you get around to it. I know you're in active development and I expect breaking changes so no issue at all from me! You'd probably be fine using an atom for the class name given the number of classes is finite and relatively low cardinality. But its largely immaterial to me - its large about pattern matching for my use cases.

kipcole9 commented 2 years ago

BTW, your packaging pre-built binaries of OpenCV is masterful. I know I wouldn't have the confidence to tackle that myself and its really only when you did that I felt comfortable enough to start diving into the vast world of OpenCV.