c# - Emgu.CV.Util.CvException: 'OpenCV: i < 0'
问题描述
我是 EmguCv 和 kinect v2 开发的新手。我正在尝试绘制在空白灰度图像上检测到的手的轮廓。而且我遇到了总是在代码行之后发生的异常:
CvInvoke.DrawContours(image, temp, -1, new MCvScalar(255, 0, 0), thickness);
这是我绘制轮廓的函数:
private void drawOnEachHand(Hand whichHand, Image<Gray, byte> image) {
int thickness = 2;
//Console.WriteLine("Check2 " + (whichHand == null));
if (whichHand != null)
{
VectorOfPoint temp = new VectorOfPoint(whichHand.ContourDepth.Count);
List<Point> arrTemp = new List<Point>();
for (int intCounter = 0; intCounter < whichHand.ContourDepth.Count; intCounter++)
{
int X = Convert.ToInt32(MathExtensions.ToPoint(whichHand.ContourDepth[intCounter]).X);
int Y = Convert.ToInt32(MathExtensions.ToPoint(whichHand.ContourDepth[intCounter]).Y);
arrTemp.Add(new Point(X, Y));
}
temp.Push(arrTemp.ToArray());
CvInvoke.DrawContours(image, temp, -1, new MCvScalar(255, 0, 0), thickness);
Console.WriteLine(image.Cols);
}
}
这是异常消息:
Exception thrown: 'Emgu.CV.Util.CvException' in Emgu.CV.World.dll<br>
An unhandled exception of type 'Emgu.CV.Util.CvException' occurred in Emgu.CV.World.dll<br>
OpenCV: i < 0
我正在使用 Visual Studio 2017、Emgu Cv 3.x 并使用 nugget 安装它。我无法弄清楚异常消息的含义是什么。
解决方案
我不知道我做错了什么,但我没有使用 CvInvoke.DrawContours(),而是使用 Image.DrawPolyline 来实现我的目标。
我用:
image.DrawPolyline(points, false, new Gray, thickness);
推荐阅读
- javascript - AJAX 错误:“内容类型中没有多部分边界参数”
- python-3.x - 如何在 OpenGL 中的标记上正确对齐立方体?
- node.js - TypeError:无法读取 null 的属性“通道”
- c - C:解释 gcc 输出和数字
- java - 无法在 Spring Webflux 2.1.0.RELEASE 中启动 Netty 服务器
- javascript - 如何从 JSON 对象计算特定属性的键数
- python - 在 Cygwin 中安装 Python 2.7.11
- python - 使用 Outlook Rest api 获取附件时“消息超出支持的最大大小”
- angularjs - 从指令调用控制器函数,参数未定义
- java - Activity has been stopped