我使用https://github.com/shimat/opencvsharp包装器在 C# 中使用 opencv。其实我想得到我countours的最大边界框。倾斜无关紧要。我想要一个完美的直盒。找到轮廓后我的实际结果如下所示:这是我的代码: Mat src = new Mat("index.jpg", ImreadModes.GrayScale); // Mat src = Cv2.ImRead("lenna.png", ImreadModes.GrayScale); Mat dst = new Mat(); Mat dst2 = new Mat(); Cv2.Canny(src, dst, hScrollBar1.Value, hScrollBar2.Value); //using (new Window("src image", src)) ; //using (new Window("dst image", dst)) ; // Find contours OpenCvSharp.Point[][] contours; //vector<vector<Point>> contours; HierarchyIndex[] hierarchyIndexes; //vector<Vec4i> hierarchy; Cv2.FindContours(dst, out contours, out hierarchyIndexes, RetrievalModes.External, ContourApproximationModes.ApproxSimple); using (new Window("dst image", dst)) ;我看到有一个函数 BoundingRect Cv2.BoundingRect()听起来对我来说是正确的。但是这个函数需要一个名为 curve 的 InputArray。我有点困惑。如果有人能给我一个提示,那就太好了。
2 回答
![?](http://img1.sycdn.imooc.com/54584dc4000118d302200220-100-100.jpg)
MYYA
TA贡献1868条经验 获得超4个赞
我自己找到了解决方案。
var biggestContourRect = Cv2.BoundingRect(contours[0]);
Cv2.Rectangle(dst,
new OpenCvSharp.Point(biggestContourRect.X, biggestContourRect.Y),
new OpenCvSharp.Point(biggestContourRect.X + biggestContourRect.Width, biggestContourRect.Y + biggestContourRect.Height),
new Scalar(255, 255, 255),2);
做这份工作:)
- 2 回答
- 0 关注
- 283 浏览
添加回答
举报
0/150
提交
取消