3
在對原始圖像進行預處理後,我得到了該圖像。現在,我的問題是如何獲得矩形(最大)的四角的座標。對不起,如果這是如此noob問題。如何查找圖像中矩形的角點座標
更新:由於我跟OpenCV的開發,結束了使用this answer
在對原始圖像進行預處理後,我得到了該圖像。現在,我的問題是如何獲得矩形(最大)的四角的座標。對不起,如果這是如此noob問題。如何查找圖像中矩形的角點座標
更新:由於我跟OpenCV的開發,結束了使用this answer
一個簡單的方法是:
快速&髒數學解決方案要點:
(* 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]}
}]]
似乎像一個很好的解決方案謝謝! – 2012-04-12 17:03:06