public static List <Rectangle> getRectsByColorHsv(Image <Bgr, byte> original, Hsv lower, Hsv higher)
        {
            List <Rectangle> rectangles = new List <Rectangle>();
            var filtered = ColorFilterer.filterByHsv(original, lower, higher);



            VectorOfVectorOfPoint contoursDetected = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(filtered, contoursDetected, null, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

            VectorOfVectorOfPoint contoursArray = new VectorOfVectorOfPoint();
            int count = contoursDetected.Size;

            for (int i = 0; i < count; i++)
            {
                using (VectorOfPoint currContour = contoursDetected[i])
                {
                    if (currContour.Size > 50)
                    {
                        Rectangle rect = CvInvoke.BoundingRectangle(currContour);
                        contoursArray.Push(currContour);
                        rectangles.Add(rect);
                    }
                }
            }
            return(rectangles);
        }
        private void begin_Click(object sender, EventArgs e)
        {
            Capture     capture     = new Capture(0); //create a camera captue
            ImageViewer imageViewer = new ImageViewer();

            Application.Idle += new EventHandler(delegate(object sender1, EventArgs e2)
            {
                Image         = capture.QueryFrame().ToImage <Bgr, byte>();
                Bitmap bitmap = ColorFilterer.filterByHsv(Image, new Hsv((double)numericUpDown1.Value, (double)numericUpDown2.Value, (double)numericUpDown3.Value), new Hsv((double)numericUpDown4.Value, (double)numericUpDown5.Value, (double)numericUpDown6.Value)).ToBitmap();

                List <Rectangle> rectangles = ColorFilterer.getRectsByColorHsv(Image, new Hsv((double)numericUpDown1.Value, (double)numericUpDown2.Value, (double)numericUpDown3.Value), new Hsv((double)numericUpDown4.Value, (double)numericUpDown5.Value, (double)numericUpDown6.Value));
//                 Create a blank bitmap with the same dimensions
                for (int i = 0; i < rectangles.Count; i++)
                {
                    Image.Draw(rectangles[i], new Bgr(0, 53, 163), 10);
                    Console.WriteLine(rectangles[i]);
                }
                pictureBox1.Image = Image.ToBitmap();
            });
        }
 private void setValue()
 {
     orangeImage = ColorFilterer.filterByHsv(Image, new Hsv((double)numericUpDown1.Value, (double)numericUpDown2.Value, (double)numericUpDown3.Value), new Hsv((double)numericUpDown4.Value, (double)numericUpDown5.Value, (double)numericUpDown6.Value));
 }