Detect correct number of CORNER coordinates from a Polygon image in MATLAB

社会主义新天地 提交于 2019-12-11 12:50:17

问题


I have a number of polygon images like a hexagon, a pentagon, any quadrilateral etc.. i need to generalize the detection technique to detect the RIGHT number of Corner coordinates.. no extra coordinates should be generated.

for eg:- the code should detect only 4 for a quadrilateral, 3 for triangle, 5 for pentagon and so on..

I used HARRIS corner detection to detect right corners by specifying the number of corners value but i cant use the same code for an image with different number of edges.

Reason for using the same code is i am trying to bulk process image -> Detect corners and print them... i cant change the code for each image.

Sample Images:-

Octagon:

Pentagon:


回答1:


There is a function called corner that works very well given the right input parameters.

For instance setting an appropriate QualityLevel give accurate results:

clear
clc

A = imread('Octagon.jpg');
A_gray = rgb2gray(A);

figure;
Ca = corner(A_gray,'QualityLevel',.2)

The coordinates ar stored in Ca as a N x 2 matrix. Here N = 8.

imshow(A)

hold on

scatter(Ca(:,1),Ca(:,2),80,'filled','k')
hold off

B = imread('Pentagon.jpg');
B_gray = rgb2gray(B);

figure;
Cb = corner(B_gray,'QualityLevel',.2)

imshow(B)

hold on

scatter(Cb(:,1),Cb(:,2),80,'filled','k')
hold off

Outputs:

and

Yay!



来源:https://stackoverflow.com/questions/29123125/detect-correct-number-of-corner-coordinates-from-a-polygon-image-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!