我在 c# 中使用 opencv 来检测网络摄像头图像中的轮廓。如果轮廓有 4 个点,我想用它来使用 opencv 的getPerspective和warpPerspective. 职能。
这是获得这4点的代码:
Imgproc.approxPolyDP(perimMat,polyMat,0.005 * perim, true); //get contour of the current detected perimeter as polyMat
List<Point> polyMatList = polyMat.toList(); //convert it to a list of points
if (polyMatList.Count == 4){ //this contour has 4 points, we can use it for getting perspective
Debug.Log("p1x: " + polyMatList[0].x + "p1y: " + polyMatList[0].y); //example log: p1x: 203,p1y: 111
}
所以现在我有了这个点列表,我需要确保它是按左上角、右上角、右下角、左下角的顺序排列的,这样我就可以在getPerspective. 我该怎么做呢?
我看过其他语言的例子,但他们通常使用 numpy 之类的东西来进行排序。我对 C# 有点陌生(因为 Unity 使用它),但我假设有一些辅助方法我可以以某种方式借鉴。
到目前为止,这个要点一直是我调整视角的主要指南,该for_point_warp功能似乎提供了一个不错的指南。我只是不知道 c# 等价物。
青春有我
函数式编程
相关分类