Comments (3)
Hi @kipcole9, I see the problem here. It wasn't actually an off-by-one error. It is because of OpenCV's inconsistent way of storing the dims of a Mat.
A 4x3x3
mat could be initialised in two ways:
cv::Mat::Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0)
e.g.,Mat(3, [4, 3, 3], CV_8U, data)
cv::Mat::Mat(int rows, int cols, int type, void * data, size_t step = AUTO_STEP)
e.g.,Mat(4, 3, CV_8UC3, data)
Both of them will give the same result on the surface, however, mat.size.dims
from the first one will give [4,3,3]
while the second one will be [4,3]
, and the left dims info, the last 3
, will be stored in channels. (And as you may have guessed, the channel info of the first one is also 3
, causing the {3, 4, 3, 3}
shape)
So the fix in Evision's code is always using from_binary_by_shape
when converting a tensor to a mat, and pass the type as CV_8U/CV_32F/etc, so that we can check mat.type()
to know if we should include the channel number as the last dim in the shape later.
from evision.
Thank you very much @cocoa-xu. I find it difficult to get the mental model of OpenCV straight in my head and its been many many years since I did anything in C/C++ so I find the API docs difficult to decode. So I worry that I will bother you with stupid questions. I'm just happy this one wasn't too stupid. And I really appreciate the fix.
I have tensors/matrices round tripping between Image and OpenCV working well. But I haven't been able to get the image to be correctly resolved in eVision. Hopefully its mostly the issue you outlined above! I'll report back if/when I get that resolved. Then I'm going to add a simple API wrapping the QRCodeDetector module as a first step.
from evision.
Hi @kipcole9, please don't worry about that. I'm always happy to help! This is also a learning process for me. I guess we could say that OpenCV is a large project, and some of its "weird" designs may be due to historical reasons.
Please let me know if there is anything I can do in this project to help you! (I'll be looking at #76 this week. It's not hard to do but will introduce breaking changes)
from evision.
Related Issues (20)
- [macOS] `@behaviour :wx_object does not exist` HOT 2
- Add precompiled binaries for NIF version 2.17 (OTP 26)
- Failed to parse ONNX model on FaceRecognizerSF
- Face recognition always answers that the two photos are of the same person.
- Proposal: To prevent the entire Erlang VM from crashing when Evision's NIF aborts HOT 3
- Split this repo into `evision_beam` and `evision` HOT 9
- Using manylinux2010 for x86_64 linux? HOT 5
- Has Evision.Backend been removed? HOT 8
- Update model zoo URL for OpenCV 4.8.0
- Compilation error on Mac M1 HOT 5
- `Evision.imread` gives confusing `{:error, "empty matrix"}` error when file is not found HOT 2
- Zoo smartcell fails face detection because Kino.Input.image changed its return structure HOT 4
- Inheritance with Evision.Features2D HOT 3
- Fail to `im_write` after divided by Nx HOT 2
- can't compile evision for ios HOT 1
- Evision 0.1.34 causes runtime crash on Windows release HOT 2
- [erlang] Lower the required NIF version and simplify HOT 1
- Remove support for choosing OpenCV version to simplify Makefile[.win]
- Evision.VideoCapture.waitAny not loaded HOT 4
- Evision fails to compile in Livebook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from evision.