OpenCV keypoint copy does not work properly

asked 2017-06-08 04:23:24 -0600

Eugene L gravatar image

I am trying to copy keypoints from one vector to another keypoint vector. I want to do this so that I can split the keypoints to thread them. The below is done by using all the keypoints found. (Copying is the problem, not the splitting, and these are done in the main thread, no threading here)

The values of keypoint1 and keypoint2 after copying are the same, but when I put them through the extracting descriptor and matching algorithm, keypoint1 and keypoint2 produces different results.

keypoint1 produces accurate results, whereas keypoint2 produces a lot of wrong results. I am using ORB algorithm for detecting keypoints and descriptor extraction, and FlannBasedMatcher for matching. I have tried a few methods to copy the keypoints, I tried push_back() too, but its the same.

Method 1:

keypoint2.clear();
keypoint2.insert(keypoint2.begin(), keypoint1.begin(), keypoint1.end());

Method 2:

keypoint2.clear();
keypoint2.resize(keypoint1.size());
for (int i = 0; i < keypoint1.size(); ++i) {
    keypoint2[i].pt.x = keypoint1[i].pt.x;
    keypoint2[i].pt.y = keypoint1[i].pt.y;
    keypoint2[i].size = keypoint1[i].size;
    keypoint2[i].angle = keypoint1[i].angle;
    keypoint2[i].response = keypoint1[i].response;
    keypoint2[i].octave = keypoint1[i].octave;
    keypoint2[i].class_id = keypoint1[i].class_id;
}

After copying the keypoints

extractor->compute(GrayImage2, keypoint2, descriptor_img2);
matcher.match(descriptor_img1, descriptor_img2, matches);

I can tell that its wrong because after this step, they go through the same filtering step to get better results. The differences in amount of correct data from using keypoint1 and keypoint2 are very large.

I tried using pointers to split the keypoint too, but I couldn't get the pointer to point at part of the keypoint vector.

edit retag flag offensive close merge delete

Comments

Can you try to debug (copy only a vector with one element and print the different fields)?

Eduardo gravatar imageEduardo ( 2017-06-08 04:51:57 -0600 )edit
  • " I want to do this so that I can split the keypoints to thread them" <-- this is incomprehensable, can you explain ?

  • you're supposed to match 1 set of keypoints and descriptors from 1 image to another set from another image, so, again, why are you trying to match a set of keypoints to itself ? (does not make any sense)

  • are you aware, that compute() may remove bad keypoints from the array ?

berak gravatar imageberak ( 2017-06-08 23:11:18 -0600 )edit
1

@Eduardo I tried, they are completely the same.

@berakdescriptor_img1 is from the previous image, sorry for not stating. I didn't know compute() does that. For the threading, I tried to split up the image into sections using roi, and use detect() with std::thread, then recombine the keypoints found and split them equally and thread again for compute(). I thought that there was an increase in fps...after checking again, the speed is the same. After more searching on the internet, I think I can't parallelize detect() and compute() this way. If you know why, I hope you can share it with me. I'm going to try TBB.

Eugene L gravatar imageEugene L ( 2017-06-09 01:49:29 -0600 )edit

"I''m going to try TBB" -- that's actually the better way.

berak gravatar imageberak ( 2017-06-09 02:24:38 -0600 )edit