首页 > 解决方案 > 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 安装它。我无法弄清楚异常消息的含义是什么。

标签: c#emgucvkinect-v2

解决方案


我不知道我做错了什么,但我没有使用 CvInvoke.DrawContours(),而是使用 Image.DrawPolyline 来实现我的目标。

我用:
image.DrawPolyline(points, false, new Gray, thickness);


推荐阅读