Giter Site home page Giter Site logo

Comments (3)

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

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.

kipcole9 avatar kipcole9 commented on May 31, 2024

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.

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

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)

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.