Ask Your Question
1

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

asked 2020-07-16 12:22:53 -0600

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

edit retag flag offensive close merge delete

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 ( 2020-07-16 12:54:40 -0600 )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 ( 2020-07-16 13:53:11 -0600 )edit

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

RedMarsBlueMoon gravatar imageRedMarsBlueMoon ( 2020-07-16 16:31:13 -0600 )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 ( 2020-07-16 17:09:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-07-17 01:24:08 -0600

berak gravatar image

updated 2020-07-17 02:19:10 -0600

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());
edit flag offensive delete link more

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 ( 2020-07-18 16:51:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-07-16 12:21:21 -0600

Seen: 671 times

Last updated: Jul 17 '20