Ask Your Question

How to find a part of an image with the highest density of feature matches

asked 2017-12-14 07:39:19 -0500

Antarus gravatar image

updated 2017-12-14 07:46:33 -0500

As the title says, I want to find the position with the most feature matches from an image. What I'm looking for is the part of the image where the feature matches have the highest density. I know that the question can be easily misunderstood, therefore I added a photo describing better what I mean.

In the end I want to have a rectangle around the position with the most feature points within, where the max distance between 2 nearest points should be smaller than a threshold. In the image added I've manually drawn a rectangle around the area with the highest density of feature points.

I could implement a not so efficient way, but I would like to know if there's any OpenCV function that could be useful or if someone knows a smart way to do it. Thank you!

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-12-14 09:41:44 -0500

kbarni gravatar image

updated 2017-12-14 09:44:42 -0500

Here's what I would do:

  1. Create a new black image (CV_8U) img
  2. For each matched keypoint, draw a white pixel (where kp is the list of your matched keypoints)
  3. Run a box filter on img with the size of your rectangle (this will count the active pixel in the area)
  4. Detect the coordinates of the maximum of the image, and draw a rectangle around it.

Here's the code (untested, so might contain bugs):

    Mat img=zeros(original.size(),CV_8U);
    for(size_t i=0;i<kp.size();i++)<uchar>(kp[i].pt)=255;
    Mat filtimg;
    Point min_loc, max_loc;double min,max;
    minMaxLoc(filtimg, &min, &max, &min_loc, &max_loc);
edit flag offensive delete link more


I highly appreciate your answer and your help! I thought about that solution too, ending up with one a bit more time efficient. I used the std map class to map the inliers found in a 100 by 100 rectangle, that being a temporary solution. What I'm looking for is a solution where the rectangle size would not be a static value, but a dynamic one, depending on the position of the feature points from the top and the bottom of the feature density zone found. That being said, I still thank you for your patience and appreciate the help!

Antarus gravatar imageAntarus ( 2017-12-14 10:08:47 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-12-14 07:39:19 -0500

Seen: 171 times

Last updated: Dec 14 '17