Ask Your Question
0

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

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

Antarus gravatar image

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

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
0

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

kbarni gravatar image

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

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++)
        img.at<uchar>(kp[i].pt)=255;
    Mat filtimg;
    boxFilter(img,filtimg,Size(100,100),Point(0,0),false);
    Point min_loc, max_loc;double min,max;
    minMaxLoc(filtimg, &min, &max, &min_loc, &max_loc);
    rectangle(original,Rect(max_loc.x,max_loc.y,100,100),Scalar(0,0,255);
edit flag offensive delete link more

Comments

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 -0600 )edit

Question Tools

2 followers

Stats

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

Seen: 2,273 times

Last updated: Dec 14 '17