【发布时间】:2018-08-20 10:54:17
【问题描述】:
我使用https://github.com/shimat/opencvsharp 包装器将opencv 与C# 一起使用。
实际上,我想获得我的计数的最大边界框。 倾斜无关紧要。我想要一个完美的直盒。
我找到轮廓后的实际结果是这样的:
这是我的代码:
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。 我有点困惑。
如果有人能给我一个提示,那就太好了。
谢谢
【问题讨论】:
-
通常你会传递你想要得到矩形的轮廓。以防万一您之后需要旋转的矩形,minAreaRect 将完成这项工作并且输入是相同的,轮廓(点向量,至少在 C++ 中)。
-
感谢您的评论。 BoundingBox 从类型 OpenCvSharp.InputArray 请求曲线。我的 Contour 来自 OpenCvSharp.Point[][] 类型。那么我应该如何将轮廓转换为 inputArray?
-
我没有用 C# OpenCV 做太多的工作,但是在 C++ 中 inputArray 有很多东西,比如一个 Mat 对象或一个点向量,它会隐式地将它转换为它需要的东西。 OpenCvSharp.Point[][] 是点向量的向量,或者是轮廓向量,只通过其中一个即可。 FindContours,也接收 inputArrays 或 inputOutputArrays
-
不幸的是它不会自动转换。
标签: c# opencv bounding-box opencvsharp