我正在使用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#(使用它是因为统一)有点陌生,但我假设有一些辅助方法可以从中借鉴。你知道吗
This gist到目前为止是我调整透视图的主要指南,for_point_warp
函数似乎提供了一个不错的指南。我只是不知道c的等价物。你知道吗
以下是我基于this tutorial实现的内容(尽管我确信我可以做一些更优雅的事情)。你知道吗
相关问题 更多 >
编程相关推荐