Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
am new one for computer vision , i have an error has index outofrange exception was unhandled in for loop condition. can anyone help me to solve it? here is my code........
C#
namespace circle_detection
{
    public partial class Form1 : Form
    {
        private Capture capturez;
        void InitializeInstanceFields()
        {
            capturez = new Capture();
        }
        public Form1()
        {
            InitializeInstanceFields();
            InitializeComponent();
        }

        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;

        }

    }
}
Posted
Updated 17-Sep-14 1:04am
v3
Comments
Bernhard Hiller 18-Sep-14 2:25am    
<pre lang="cs">CircleF[] circlez = imagez7.HoughCircles(new Gray(cannyThreshold), new Gray(circleAccumulatorThreshold), 1, 60, 3, 300)[0];</pre>How many CircleF does circlez contain now? Apart from the correct (!) solutions shown below, your problem likely resides here.

change for (int i =0; i<=circlez.Length; i++) into for (int i =0; i < circlez.Length; i++)
 
Share this answer
 
Comments
Pearl hepsi 17-Sep-14 3:24am    
yeah i have changed it... but it doesn't enter into the for loop..
as you are using Zero indexing you have to change that code

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

}



to be


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

}
 
Share this answer
 
Comments
Pearl hepsi 17-Sep-14 8:04am    
it doesn't enter into the loop condition.....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900