在opencv循环检测中未处理Index OutOfRange异常

本文关键字:Index OutOfRange 异常 未处理 opencv 循环 检测 | 更新日期: 2023-09-27 18:22:05

我是计算机视觉的新手,有人能帮我解决这个错误吗?我在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;
}

在opencv循环检测中未处理Index OutOfRange异常

从循环中删除相等

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) 

不返回空