我正在搜索一个轮廓,并且至少找到了一个,正如我在调试器中看到的那样。当我尝试将序列转换为点数组时,会抛出 StackOverflowException(这就是我在这里的原因:-)。
我确定原因是缓冲区分配错误,我对我在 C、C++ 中找到的示例感到有些困惑,但在 C# 中却没有。OpenCvSharp 使用了我以前从未使用过的泛型。
平台:x86 上的 Windows 7,Sharpdevelop 4.2.2
下面是代码片段:
OpenCvSharp.CvMemStorage allContours = new OpenCvSharp.CvMemStorage();
OpenCvSharp.CvSeq<OpenCvSharp.CvPoint> contour = null;
OpenCvSharp.CvPoint[] border;
i = OpenCvSharp.Cv.FindContours (image[EDGE], allContours, out contour,
OpenCvSharp.CvContour.SizeOf, OpenCvSharp.ContourRetrieval.List,
OpenCvSharp.ContourChain.ApproxNone,
OpenCvSharp.Cv.Point(0,0));
if (i!=1)
{ Forms.MessageBox.Show( i.ToString() + " instead of 1 contours found", "Info");
return;
}
border = new OpenCvSharp.CvPoint [contour.Total];
OpenCvSharp.Cv.CvtSeqToArray<OpenCvSharp.CvPoint> (contour, out border);
这是程序崩溃的最后一行。