获取上面有硬币的A4纸的顶点坐标,以进行进一步的投影变换和硬币检测

问题描述 投票:0回答:1

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

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

是否有一种方法可以自动执行此过程,例如,应用一些边缘检测器,然后找到每个顶点的坐标,然后将它们作为转换所需的坐标传递?

手动选择:enter image description here

结果:enter image description here

matlab image-processing edge-detection
1个回答
0
投票

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

我一直在寻找能够获得纸张最大对比度的色彩空间。看起来HSV的饱和色通道在纸张和背景之间形成了很好的对比。

将图像调整大小为0.25倍,以去除噪声。

detectHarrisFeatures查找纸张的四个角,但可能不够鲁棒。您可能需要使用一些逻辑,找到更多功能,并找到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));

结果:enter image description here


您可以尝试的不同方法:

  • 不带硬币拍照。
  • 手动标记角,并提取四个角的特征。
  • 使用image matching技术将带有硬币的图像与没有硬币的图像进行匹配(马赫位于四个角)。
© www.soinside.com 2019 - 2024. All rights reserved.