Ask Your Question
1

How to copy std::vector<uint32_t> to pre-formatted Mat!?

asked Jul 16 '0

RedMarsBlueMoon gravatar image

Hi Everyone,

I'm working on combining two different pieces of code for a ORB Slam project and am trying to figure out how to re-format the 'descriptors'.

The FROM data is this,

std::vector<uint32_t> descriptors;

(I'm then adding to this)

The TO format is this,

_descriptors.create(descriptors.size(), 32, CV_8U);

How can I copy this for best performance?

Cheers Fred

Preview: (hide)

Comments

opencv does not support uint32_t for Mat

what exactly is inside your std::vector<uint32_t> ?

please explain in more detail, how you obtain that data

berak gravatar imageberak (Jul 16 '0)edit

I don't really follow what the first code does in its inner loop, its optimized code for Neon but should be compatible with ORB SLAM2 as that was the purpose of that project. Here is a description in the code + the function definition of the top level descriptor generation:

/// Compute ORB descriptions from keypoints. Set words to the number

/// of 32bit words the brief description should output, up to

/// 8 for a 256 bit descriptor. Descriptors are appended to the back of

/// descriptors.

void orbCompute(uint8_t img[][vstep], const std::vector<uint32_t> &points,
    std::vector<uint32_t> &descriptors) {
RedMarsBlueMoon gravatar imageRedMarsBlueMoon (Jul 16 '0)edit

I'm reading through this post that I found...
https://stackoverflow.com/questions/2...

RedMarsBlueMoon gravatar imageRedMarsBlueMoon (Jul 16 '0)edit

Sorry I missed the template part,

template <int vstep, int words>
void orbCompute(uint8_t img[][vstep], const std::vector<uint32_t> &points,
    std::vector<uint32_t> &descriptors)

This is an actual call in the demo code:

pislam::orbCompute<IMG_W, 8>(img, points, descriptors);
RedMarsBlueMoon gravatar imageRedMarsBlueMoon (Jul 16 '0)edit

1 answer

Sort by » oldest newest most voted
1

answered Jul 17 '0

berak gravatar image

updated Jul 17 '0

so, since there will be several ORB descriptors in your vector, and each of them has 8 uint32_t items, descriptors.size() / 8 should be the correct count.

you could try:

std::vector<uint32_t> descriptors = ....
assert(descriptors.size()%8==0); // must be multiple of 8!
int count = descriptors.size() / 8;

Mat ocv_desc(count, 32, CV_8U, (uchar*)descriptors.data());
Preview: (hide)

Comments

Thank you! I'm trying this now. So far no luck but it seems like this other function I'm using is not returning good data atm. I'm printing out the first 'descriptor' line from both the old and the new method and they are very different and only the old one works in context.
So I can't yet verify that this works but I'll be assuming it does until I can get some working result from the new function. Cheers!

RedMarsBlueMoon gravatar imageRedMarsBlueMoon (Jul 18 '0)edit

Question Tools

1 follower

Stats

Asked: Jul 16 '0

Seen: 722 times

Last updated: Jul 17 '20