首页 > 解决方案 > 获取上面有硬币的 A4 纸的顶点坐标,用于进一步的投影变换和硬币检测

问题描述

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

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

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

手动选择:
在此处输入图像描述

结果:
在此处输入图像描述

标签: matlabimage-processingedge-detection

解决方案


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

我一直在寻找能够获得最大纸张对比度的色彩空间。
看起来 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个角点的特征。
  • 使用图像匹配技术将带有硬币的图像与没有硬币的图像匹配(马赫在 4 个角上)。

推荐阅读