algorithm - 是否有将多边形图像转换为方形图像的算法?

标签 algorithm image-processing

我编写了代码,可以用我的网络摄像头检测拼图区域,并想将其转换为拼图区域的方形图像以供进一步分析:

puzzle area

所以我想把它映射到一个 640x480 的区域。我的第一个想法是做类似这个伪代码的事情,但我认为可能有一个定义明确的算法,我一直没能找到...

  // x, y is from 0,0 to 639,479 in the target image
  let topX = B.x - A.x;
  let topY = B.y - A.y;
  let bottomX = C.x - D.x;
  let bottomY = C.y - D.y;

  pointAt(x, y) {
    let frac = x / 639; // how far along line from A to B or D to C

    // point along top AB line for x position
    let top = { x: A.x + (frac * topX), y: A.y + (frac * topY) };

    // point along bottom CD line for x position
    let bottom = { x: D.x + (frac * bottomX), y: D.y + (frac * bottomY) };

    // now get point along line from top to bottom
    let dx = bottom.x - top.x;
    let dy = bottom.y - top.y;
    frac = y / 479;
    return { x: top.x + (frac * dx), y: top.y + (frac * dy) };
  }

更新

到目前为止,我最终使用了我的伪代码,它工作得很好,速度足以满足我的需要,大约 20 毫秒就可以在我的笔记本电脑上转换图像:code (请原谅,做了很多实验)。叠加在原始图像上:

enter image description here

最佳答案

您可以在 OpenCV 中使用透视变换算法和 BoofCV .如果您打算为此编写自己的代码,我建议您阅读 this博客。

希望这对您有所帮助!

关于algorithm - 是否有将多边形图像转换为方形图像的算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56910424/

相关文章:

algorithm - 通过采用最大权重的路径遍历图形的复杂性

database - Django:避免数据库和 ORM 中的 ABA 场景

amazon-s3 - 上传图像 - 数据显示为 "���"�!1A"Qaq�2�B�#"并且图像为空白 - Next.js 应用程序上传到 DigitalOcean Spaces/AWS S3

php - 如何最好地在服务器外调整图像大小

algorithm - 如何用固定数量的圆圈部分覆盖给定的形状?

c++ - 大输入程序耗时过长

java - 给定约束的 Java 中最大大小的子集

c++ - 使用opencv4将鱼眼图像转换为等距柱状图像

python - 如何在灰度图像上应用渐变贴图

java - 在 r 或其他软件中查找草图图像的坐标(例如扫描为照片格式)