作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的目标是从图像中提取任何卡片..
描述:
我最初有以下图像...
将其绘制在 Canvas 上并应用精明的边缘检测并得到这个..
我希望得到的结果应该类似于:
要从图像中提取卡片,我需要找到卡片的 Angular 点。
或者
我在互联网上找到的另一种方法是:
遍历所有边并找到闭合边,然后
找到最大的闭合边缘并进行相应的裁剪。
但是在尝试构建任何逻辑来实现任何方法时我变得毫 headless 绪。
这样做是为了获得边缘检测,但无法进一步继续:
var img = new Image();
img.src = "bcard.png";
img.onload = function() {
var canv = document.getElementById("canv");
var ctx = canv.getContext("2d");
canv.height = img.height;
canv.width = img.width;
ctx.drawImage(img,0,0);
window.canny = CannyJS.canny(canv); //included a js script to do canny edge detection
canny.drawOn(canv);
}
最佳答案
首先,我从提供的图像中提取了红色 channel 。
红色 channel 图像:
接下来,我应用高斯模糊对其进行模糊处理。
图像模糊:
最后,我进行了边缘检测以获得以下结果。
最终边缘:
为了完美裁剪卡片,您必须仅找到一个外部轮廓。为此,您需要放大生成的图像
放大图像:
现在你必须找到轮廓。找到存在的外部轮廓。在这种情况下,您只会找到一个轮廓。围绕该轮廓绘制一个边界矩形。
使用边界矩形的坐标,裁剪图像:
(我有 python 生成的脚本,但我看到您已经用 javascript 编写了代码脚本)
关于javascript - Canvas : Find corners of a card in Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43654099/
我是一名优秀的程序员,十分优秀!