matlab - 获取上面有硬币的 A4 纸的顶点坐标,用于进一步的投影变换和硬币检测
问题描述
我需要以一种可以在 A4 纸上找到硬币的方式转换我的倾斜图像。到目前为止,通过使用 ginput 手动选择它们,我已经获得了纸张边缘的四个坐标。
targetImageData = imread('coin1.jpg');
imshow(targetImageData);
fprintf('Corner selection must be clockwise or anti-clockwise.\n');
[X,Y] = ginput(4);
有没有办法自动化这个过程,比如说,应用一些边缘检测器,然后找到每个顶点的坐标,然后将它们作为转换所需的坐标传递?
解决方案
您可以尝试在 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 个角上)。
推荐阅读
- swift - withUnsafeBytes + 泛型类型行为
- csv - 如何使用 sed/vim 重新格式化文件?
- java - 使用依赖于其他方法的方法
- docker - Hyperledger Fabric BYFN - 找不到 docker-compose-base.yaml 中列出的目录
- node.js - 通过 Node.js 连接到 SQL Server
- visual-studio - 如何在 Visual Studio 2017 中修复此 NuGet 重启循环?
- docker - OCI8 未通过 Docker 出现在 PHP-FPM7.2 中
- php - Smarty PHP - 带有斜线双引号的变量的 If 语句
- python - UnicodeDecodeError 使用 PIL 模块
- mysql - 将长字符串作为字段保存的 sql 良好做法