Is there a way to extract the 4 corners points from all the points found with detectMinEigenFeatures?

3 views (last 30 days)
Arseni Ivanov
Arseni Ivanov on 6 May 2021
Edited: Arseni Ivanov on 7 May 2021
I am trying to make an Augmented Reality video feature using automatic detection after designating an area using 4 points with drawpolygon. I am getting a lot of matches, and I want to make a generic solution that can find the 4 corner points for the homography as marked in red below:
I have tried using max- and min-points, but this does not work for all camera angles as different directions might render the upper right corner as the minX instead of the upper left corner and so on.
edit; In particular, this breaks when seeing the checkerboard "straight on" as for example both minX goes to the same value as maxY and can occupy neighbouring detections.

Accepted Answer

Matt J
Matt J on 6 May 2021
If you have a binary map of the chequerboard, you can use imerode to separate the black squares and then pgonCorners
to identify the corners of each.
  3 Comments
Arseni Ivanov
Arseni Ivanov on 7 May 2021
You are right it works, I just assumed that the first column of the output was x and not y, so by flipping my output it now works properly. I will edit the message as it was my fault. If anyone is interested in the code from the image above to the result posted by Matt J:
se = strel('disk',45);
T = imerode(imcomplement(imerode(imbinarize(rgb2gray(I),0.19),se)),se);
T = bwareafilt(T,1);
points = pgonCorners(T,4);
points = flip(xA,2);
Note that this is very slow due to probably unnecessary operations but it works. Also it's very adapted to my scene so anyone stumbling upon this might have to change the threshold, single structuring element and order of operations on the image.

Sign in to comment.

More Answers (1)

Gatech AE
Gatech AE on 6 May 2021
I think an interesting way might be using the convex hull of your points. Running on the assumption that you have an Nx2 array of points,
x = Pts(:,1);
y = Pts(:,2);
k = convhull(x,y);
The variable k returns the indices of the points that form the perimeter sorted in counter-clockwise order. So for the corners,
corners = Pts(k,:);
  1 Comment
Arseni Ivanov
Arseni Ivanov on 6 May 2021
Thank you for the suggestion, I think that this can be a very good solution if you have a better pattern. In my case, I get k ranging from size of 4 to 14 indexes depending on the frame as a lot of the points lie exactly on the edge due to the checkered pattern. Perhaps I can play around with these points and treat nearby points as a mean of the group.and see if this gives an alright approximation.
edit; I might be wrong though, and perhaps the extra points are a result of the image being uneven, creating a bigger hull

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!