Opencv plus unity(资产存储插件)



我需要使用ConvexHull找到"ConvexityDefects",因为下面是我使用的代码https://assetstore.unity.com/packages/tools/integration/opencv-plus-unity-85928"统一插件

目前,我无法将点数组传递给"ConvexityDefects"函数,因为它接受第二个参数为integer[],并且无法将点转换为integer数组。

我得到的错误是"错误CS1503:参数2:无法从"OpenCvSharp.Point[]"转换为"System.Collections.Generic.IEnumerable">

Point[] hull;
Point[][] contours;
for (int i = 0; i < contours.Length; i++)
{

hull =  Cv2.ConvexHull(contours[i], false);
defects =  Cv2.ConvexityDefects(contours[i], hull);
Cv2.DrawContours(frame, new Point[][] { hull }, (int)largestContour, new OpenCvSharp.Scalar(0, 0, 255), 2);
}

点和int是不同的,所以点数组和int数组也是不同的。

OpenCV经常使用InputArray将大量数据传输到GPU。您需要使用其create方法和您选择的轮廓数组来创建输入数组。如果你想优化你的代码,你可能想为每个轮廓重用相同的数组,但这取决于你自己。

@Louis Garczynski下面是格式化的代码

Point[][] contours;
Point[]  hull;
for (int i = 0; i < contours.Length; i++)
{
hull = Cv2.ConvexHull(contours[i], false);
for (int k = 0; k < hull.Length; k++) 
{
Debug.Log("jihjib" + hull[k]); 
defects = Cv2.ConvexityDefects(contours[i], InputArray.Create(hull) ); 
}
}

最新更新