索引OutOfRange异常在opencv圈检测中未处理

时间:2014-09-17 07:01:45

标签: c# emgucv

我是计算机视觉的新手,有谁可以帮我解决错误?我在for循环条件中有错误。

private void timer1_Tick(object sender, EventArgs e) 
{ 
    double cannyThreshold = 180.0; 
    double circleAccumulatorThreshold = 120; 
    double cannyThresholdLinking = 160;
    Image<Bgr, Byte> imagez5 = capturez.QueryFrame().Resize(400, 400, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, true);
    pictureBox2.Image = imagez5.Bitmap;
    Image<Gray, Byte> gray = imagez5.Convert<Gray, Byte>().PyrDown().PyrUp();
    Image<Gray, byte> imagez7 = gray.Canny(cannyThreshold, cannyThresholdLinking);
    CircleF[] circlez = imagez7.HoughCircles(new Gray(cannyThreshold), new Gray(circleAccumulatorThreshold), 1, 60, 3, 300)[0];
    Image<Bgr, Byte> circleImage = imagez5.CopyBlank();

    for (int i =0; i<=circlez.Length; i++)
    {
        imagez7.Draw(circlez[i], new Gray(255), 3);
    }
    pictureBox1.Image = imagez7.Bitmap;
}

1 个答案:

答案 0 :(得分:0)

从循环中删除相等性

for (int i =0; i<circlez.Length; i++)
{
    imagez7.Draw(circlez[i], new Gray(255), 3);

}

确保

imagez7.HoughCircles(
    new Gray(cannyThreshold), new Gray(circleAccumulatorThreshold), 1, 60, 3, 300) 

不返回null