获取上面有硬币的A4sheet的顶点坐标,用于进一步的投影变换和硬币检测

Getting the coordinates of vertices of an A4 sheet with coins on it, for its further projective transformation and coin detection

我需要以一种可以在 A4 纸上找到硬币的方式转换我的倾斜图像。到目前为止,我已经通过使用 ginput 手动选择它们来获得纸张边缘的四个坐标。

targetImageData = imread('coin1.jpg');
imshow(targetImageData);
fprintf('Corner selection must be clockwise or anti-clockwise.\n');
[X,Y] = ginput(4);

有没有办法使这个过程自动化,比如说,应用一些边缘检测器,然后找到每个顶点的坐标,然后将它们作为转换所需的坐标传递?

手动选择:

结果:

您可以尝试在 HSV 颜色 space 的 S 颜色通道上使用 detectHarrisFeatures

我一直在寻找一种颜色 space 可以使纸张具有最大的对比度。
看起来 HSV 的饱和度颜色通道在纸张和背景之间形成了很好的对比。

图像按 0.25 倍调整图像大小,以去除噪点。

detectHarrisFeatures 找到纸的 4 个角,但可能不够稳健。
您可能需要使用一些逻辑查找更多功能,并找到 4 个正确的功能。

这是一个代码示例:

%Read input image
I = imread('im.png');

%Remove the margins, and replace them using padding (just because the image is a MATLAB figure)
I = padarray(I(11:end-10, 18:end-17, :), [10, 17], 'both', 'replicate');

HSV = rgb2hsv(I);

%H = HSV(:, :, 1);%figure;imshow(H);title('H');
S = HSV(:, :, 2);%figure;imshow(S);title('S');
%V = HSV(:, :, 3);%figure;imshow(V);title('V');

%Reduce image size by a factor of 0.25 in each axis
S = imresize(S, 0.25);

%S = imclose(S, ones(3)); %May be requiered

%Detect corners
corners = detectHarrisFeatures(S);

imshow(S); hold on;
plot(corners.selectStrongest(4));

结果:


您可以尝试的不同方法:

  • 拍一张没有硬币的照片。
  • 手动标记角点,并提取4个角点的特征。
  • 使用 image matching 技术将带有硬币的图像与没有硬币的图像匹配(在 4 个角上涂上马赫)。