image-processing - 如何在图像中找到矩形的角坐标

标签 image-processing

我在对原始图像进行预处理后得到了这张图像。现在,我的问题是如何获得矩形(最大)的四个角的坐标。对不起,如果这是一个如此菜鸟的问题。

enter image description here

更新:由于我正在使用 OpenCV 进行开发,因此最终使用了 this answer

最佳答案

一个简单的方法是:

  1. 找到所有连接的组件
  2. 计算每个组件的凸包
  3. 选择凸包面积最大的组件
  4. 简化凸包多边形
  5. 简化多边形的顶点就是你要找的点

Quick&dirty Mathematica 解决方案:

(* find all connected components, calculate the convex hull for each component *)
convexHulls = ComponentMeasurements[ColorNegate[Binarize[src]], {"ConvexArea", "ConvexVertices"}];

(* pick the component where the convex hull has the largest area *)
vertices = SortBy[convexHulls[[All, 2]], First][[-1, 2]]

(* simplify the convex hull polygon, by iteratively removing the vertex with the lowest distance to the line through the vertex before and after it *)
distanceToNeighbors[vertices_] := MapThread[Abs[(#1 - #2).Cross[#1 - #3]/Norm[#1 - #3]]&, RotateLeft[vertices, #] & /@ {-1, 0, 1}]
removeVertexWithLowestDistance[vertices_] := With[{removeIndex = Ordering[distanceToNeighbors[vertices], 1]}, Drop[vertices, removeIndex]]
verticesSimplified = NestWhile[removeVertexWithLowestDistance, vertices, Min[distanceToNeighbors[#]] < 10&]

(* the vertices of the simplified polygon are the points you're looking for *)
Show[src, Graphics[
  {
   {EdgeForm[Red], Transparent, Polygon[verticesSimplified]},
   {Red, PointSize[Large], Point[verticesSimplified]}
   }]]

Result

关于image-processing - 如何在图像中找到矩形的角坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10127475/

相关文章:

python - 如何在python中计算二维图像的互信息

matlab - 计算区域内部或外部的邻域

html - 堆叠图像以实现无缝加载?

android - 使用 Processing 和 Opencv 进行 android 开发?

image - 如何在opencv中找到图像中形状的角点?

android - 使用 openCV 读取复选框

image-processing - 在序列matlab中提取字符

math - 如何标准化图像?

c++ - OpenCV绘制带有轴标签和坐标的直方图

python - 灰度图像Python实现