Example #1
0
        private void run()
        {
            Image<Bgr, Byte> image = new Image<Bgr, byte>("lena.jpg"); //Read the files as an 8-bit Bgr image
            Capture vid = new Capture("kw.avi");
            vid.FlipVertical = true;
            int x = 0;
            TimeSpan time = TimeSpan.Zero;
            MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
            using (VideoWriter vw = new VideoWriter("out3.avi", 15, 640, 480, true))
            {

                while (vid.Grab())
                {
                    //if (++x % 1 != 0) continue;

                    image = vid.RetrieveBgrFrame();

                    long detectionTime;
                    List<Rectangle> faces = new List<Rectangle>();
                    List<Rectangle> eyes = new List<Rectangle>();
                    DetectFace.Detect(image, "haarcascade_frontalface_default.xml", "supersmile.xml", faces, eyes, out detectionTime);
                    foreach (Rectangle face in faces)
                        image.Draw(face, new Bgr(Color.Red), 2);
                    foreach (Rectangle eye in eyes)
                        image.Draw(eye, new Bgr(Color.Blue), 2);
                    if (eyes.Count > 0) time = time.Add(new TimeSpan(0, 0, 0, 0, 66));
                    //display the image
                    image.Draw(String.Format("{0}:{1}", time.Seconds, time.Milliseconds), ref font, new Point(50, 50), new Bgr(0, 0, 255));
                    setimage(image);
                    vw.WriteFrame<Bgr, Byte>(image);
                }
            }
        }
        public FormManualTrain(Form1 frm1)
        {
            InitializeComponent();
            browseImage = new OpenFileDialog();

            _form1 = frm1;

            eigenRecog = new Classifier_Train();
            face = new HaarCascade("haarcascade_frontalface_default.xml");
            eyeWithGlass = new CascadeClassifier("haarcascade_eye_tree_eyeglasses.xml");
            mydb = new DBConn();
            minEye = new Size(10, 10);
            maxEye = new Size(225, 225);
            font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
            if (File.ReadAllText("setting.txt") != null)
            {
                folderPath = File.ReadAllText("setting.txt");
            }
            else
            {
                FolderBrowserDialog b = new FolderBrowserDialog();
                b.Description = "Please select your installation path";
                DialogResult r = b.ShowDialog();
                if (r == DialogResult.OK) // Test result.
                {
                    folderPath = b.SelectedPath;
                    Console.WriteLine(folderPath);
                    File.WriteAllText(@"setting.txt", folderPath);
                    MessageBox.Show("Path is at " + folderPath);
                }
            }
        }
    public virtual void ProcessImage(Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> image) {
      Emgu.CV.Image<Gray, byte> gray = image.Convert<Gray, byte>();
      gray._ThresholdBinary(new Gray(_threshold), new Gray(255.0));
      gray._Not();

      Parsley.Core.EllipseDetector ed = new Parsley.Core.EllipseDetector();
      ed.MinimumContourCount = _min_contour_count;

      List < Parsley.Core.DetectedEllipse > ellipses = 
        new List<Parsley.Core.DetectedEllipse>(ed.DetectEllipses(gray));

      List < Parsley.Core.DetectedEllipse > finals = 
        new List<Parsley.Core.DetectedEllipse>(
          ellipses.Where(e => { return e.Rating < _distance_threshold; })
        );

      finals.Sort(
        (a, b) => {
          double dista = a.Ellipse.MCvBox2D.center.X * a.Ellipse.MCvBox2D.center.X + a.Ellipse.MCvBox2D.center.Y * a.Ellipse.MCvBox2D.center.Y;
          double distb = b.Ellipse.MCvBox2D.center.X * b.Ellipse.MCvBox2D.center.X + b.Ellipse.MCvBox2D.center.Y * b.Ellipse.MCvBox2D.center.Y;
          return dista.CompareTo(distb);
        }
      );

      Bgr bgr = new Bgr(0, 255, 0);
      MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 0.8, 0.8);
      int count = 1;
      foreach (Parsley.Core.DetectedEllipse e in finals) {
        image.Draw(e.Ellipse, bgr, 2);
        image.Draw(count.ToString(), ref f, new System.Drawing.Point((int)e.Ellipse.MCvBox2D.center.X, (int)e.Ellipse.MCvBox2D.center.Y), bgr);
        count++;
      }
    }
Example #4
0
 public Image<Bgr, byte> GetBigPicture()
 {
     MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 1, 1);
     font.thickness = 2;
     Image<Bgr, byte> newImage = MostRecentImage.Image.Clone();
     foreach (Note note in _logic.CurrentNotes.Where(n => n.DetectedInFrames > 1))
     {
         Point playAreaOffset = new Point(218, 262);
         Point trackOffset;
         switch (note.TrackColor)
         {
             case NoteType.Red:
                 trackOffset = new Point(0, 0);
                 break;
             case NoteType.Yellow:
                 trackOffset = new Point(66, 0);
                 break;
             case NoteType.Blue:
                 trackOffset = new Point(134, 0);
                 break;
             case NoteType.Green:
                 trackOffset = new Point(176, 0);
                 break;
             default:
                 trackOffset = new Point(0, 0);
                 break;
         }
         Rectangle drawRectangle = new Rectangle(playAreaOffset.X + trackOffset.X + note.Rectangle.X,
                                                 playAreaOffset.Y + trackOffset.Y + note.Rectangle.Y,
                                                 note.Rectangle.Width, note.Rectangle.Height);
         Bgr color = new Bgr(0, 0, 0);
         switch (note.Color)
         {
             case NoteType.Red:
                 color = new Bgr(0, 0, 255);
                 break;
             case NoteType.Yellow:
                 color = new Bgr(0, 255, 255);
                 break;
             case NoteType.Blue:
                 color = new Bgr(255, 0, 0);
                 break;
             case NoteType.Green:
                 color = new Bgr(0, 255, 0);
                 break;
             case NoteType.Orange:
                 color = new Bgr(255, 255, 255);
                 break;
         }
         newImage.Draw(drawRectangle, color, 2);
         newImage.Draw(note.FramesUntilHit.ToString("##.##"), ref font,
                       new Point(drawRectangle.Left, drawRectangle.Bottom), new Bgr(0, 0, 0));
         //newImage.Draw("X" + note.PerFrameVelocityX + ";Y" + note.PerFrameVelocityY, ref font,
         //              new Point(drawRectangle.Left, drawRectangle.Bottom), new Bgr(0,0,0));
         //newImage.Draw(((int) note.DistanceToTarget).ToString(), ref font,
         //              new Point(drawRectangle.Left, drawRectangle.Bottom), new Bgr(128, 128, 128));
     }
     return newImage;
 }
Example #5
0
 public Form1()
 {
     InitializeComponent();
     Image<Bgr, Byte> f = new Image<Bgr, byte>(300,300);
     MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_DUPLEX, 2d, 2d);
     f.Draw(c.ToString(), ref font, new Point(32, 55), new Bgr(Color.Red));
     imageBox1.Image = f;
 }
Example #6
0
        private void image1_Initialized(object sender, EventArgs e)
        {
            Image<Bgr, Byte> image = new Image<Bgr, byte>(400, 100, new Bgr(255, 255, 255));
            MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 3.0, 3.0);
            image.Draw("Hello, world", ref f, new System.Drawing.Point(10, 50), new Bgr(255.0, 0.0, 0.0));

            image1.Source = ToBitmapSource(image);
        }
Example #7
0
        public Image<Bgr, Byte> GrabFrame()
        {
            Image<Bgr, Byte> img = new Image<Bgr, byte>(300, 300, new Bgr(255, 255, 255));

             MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 1.0, 1.0);
             String str = DateTime.Now.Ticks.ToString();
             img.Draw(str, ref f, new System.Drawing.Point(50, 150), new Bgr(0, 0, 0));
             return img;
        }
        public void DrawMeasurements( int x, int y, double dist, double pfc,
                                      MCvScalar color, Image<Bgr, Byte> src )
        {
            // Measurement text content, position, and font
            string text_size, text_posn, text_pfc, text_dist;
            Point point_size, point_posn, point_pfc, point_dist;
            MCvFont font = new MCvFont( Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5 );

            // Fill size string
            text_size = "Size (pix): ";
            text_size += Convert.ToString( CvInvoke.cvGetSize( src ).Width );
            text_size += ", ";
            text_size += Convert.ToString( CvInvoke.cvGetSize( src ).Height );

            // Start position, pfc, and distance strings
            text_posn = "Position (pix):  ";
            text_pfc  = "PFC (pix): ";
            text_dist = "Distance (cm): ";

            // If the laser point WAS found
            if ( ( x > 0 ) && ( y > 0 ) )
            {
                // Fill position string
                text_posn += Convert.ToString( x );
                text_posn += ", ";
                text_posn += Convert.ToString( y );

                // Fill pfc string
                text_pfc += Convert.ToString( pfc );

                // Fill distance string
                text_dist += String.Format( "{0:F1}", dist );
            }
            // If the laser pointer was NOT found
            else
            {
                // Fill measurement strings with NULL readings
                text_posn += "NULL, NULL";
                text_pfc += "NULL";
                text_dist += "NULL";
            }

            // Initialize text position
            point_size = new Point( 10, 400 );
            point_posn = new Point( 10, 420 );
            point_pfc  = new Point( 10, 440 );
            point_dist = new Point( 10, 460 );

            // Draw text on image
            CvInvoke.cvPutText( src, text_size, point_size, ref font, color );
            CvInvoke.cvPutText( src, text_posn, point_posn, ref font, color );
            CvInvoke.cvPutText( src, text_pfc,  point_pfc,  ref font, color );
            CvInvoke.cvPutText( src, text_dist, point_dist, ref font, color );
        }
Example #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            c = 0;
            //pictureBox1.Image = Image.FromFile("C:\\Users\\Tarang\\Desktop\\New folder\\image6.png");
            Image<Bgr, Byte> f = new Image<Bgr, byte>(300, 300);
            MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 2d, 2d);
            f.Draw(c.ToString(), ref font, new Point(32,55), new Bgr(Color.Red));
            imageBox1.Image = f;

            progressBar1.Value = 0;
        }
Example #10
0
 /// <summary>
 /// Function used to grab a frame 
 /// (Change this to suite your need, for example, capture an image from the camera and do face detection)
 /// </summary>
 /// <returns>Grabed image</returns>
 public Image<Bgr, Byte> GrapFrame()
 {
    //Create an image of 300x200 with white background
    Image<Bgr, Byte> img = new Image<Bgr, byte>(300, 200, new Bgr(255, 255, 255));
    MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_PLAIN, 1.0, 1.0);
    img.Draw(
        DateTime.Now.Ticks.ToString(), //draw the system clock tick 
        ref f, //using the specific font
        new Point(50, 150), //The bottom left posistion of the first character
        new Bgr(0, 0, 0)); //The color of the font
    return img;
 }
Example #11
0
        static void Main(string[] args)
        {
            String win1 = "Test Window"; //The name of the window
             CvInvoke.cvNamedWindow(win1); //Create the window using the specific name

             Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0)); //Create an image of 400x200 of Blue color
             MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0); //Create the font

             img.Draw("Hello, world", ref f, new System.Drawing.Point(10, 80), new Bgr(0, 255, 0)); //Draw "Hello, world." on the image using the specific font

             CvInvoke.cvShowImage(win1, img); //Show the image
             CvInvoke.cvWaitKey(0);  //Wait for the key pressing event
             CvInvoke.cvDestroyWindow(win1); //Destory the window
        }
Example #12
0
File: Draw.cs Project: qida/qcv
 /// <summary>
 /// Draw a list of ordered points using circles and numbering.
 /// </summary>
 /// <param name="image">Image to draw to</param>
 /// <param name="points">Points to draw</param>
 /// <param name="color">Color to use</param>
 public static void OrderedPointList(
     Image<Bgr, byte> image,
     IEnumerable<PointF> points,
     System.Drawing.Color color)
 {
     Bgr bgr = new Bgr(color);
       MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 0.8, 0.8);
       int count = 1;
       foreach (PointF point in points) {
     image.Draw(new CircleF(point, 4), bgr, 2);
     Point p = new Point((int)Math.Round(point.X), (int)Math.Round(point.Y));
     image.Draw(count.ToString(), ref f, new System.Drawing.Point(p.X + 5, p.Y - 5), bgr);
     count++;
       }
 }
Example #13
0
        public Form1()
        {
            InitializeComponent();
            recognizer = new LBPHFaceRecognizer(1, 8, 8, 9, 65);

            classifier = new CascadeClassifier(haarcascade);
            GPU_classifier = new GpuCascadeClassifier(haarcascade_cuda);

            font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5, 0.5);
            if (File.Exists(@"traningdata.xml"))
            {
                recognizer.Load(@"traningdata.xml");
            }
            else
            {

                foreach (var file in Directory.GetFiles(Application.StartupPath + @"\Traning Faces\"))
                {
                    try { temp = new Image<Gray, Byte>(file); }
                    catch { continue; }
                    temp._EqualizeHist();

                    var detectedFaces = classifier.DetectMultiScale(temp, 1.1, 15, new Size(24, 24), Size.Empty);
                    if (detectedFaces.Length == 0)
                    {
                        continue;
                    }

                    temp.ROI = detectedFaces[0];
                    temp = temp.Copy();
                    temp = temp.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                    imagesList.Add(temp);
                    imagesLabels.Add(Path.GetFileNameWithoutExtension(file));
                }
                for (int i = 0; i < imagesList.Count; i++)
                {
                    imagesLabels_indices.Add(i);
                }

                try { recognizer.Train(imagesList.ToArray(), imagesLabels_indices.ToArray()); }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    Environment.Exit(0);
                }
            }
        }
        public FormTrain(Form1 frm1)
        {
            InitializeComponent();
            _form1 = frm1;

            eigenRecog = new Classifier_Train();
            face = new HaarCascade("haarcascade_frontalface_default.xml");
            eyeWithGlass = new CascadeClassifier("haarcascade_eye_tree_eyeglasses.xml");
            mydb = new DBConn();
            minEye = new Size(10, 10);
            maxEye = new Size(225, 225);
            font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 0.5d, 0.5d);
            
            captureT = new Capture();
            Application.Idle += new EventHandler(runningCamera);
            
        }
Example #15
0
        public void Run()
        {
            CvInvoke.cvNamedWindow(this._windowName);

            //Create an image of 400x200 of Blue color
            using (Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0)))
            {
                //Create the font
                MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
                //Draw "Hello, world." on the image using the specific font
                img.Draw("Hello, world", ref f, new Point(10, 80), new Bgr(0, 255, 0));

                //Show the image
                CvInvoke.cvShowImage(_windowName, img.Ptr);
                //Wait for the key pressing event
                CvInvoke.cvWaitKey(0);
                //Destory the window
                CvInvoke.cvDestroyWindow(_windowName);
            }
        }
        private void btnDetect_Click(object sender, EventArgs e)
        {
            current = new Image<Bgr, byte>(filePath).Resize(300, 250, INTER.CV_INTER_CUBIC);
            Image<Gray, byte> grayScale = current.Convert<Gray, byte>();

                MCvAvgComp[][] detected = grayScale.DetectHaarCascade(face, scale, minNeighbors, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20));
                foreach (MCvAvgComp d in detected[0])
                {
                    current.Draw(d.rect, new Bgr(Color.LawnGreen), 2);
                    if (trainingImgs.Count > 0)
                    {
                        Image<Gray, byte> dFace = current.Copy(d.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                        MCvTermCriteria criteria = new MCvTermCriteria(trainingImgs.Count, epsilon);  //count, epsilon value
                        EigenObjectRecognizer recognize = new EigenObjectRecognizer(trainingImgs.ToArray(), trainingNames.ToArray(), 0, ref criteria);
                        MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_TRIPLEX, 1, 1);
                        string name = recognize.Recognize(dFace);
                        current.Draw(name, ref font, new Point(d.rect.X - 2, d.rect.Y - 20), new Bgr(Color.Red));
                    }
                }
            picWebCam.Image = current.ToBitmap();
        }
Example #17
0
        public void AddImagesToDatabase(int count)
        {
            ISession session = ImageDatabase.GetCurrentSession();
             ITransaction tx = session.BeginTransaction();

             MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0);
             long tick = DateTime.Now.Ticks;
             for (int i = 0; i < count; i++, tick++)
             {
            PersistentImage image = new PersistentImage(400, 200);
            image.SetRandUniform(new MCvScalar(), new MCvScalar(50, 50, 50));

            image.Draw(tick.ToString(), ref f, new Point(10, 100), new Bgr(Color.White));

            image.SerializationCompressionRatio = 9;
            session.Save(image);
             }

             tx.Commit();
             session.Close();
        }
Example #18
0
        public static void DrawContours(ContourNode node, Image<Bgr, Byte> canvas, System.Drawing.Color color)
        {
            Bgr _color = new Bgr(System.Drawing.Color.Red);

            foreach (ContourNode child in node.Children)
            {
                canvas.DrawPolyline(child.Contour.ToArray(), true, _color, 1);

                if (node.Shape != null)
                {
                    MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_PLAIN, 1, 1);
                    canvas.Draw(child.Shape + child.Color.ToString(),
                        ref font,
                        child.Contour[0],
                        new Bgr(System.Drawing.Color.Red)
                        );
                }

                DrawContours(child, canvas, color);
            }
        }
Example #19
0
        public static void DrawContours(ContourNode node, Image<Bgr, Byte> canvas)
        {
            #region color
            Random rnd = new Random(node.Contour.Ptr.ToInt32());
            Bgr _color = new Bgr(rnd.Next(255), rnd.Next(255), rnd.Next(255));
            #endregion

            foreach (ContourNode child in node.Children)
            {
                canvas.DrawPolyline(child.Contour.ToArray(), true, _color, 1);

                if (node.Shape != null)
                {
                    MCvFont font = new MCvFont(FONT.CV_FONT_HERSHEY_PLAIN, 1, 1);
                    canvas.Draw(child.Shape + child.Color.ToString(),
                        ref font,
                        child.Contour[0],
                        new Bgr(System.Drawing.Color.Red)
                        );
                }

                DrawContours(child, canvas);
            }
        }
Example #20
0
        public void TestAngle(/*LineSegment2D HorizontalMiddleLine*/)
        {
            Image<Bgr, Byte> imgBackground = new Image<Bgr, byte>("C:\\Users\\kevin\\Downloads\\gridBackground2.jpg");
            LineSegment2D line1 = new LineSegment2D(new Point(100, 0), new Point(200, 150));
            LineSegment2D line2 = new LineSegment2D(new Point(200, 150), new Point(150, 300));

            imgBackground.Draw(line1, new Bgr(Color.Red), 1);
            imgBackground.Draw(line2, new Bgr(Color.Blue), 1);

            Double angle = 0;
            angle = (line1.GetExteriorAngleDegree(line2));//* (180.0 / Math.PI) );

            MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.6, 0.6);
            imgBackground.Draw(angle.ToString(), ref f, new Point(50, 50), new Bgr(0, 0, 0));

            //ibTestAngle.Image = imgBackground;
        }
Example #21
0
        public void ProcesseFrameToFindCircles(Image<Bgr, Byte> pImage, int iterator)
        {
            #region test_200ppp

            //if (pImg != null)
            //{
            //    //Images where to draw of what is processed
            //    imgProcessedHoughCircle = pImg.Copy();
            //    imgProcessedHoughCircle2 = pImg.Copy();

            //    ////

            //    Image<Bgr, byte> blur = pImg.SmoothBlur(10, 10, true);
            //    //ibOriginal.Image = blur;
            //    Image<Bgr, byte> mediansmooth = pImg.SmoothMedian(3);
            //    //imageBox1.Image = mediansmooth;
            //    Image<Bgr, byte> bilat = pImg.SmoothBilatral(7, 255, 34);
            //    //imageBox2.Image = bilat;
            //    Image<Bgr, byte> gauss = pImg.SmoothGaussian(3, 3, 34.3, 45.3);
            //    //ibHoughCircles2.Image = gauss;

            //    ///

            //    //ranges
            //    imgProcessed = pImg.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
            //                                      new Bgr(B_MAX, G_MAX, R_MAX));
            //    ibOriginal.Image = imgProcessed;

            //    //SmoothGuassian process
            //    imgProcessed = imgProcessed.SmoothGaussian(11);
            //    ibCanny.Image = imgProcessed;

            //    /*
            //    //THRESHOLD_BINARY
            //    imgProcessed = imgProcessed.ThresholdBinary(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary

            //    ibCanny.Image = imgProcessed;

            //    //Image<Gray,float> imgSobel = imgProcessed.Sobel(1, 0,3);

            //    //ibHoughCircles2.Image = imgSobel;
            //    imgProcessed = imgProcessed.SmoothGaussian(9);
            //    ibHoughCircles.Image = imgProcessed;

            //    */
            //    // canny process
            //    imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));
            //    ibHoughCircles.Image = imgProcessedCanny;

            //    // finding all circles from image
            //    CircleF[] circles = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
            //                                                       new Gray(ACUMMULATOR_THRESHOLD),
            //                                                       2,
            //        //imgProcessed.Height / 4,
            //                                                       MIN_DIST,
            //        // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
            //                                                       MIN_RADIO,
            //                                                       MAX_RADIO)[0];

            //    //circles = null;

            //    if (circles != null)
            //    {
            //        txtTotalCircles.Text = circles.Length.ToString();

            //        for (int i = 0; i < circles.Length; i++)
            //        {
            //            CvInvoke.cvCircle(imgProcessedHoughCircle,
            //                              new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
            //                              2,
            //                              new MCvScalar(0, 255, 0),
            //                              -1,
            //                              LINE_TYPE.CV_AA,
            //                              0);
            //        }

            //        for (int i = 0; i < circles.Length; i++)
            //        {

            //            imgProcessedHoughCircle.Draw(circles[i],
            //                           new Bgr(Color.Red),
            //                           2);
            //            // mostrmo lo Id desordemandos del arreglo de circles
            //            MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
            //            imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
            //        }

            //        ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList());

            //        //ibHoughCircles.Image = imgProcessedHoughCircle;
            //        //ibHoughCircles2.Image = imgProcessedHoughCircle2;
            //        ibHoughCircles2.Image = imgProcessedHoughCircle;
            //        imageBox1.Image = imgProcessedHoughCircle2;

            //    }

            //    //ibOriginal.Image = pImg;
            //    //ibCanny.Image = imgProcessedCanny;

            //}

            #endregion

            switch (iterator)
            {
                #region test_200ppp Better_FOTOS 3 NO inverse  => first iteration     0

                case 0:
                    #region Official

                    if (pImage != null)
                    {

                        Image<Bgr, Byte> pImg = pImage.Copy();
                        //Image<Bgr, Byte> pImgN = pImage.Copy();
                        ////ibCanny.Image = pImgN;

                        ////History equalization and gamma corretion
                        //Image<Bgr, Byte> pImgEH = pImage.Copy();
                        //pImgEH._EqualizeHist();
                        //ibHoughCircles.Image = pImgEH;
                        //Image<Bgr, Byte> pImgG = pImgEH.Copy();
                        //pImgG._GammaCorrect(2.9d);
                        //ibHoughCircles2.Image = pImgG;

                        //ranges
                        imgProcessed = pImg.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
                                                          new Bgr(B_MAX, G_MAX, R_MAX));
                        //Image <Gray, Byte> gi = pImgG.Convert<Gray, Byte>();
                        //imgProcessed = gi.ThresholdBinary(new Gray(240),new Gray(255));
                        //ibCanny.Image = imgProcessed;

                        //Test using expensive filters...not good results
                        //Image<Gray, float> imgSobel = imgProcessed.Sobel(1, 0, 23);
                        //ibHoughCircles.Image = imgSobel;
                        //imgProcessed = imgProcessed.SmoothGaussian(3);
                        //ibHoughCircles2.Image = imgProcessed;

                        //THRESHOLD_BINARY
                        //imgProcessed = imgProcessed.ThresholdBinary(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary
                        //imgProcessed = imgProcessed.ThresholdBinaryInv(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary
                        #region MemStorage

                        contoursPositions.Clear();

                        #region Circles

                        using (MemStorage stor = new MemStorage())
                        {
                            //Find contours with no holes try CV_RETR_EXTERNAL to find holes
                            contours = imgProcessed.FindContours(
                             Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
                             Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL,
                             stor);

                            //contours = imgProcessed.FindContours(
                            //  Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE,
                            //  Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_CCOMP,
                            //  stor);
                            //markers.Clear();
                            for (int i = 0; contours != null; contours = contours.HNext)
                            {
                                i++;
                                //if ((contours.Area > Math.Pow(17, 2)) && (contours.Area < Math.Pow(45, 2)))
                                if ((contours.Area > Math.Pow(7, 2)) && (contours.Area < Math.Pow(45, 2)))
                                {

                                    MCvBox2D box = contours.GetMinAreaRect();
                                    CountorsPositions cp = new CountorsPositions(box.center.X, box.center.Y,(float)contours.Area);

                                    contoursPositions.Add(cp);

                                    //pImg.Draw(box, new Bgr(System.Drawing.Color.Red), 3);
                                    //blobCount++;

                                    CvInvoke.cvCircle(pImg,
                                                      new System.Drawing.Point((int)box.center.X, (int)box.center.Y),
                                                      2,
                                                      new MCvScalar(0, 255, 0),
                                                      -1,
                                                      LINE_TYPE.CV_AA,
                                                      0);

                                    PointF p = new PointF((int)box.center.X, (int)box.center.Y);

                                    CircleF c = new CircleF(p, (float)Math.Sqrt(contours.Area));
                                    pImg.Draw(c,
                                                 new Bgr(System.Drawing.Color.Orange),
                                                 3);
                                    //markers.Add(new Point((int)box.center.X, (int)box.center.Y));

                                }
                            }
                        }
                        #endregion
            //cleanList();
                        FillingAnswersToAbstractObject();

                        FillingAnswerstToFinalQuestionsList();

                        //if (markers.Count == 4)
                        //{
                        //    DrawLines(markers);
                        //}
                        ////this.outImg.Source = ImageHelpers.ToBitmapSource(openCVImg);
                        ////txtBlobCount.Text = blobCount.ToString();

                        #endregion

                        //ibHoughCircles.Image = imgProcessed;

                        //Image<Gray,float> imgSobel = imgProcessed.Sobel(1, 0,3);
                        //ibHoughCircles2.Image = imgSobel;
                        //imgProcessed = imgProcessed.SmoothGaussian(3);
                        //ibHoughCircles.Image = imgProcessed;

                        // canny process
                        //imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));
                        //ibHoughCircles2.Image = imgProcessed;

                        // finding all circles from image
                        CircleF[] circles;/* = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
                                                                           new Gray(ACUMMULATOR_THRESHOLD),
                                                                           2,
                            //imgProcessed.Height / 4,
                                                                           MIN_DIST,
                            // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
                                                                           MIN_RADIO,
                                                                           MAX_RADIO)[0];
                        */
                        circles = null;

                        if (circles != null)
                        {
                            txtTotalCircles.Text = circles.Length.ToString();

                            for (int i = 0; i < circles.Length; i++)
                            {
                                CvInvoke.cvCircle(imgProcessedHoughCircle,
                                                  new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
                                                  2,
                                                  new MCvScalar(0, 255, 0),
                                                  -1,
                                                  LINE_TYPE.CV_AA,
                                                  0);
                            }

                            for (int i = 0; i < circles.Length; i++)
                            {

                                imgProcessedHoughCircle.Draw(circles[i],
                                               new Bgr(Color.Red),
                                               2);
                                // mostrmo lo Id desordemandos del arreglo de circles
                                MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
                                imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
                            }

                            // call method to make second iteration
                            //ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList(),0);

                            //ibHoughCircles.Image = imgProcessedHoughCircle;
                            //ibHoughCircles2.Image = imgProcessedHoughCircle2;
                            //ibHoughCircles2.Image = imgProcessedHoughCircle;
                            imageBox1.Image = imgProcessedHoughCircle2;

                        }

                       //ibOriginal.Image = pImg;
                        //ibCanny.Image = imgProcessedCanny;

                    }

                    break;
                    #endregion

                #region test_200ppp_Edit

                //if (pImg != null)
                //{
                //    //Images where to draw of what is processed
                //    imgProcessedHoughCircle = pImg.Copy();
                //    imgProcessedHoughCircle2 = pImg.Copy();

                //    ////

                //    //Image<Bgr, byte> blur = pImg.SmoothBlur(10, 10, true);
                //    //ibOriginal.Image = blur;
                //    //Image<Bgr, byte> mediansmooth = pImg.SmoothMedian(3);
                //    //imageBox1.Image = mediansmooth;
                //    //Image<Bgr, byte> bilat = pImg.SmoothBilatral(7, 255, 34);
                //    //imageBox2.Image = bilat;
                //    //Image<Bgr, byte> gauss = pImg.SmoothGaussian(3, 3, 34.3, 45.3);
                //    //ibHoughCircles2.Image = gauss;

                //    ///

                //    //ranges
                //    imgProcessed = pImg.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
                //                                      new Bgr(B_MAX, G_MAX, R_MAX));
                //    ibOriginal.Image = imgProcessed;

                //    //SmoothGuassian process
                //    imgProcessed = imgProcessed.SmoothGaussian(31);
                //    ibCanny.Image = imgProcessed;

                //    //THRESHOLD_BINARY
                //    imgProcessed = imgProcessed.ThresholdBinary(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary

                //    ibHoughCircles.Image = imgProcessed;

                //    //Image<Gray,float> imgSobel = imgProcessed.Sobel(1, 0,3);

                //    //ibHoughCircles2.Image = imgSobel;
                //    //imgProcessed = imgProcessed.SmoothGaussian(9);

                //    // canny process
                //    imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));
                //    //ibHoughCircles.Image = imgProcessedCanny;

                //    // finding all circles from image
                //    CircleF[] circles = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
                //                                                       new Gray(ACUMMULATOR_THRESHOLD),
                //                                                       2,
                //        //imgProcessed.Height / 4,
                //                                                       MIN_DIST,
                //        // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
                //                                                       MIN_RADIO,
                //                                                       MAX_RADIO)[0];

                //    //circles = null;

                //    if (circles != null)
                //    {
                //        txtTotalCircles.Text = circles.Length.ToString();

                //        for (int i = 0; i < circles.Length; i++)
                //        {
                //            CvInvoke.cvCircle(imgProcessedHoughCircle,
                //                              new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
                //                              2,
                //                              new MCvScalar(0, 255, 0),
                //                              -1,
                //                              LINE_TYPE.CV_AA,
                //                              0);
                //        }

                //        for (int i = 0; i < circles.Length; i++)
                //        {

                //            imgProcessedHoughCircle.Draw(circles[i],
                //                           new Bgr(Color.Red),
                //                           2);
                //            // mostrmo lo Id desordemandos del arreglo de circles
                //            MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
                //            imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
                //        }

                //        ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList(),0);

                //        //ibHoughCircles.Image = imgProcessedHoughCircle;
                //        //ibHoughCircles2.Image = imgProcessedHoughCircle2;
                //        ibHoughCircles2.Image = imgProcessedHoughCircle;
                //        imageBox1.Image = imgProcessedHoughCircle2;

                //    }

                //    //ibOriginal.Image = pImg;
                //    //ibCanny.Image = imgProcessedCanny;

                //}
                //break;

                #endregion

                #endregion

                //#region second iteration   1
                //case 1:
                //    if (pImg != null)
                //    {
                //        InicializeColorConfigurationpPen_200ppp_No_Inverse_Second_Iteration();

                //        //Images where to draw of what is processed
                //        imgProcessedHoughCircle = pImg.Copy();
                //        imgProcessedHoughCircle2 = pImg.Copy();

                //        ////

                //        //Image<Bgr, byte> blur = pImg.SmoothBlur(10, 10, true);
                //        //ibOriginal.Image = blur;
                //        //Image<Bgr, byte> mediansmooth = pImg.SmoothMedian(13);
                //        //imageBox1.Image = mediansmooth;

                //        //imageBox1.Image = mediansmooth;
                //        //Image<Bgr, byte> bilat = pImg.SmoothBilatral(5, 255, 34);
                //        //imageBox2.Image = bilat;
                //        //Image<Bgr, byte> gauss = pImg.SmoothGaussian(7, 7, 34.3, 45.3);
                //        //imageBox1.Image = gauss;

                //        ///

                //        //ranges
                //        imgProcessed = pImg.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
                //                                          new Bgr(B_MAX, G_MAX, R_MAX));

                //        //ibOriginal.Image = imgProcessed;

                //        //SmoothGuassian process
                //        imgProcessed = imgProcessed.SmoothGaussian(31);
                //        ibCanny.Image = imgProcessed;

                //        //THRESHOLD_BINARY
                //        imgProcessed = imgProcessed.ThresholdBinary(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary

                //        ibHoughCircles.Image = imgProcessed;

                //        //Image<Gray,float> imgSobel = imgProcessed.Sobel(1, 0,3);

                //        //ibHoughCircles2.Image = imgSobel;
                //        imgProcessed = imgProcessed.SmoothGaussian(9);
                //        //ibHoughCircles.Image = imgProcessed;

                //        // canny process
                //        //imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));
                //        ibHoughCircles2.Image = imgProcessed;

                //        // finding all circles from image
                //        CircleF[] circles = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
                //                                                           new Gray(ACUMMULATOR_THRESHOLD),
                //                                                           2,
                //            //imgProcessed.Height / 4,
                //                                                           MIN_DIST,
                //            // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
                //                                                           MIN_RADIO,
                //                                                           MAX_RADIO)[0];

                //        //circles = null;

                //        if (circles != null)
                //        {
                //            txtTotalCircles.Text = circles.Length.ToString();

                //            for (int i = 0; i < circles.Length; i++)
                //            {
                //                CvInvoke.cvCircle(imgProcessedHoughCircle,
                //                                  new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
                //                                  2,
                //                                  new MCvScalar(0, 255, 0),
                //                                  -1,
                //                                  LINE_TYPE.CV_AA,
                //                                  0);
                //            }

                //            for (int i = 0; i < circles.Length; i++)
                //            {

                //                imgProcessedHoughCircle.Draw(circles[i],
                //                               new Bgr(Color.Red),
                //                               2);
                //                // mostrmo lo Id desordemandos del arreglo de circles
                //                MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
                //                imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
                //            }

                //            // call method to make second iteration
                //            ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList(), 1);

                //            //ibHoughCircles.Image = imgProcessedHoughCircle;
                //            //ibHoughCircles2.Image = imgProcessedHoughCircle2;
                //            //ibHoughCircles2.Image = imgProcessedHoughCircle;
                //            imageBox1.Image = imgProcessedHoughCircle2;

                //        }

                //        //ibOriginal.Image = pImg;
                //        //ibCanny.Image = imgProcessedCanny;

                //    }

                //    break;

                //#endregion

                //#region  third iteration    2
                //case 2:
                //    if (pImg != null)
                //    {
                //        InicializeColorConfigurationpPen_200ppp_No_Inverse_Third_Iteration();

                //        //Images where to draw of what is processed
                //        imgProcessedHoughCircle = pImg.Copy();
                //        imgProcessedHoughCircle2 = pImg.Copy();

                //        ////

                //        //Image<Bgr, byte> blur = pImg.SmoothBlur(10, 10, true);
                //        //ibOriginal.Image = blur;
                //        //Image<Bgr, byte> mediansmooth = pImg.SmoothMedian(13);
                //        //imageBox1.Image = mediansmooth;

                //        //imageBox1.Image = mediansmooth;
                //        //Image<Bgr, byte> bilat = pImg.SmoothBilatral(5, 255, 34);
                //        //imageBox2.Image = bilat;
                //        //Image<Bgr, byte> gauss = pImg.SmoothGaussian(7, 7, 34.3, 45.3);
                //        //imageBox1.Image = gauss;

                //        ///

                //        //ranges
                //        imgProcessed = pImg.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
                //                                          new Bgr(B_MAX, G_MAX, R_MAX));

                //        ibOriginal.Image = imgProcessed;

                //        //SmoothGuassian process
                //        imgProcessed = imgProcessed.SmoothGaussian(23);
                //        ibCanny.Image = imgProcessed;

                //        //THRESHOLD_BINARY
                //        imgProcessed = imgProcessed.ThresholdBinary(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary

                //        ibHoughCircles.Image = imgProcessed;

                //        //Image<Gray,float> imgSobel = imgProcessed.Sobel(1, 0,3);

                //        //ibHoughCircles2.Image = imgSobel;
                //        //imgProcessed = imgProcessed.SmoothGaussian(9);
                //        //ibHoughCircles.Image = imgProcessed;

                //        // canny process
                //        imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));
                //        ibHoughCircles2.Image = imgProcessedCanny;

                //        // finding all circles from image
                //        CircleF[] circles = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
                //                                                           new Gray(ACUMMULATOR_THRESHOLD),
                //                                                           2,
                //            //imgProcessed.Height / 4,
                //                                                           MIN_DIST,
                //            // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
                //                                                           MIN_RADIO,
                //                                                           MAX_RADIO)[0];

                //        //circles = null;

                //        if (circles != null)
                //        {
                //            txtTotalCircles.Text = circles.Length.ToString();

                //            for (int i = 0; i < circles.Length; i++)
                //            {
                //                CvInvoke.cvCircle(imgProcessedHoughCircle,
                //                                  new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
                //                                  2,
                //                                  new MCvScalar(0, 255, 0),
                //                                  -1,
                //                                  LINE_TYPE.CV_AA,
                //                                  0);
                //            }

                //            for (int i = 0; i < circles.Length; i++)
                //            {

                //                imgProcessedHoughCircle.Draw(circles[i],
                //                               new Bgr(Color.Red),
                //                               2);
                //                // mostrmo lo Id desordemandos del arreglo de circles
                //                MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
                //                imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
                //            }

                //            // call method to make second iteration
                //            ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList(), 2);

                //            //ibHoughCircles.Image = imgProcessedHoughCircle;
                //            //ibHoughCircles2.Image = imgProcessedHoughCircle2;
                //            //ibHoughCircles2.Image = imgProcessedHoughCircle;
                //            imageBox1.Image = imgProcessedHoughCircle2;

                //        }

                //        //ibOriginal.Image = pImg;
                //        //ibCanny.Image = imgProcessedCanny;

                //    }

                //    break;

                //#endregion

            }

            #region test_200ppp Better_ VALORES EN FOTOS 1 y 2

            //if (pImg != null)
            //{
            //    //Images where to draw of what is processed
            //    imgProcessedHoughCircle = pImg.Copy();
            //    imgProcessedHoughCircle2 = pImg.Copy();

            //    ////

            //    Image<Bgr, byte> blur = pImg.SmoothBlur(10, 10, true);
            //    ibOriginal.Image = blur;
            //    //Image<Bgr, byte> mediansmooth = pImg.SmoothMedian(13);
            //    //imageBox1.Image = mediansmooth;

            //    //imageBox1.Image = mediansmooth;
            //    //Image<Bgr, byte> bilat = pImg.SmoothBilatral(5, 255, 34);
            //    //imageBox2.Image = bilat;
            //    //Image<Bgr, byte> gauss = pImg.SmoothGaussian(7, 7, 34.3, 45.3);
            //    //imageBox1.Image = gauss;

            //    ///

            //    //ranges
            //    imgProcessed = blur.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
            //                                      new Bgr(B_MAX, G_MAX, R_MAX));

            //    ibCanny.Image = imgProcessed;

            //    //SmoothGuassian process
            //    imgProcessed = imgProcessed.SmoothGaussian(23);
            //    //ibCanny.Image = imgProcessed;

            //    //THRESHOLD_BINARY
            //    imgProcessed = imgProcessed.ThresholdBinaryInv(new Gray(THRESHOLD_BINARY_MIN), new Gray(THRESHOLD_BINARY_MAX)); //ThresholdBinary

            //    ibHoughCircles.Image = imgProcessed;

            //    //Image<Gray,float> imgSobel = imgProcessed.Sobel(1, 0,3);

            //    //ibHoughCircles2.Image = imgSobel;
            //    //imgProcessed = imgProcessed.SmoothGaussian(9);
            //    //ibHoughCircles.Image = imgProcessed;

            //    // canny process
            //    imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));
            //    ibHoughCircles2.Image = imgProcessedCanny;

            //    // finding all circles from image
            //    CircleF[] circles = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
            //                                                       new Gray(ACUMMULATOR_THRESHOLD),
            //                                                       2,
            //        //imgProcessed.Height / 4,
            //                                                       MIN_DIST,
            //        // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
            //                                                       MIN_RADIO,
            //                                                       MAX_RADIO)[0];

            //    //circles = null;

            //    if (circles != null)
            //    {
            //        txtTotalCircles.Text = circles.Length.ToString();

            //        for (int i = 0; i < circles.Length; i++)
            //        {
            //            CvInvoke.cvCircle(imgProcessedHoughCircle,
            //                              new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
            //                              2,
            //                              new MCvScalar(0, 255, 0),
            //                              -1,
            //                              LINE_TYPE.CV_AA,
            //                              0);
            //        }

            //        for (int i = 0; i < circles.Length; i++)
            //        {

            //            imgProcessedHoughCircle.Draw(circles[i],
            //                           new Bgr(Color.Red),
            //                           2);
            //            // mostrmo lo Id desordemandos del arreglo de circles
            //            MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
            //            imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
            //        }

            //        //ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList());

            //        //ibHoughCircles.Image = imgProcessedHoughCircle;
            //        //ibHoughCircles2.Image = imgProcessedHoughCircle2;
            //        imageBox1.Image = imgProcessedHoughCircle;
            //        imageBox2.Image = imgProcessedHoughCircle2;

            //    }

            //    //ibOriginal.Image = pImg;
            //    //ibCanny.Image = imgProcessedCanny;

            //}

            #endregion

            #region test_100ppp so so

            //if (pImg != null)
            //{
            //    //Images where to draw of what is processed
            //    imgProcessedHoughCircle = pImg.Copy();
            //    imgProcessedHoughCircle2 = pImg.Copy();

            //    //ranges
            //    imgProcessed = pImg.InRange(new Bgr(B_MIN, G_MIN, R_MIN),
            //                                            new Bgr(B_MAX, G_MAX, R_MAX));
            //    //SmoothGuassian process
            //    imgProcessed = imgProcessed.SmoothGaussian(9);

            //    // canny process
            //    imgProcessedCanny = imgProcessed.Canny(new Gray(THRESH), new Gray(THRESH_LINKING));

            //    // finding all circles from image
            //    CircleF[] circles = imgProcessedCanny.HoughCircles(new Gray(CANNY_THRESHOLD),
            //                                                       new Gray(ACUMMULATOR_THRESHOLD),
            //                                                       2,
            //        //imgProcessed.Height / 4,
            //                                                       MIN_DIST,
            //        // de 1 a 4 varia en la cantidad de pixeles a procesar, calidad de la imagen
            //        /* =>      */                                  MIN_RADIO,
            //                                                       MAX_RADIO)[0];

            //    //COMENTAR PARA HACER PRUEBAS DE CALIBRACION
            //    //circles = null;

            //    if (circles != null)
            //    {
            //        txtTotalCircles.Text = circles.Length.ToString();

            //        for (int i = 0; i < circles.Length; i++)
            //        {
            //            CvInvoke.cvCircle(imgProcessedHoughCircle,
            //                              new Point((int)circles[i].Center.X, (int)circles[i].Center.Y),
            //                              2,
            //                              new MCvScalar(0, 255, 0),
            //                              -1,
            //                              LINE_TYPE.CV_AA,
            //                              0);
            //        }

            //        for (int i = 0; i < circles.Length; i++)
            //        {

            //            imgProcessedHoughCircle.Draw(circles[i],
            //                           new Bgr(Color.Red),
            //                           2);
            //            // mostrmo lo Id desordemandos del arreglo de circles
            //            MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
            //            imgProcessedHoughCircle.Draw(i.ToString(), ref f, new Point((int)circles[i].Center.X + 10, (int)circles[i].Center.Y + 6), new Bgr(255, 0, 0));
            //        }

            //        ProcesseFrameToFindAnswers(imgProcessedHoughCircle2, circles.ToList());

            //        ibHoughCircles.Image = imgProcessedHoughCircle;
            //        ibHoughCircles2.Image = imgProcessedHoughCircle2;
            //    }

            //    ibOriginal.Image = pImg;
            //    ibCanny.Image = imgProcessedCanny;

            //}

            #endregion
        }
Example #22
0
        void r_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            c++;
            String a= e.Result.Text;
            String low1 = "haha";
            String low2 = "hahaha";
            String med1 = "hahahaha";
            String med2 = "hahahahaha";
            String high1 ="hahahahahaha";
            String high2 ="hahahahahahaha";
            String high3 ="hahahahahahahaha";
            String high4 ="hahahahahahahahaha";
                MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_DUPLEX,2d,2d);
                Image<Bgr, Byte> frame = new Image<Bgr, byte>(300, 300);
                FontFamily ff = new FontFamily("Courier New");
            Font f = new Font(ff, 50, FontStyle.Italic);
            frame.Draw(c.ToString(), ref font, new Point(32, 55), new Bgr(Color.Red));
              imageBox1.Image = frame;
            if (a.Equals(low1))
            {
                progressBar1.Value = 25;

            }
            if (a.Equals(low2))
             {
                progressBar1.Value = 25;

            }
            if (a.Equals(med1))
            {
                progressBar1.Value = 50;

            }
            if (a.Equals(med2))
            {
                progressBar1.Value = 50;

            }
            if ((a.Equals(high2))||(a.Equals(high1)))
            {
                progressBar1.Value = 80;
            }
            if ((a.Equals(high3)) || (a.Equals(high4)))
            {
                progressBar1.Value = 100;

            }
        }
Example #23
0
 private void showID(List<List<CircleF>> pListOrdered)
 {
     int id = 0;
     for (int i = 0; i < pListOrdered.Count; i++)
     {
         for (int j = 0; j < pListOrdered[i].Count; j++)
         {
             MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX, 0.9, 0.9);
             imgProcessedHoughCircle2.Draw((id + 1).ToString(), ref f, new Point((int)pListOrdered[i][j].Center.X + 10, (int)pListOrdered[i][j].Center.Y + 6), new Bgr(0, 0, 255));
             id++;
         }
     }
 }
Example #24
0
        private void addFPS(Image<Bgr, Byte> imageFrame, int x, int y)
        {
            frameCounter++;
            long seconds = DateTime.Now.Ticks / TimeSpan.TicksPerSecond;
            if (tickCouner != seconds)
            {
                FPS = frameCounter;
                tickCouner = seconds;
                frameCounter = 0;
            }

            MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 1, 1);
            imageFrame.Draw("FPS: " + FPS, ref font, new Point(x, y), new Bgr(Color.Green));
        }
Example #25
0
        private Hand ComputeHandInfo(Image<Bgr, byte> imageFrame)
        {
            int fingerNumber = 0;

            #region defects drawing
            if (defects == null)
            {
                return null;
            }

            //iterating all found defects
            for (int i = 0; i < defects.Total; i++)
            {
                PointF beginPoint, depthPoint, endPoint;
                try
                {
                    //defect has three points: begin, depth and end. They're computed here:
                    beginPoint = new PointF((float)defectsArr[i].StartPoint.X,
                                                    (float)defectsArr[i].StartPoint.Y);

                    depthPoint = new PointF((float)defectsArr[i].DepthPoint.X,
                                                    (float)defectsArr[i].DepthPoint.Y);

                    endPoint = new PointF((float)defectsArr[i].EndPoint.X,
                                                    (float)defectsArr[i].EndPoint.Y);
                }
                catch (Exception e)
                {
                    return null;
                }

                //nice looking lines connecting defects begin and end, with it's depth point:
                LineSegment2D startDepthLine = new LineSegment2D(defectsArr[i].StartPoint, defectsArr[i].DepthPoint);
                LineSegment2D depthEndLine = new LineSegment2D(defectsArr[i].DepthPoint, defectsArr[i].EndPoint);

                //circles at the begin,depth,end points (for computing purposes):
                CircleF beginCircle = new CircleF(beginPoint, 5f);
                CircleF depthCircle = new CircleF(depthPoint, 5f);
                CircleF endCircle = new CircleF(endPoint, 5f);

                //heuristic that decides if the defect in convect hull can caused by finger:
                if ((beginCircle.Center.Y < box.center.Y || depthCircle.Center.Y < box.center.Y) && (beginCircle.Center.Y < depthCircle.Center.Y) && (Math.Sqrt(Math.Pow(beginCircle.Center.X - depthCircle.Center.X, 2) + Math.Pow(beginCircle.Center.Y - depthCircle.Center.Y, 2)) > box.size.Height / 6.5))
                {
                    fingerNumber++;
                    imageFrame.Draw(startDepthLine, new Bgr(Color.Green), 2);
                    imageFrame.Draw(depthEndLine, new Bgr(Color.Magenta), 2);
                }

                //finally also we can draw the dots:
                imageFrame.Draw(beginCircle, new Bgr(Color.Red), 2);
                imageFrame.Draw(depthCircle, new Bgr(Color.Yellow), 5);
                imageFrame.Draw(endCircle, new Bgr(Color.DarkBlue), 4);
            }
            #endregion

            //Console.Write(fingerNumber + " | ");

            for (int j = 1; j < fingerCountArray.Length; j++)
            {
                fingerCountArray[j - 1] = fingerCountArray[j];
            }
            fingerCountArray[fingerCountArray.Length - 1] = fingerNumber;

            int[] tmpArr = new int[fingerCountArray.Length];
            for (int k = 0; k < tmpArr.Length; k++)
            {
                tmpArr[k] = fingerCountArray[k];
            }
            Array.Sort(tmpArr);

            fingerNumber = tmpArr[tmpArr.Length / 2];

            Console.WriteLine(string.Join(",", fingerCountArray));

            //drawing the number of visible fingers:
            MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_DUPLEX, 5d, 5d);
            imageFrame.Draw(fingerNumber.ToString(), ref font, new Point(50, 150), new Bgr(Color.White));

            return new Hand(fingerNumber, handRect.Height, imageFrame.Size.Height, handRect.Left, handRect.Top);
        }
Example #26
0
        private void ProcessFrame(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> frame = _capture.QueryFrame();

            if (insText != "")
            {
                MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 2.0, 2.0);

                frame.Draw(insText, ref font, new System.Drawing.Point(150, 450), new Bgr(255, 255, 255));

            }

            imgPreview.Image = frame;


        }
Example #27
0
        /// <summary> 
        /// Capture a Bgr image frame
        /// </summary>
        /// <returns> A Bgr image frame</returns>
        public virtual Image<Bgr, Byte> QueryFrame()
        {
            #if TEST_CAPTURE
            Image<Bgr, Byte> tmp = new Image<Bgr, Byte>(320, 240, new Bgr());
            MCvFont font = new MCvFont( CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 1.0, 1.0);
            tmp.Draw(System.DateTime.Now.Ticks.ToString(),
                ref font,
                new Point(10, 50),
                new Bgr(255.0, 255.0, 255.0));
            IntPtr img = tmp;
            #else
             IntPtr img = CvInvoke.cvQueryFrame(Ptr);
            #endif
             if (img == IntPtr.Zero)
            return null;

             MIplImage iplImage = (MIplImage)Marshal.PtrToStructure(img, typeof(MIplImage));

             Image<Bgr, Byte> res;
             if (iplImage.nChannels == 1)
             {  //if the image captured is Grayscale, convert it to BGR
            res = new Image<Bgr, Byte>(iplImage.width, iplImage.height);
            CvInvoke.cvCvtColor(img, res.Ptr, Emgu.CV.CvEnum.COLOR_CONVERSION.CV_GRAY2BGR);
             }
             else
             {
            res = new Image<Bgr, byte>(iplImage.width, iplImage.height, iplImage.widthStep, iplImage.imageData);
             }

             //inplace flip the image if necessary
             res._Flip(FlipType);

             return res;
        }
Example #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            //The name of the window
            String win1 = "Test Window";

            //Create the window using the specific name
            CvInvoke.cvNamedWindow(win1);

            //Create an image of 400x200 of Blue color
            using (Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0)))
            {
                //Create the font
                MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 1.0, 1.0);
                //Draw "Hello, world." on the image using the specific font
                img.Draw("Hello, world", ref f, new Point(10, 80), new Bgr(0, 255, 0));

                //Show the image
                CvInvoke.cvShowImage(win1, img.Ptr);
                //Wait for the key pressing event
                CvInvoke.cvWaitKey(0);
                //Destory the window
                CvInvoke.cvDestroyWindow(win1);
            }
        }
Example #29
0
        private void captureThread()
        {
            while (captureEnabled)
            {
                System.Threading.Thread.Sleep(20);
                Image<Bgr, Byte> frame = _capture.QueryFrame();

                if (insText != "")
                {
                    MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 2.0, 2.0);

                    frame.Draw(insText, ref font, new System.Drawing.Point(150, 450), new Bgr(255, 255, 255));

                }

                imgPreview.Image = frame;
            }
        }
        public int apply(string fileName, string output)
        {
            int counter = 0;

            Emgu.CV.Image<Bgr, Byte> imgS = new Emgu.CV.Image<Bgr, Byte>(fileName);

            Emgu.CV.Image<Gray, Byte> img = new Emgu.CV.Image<Gray, Byte>(fileName);

            //Emgu.CV.Image<Gray, Byte> imgGray = new Image<Gray, byte>(img.Width, img.Height);
            //CvInvoke.cvCvtColor(img, imgGray, COLOR_CONVERSION.BGR2GRAY);

            int thresh = 1;
            int max_thresh = 255;
            img = img.ThresholdBinary(new Gray(thresh), new Gray(max_thresh));

            img.Save(output.Replace(".", "_binary."));

            Contour<Point> contur = img.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_CCOMP);
            Emgu.CV.CvInvoke.cvDrawContours(imgS, contur, new MCvScalar(0, 0, 255), new MCvScalar(0, 0, 255), 1, 1, LINE_TYPE.EIGHT_CONNECTED, new Point(0, 0));

            contur = img.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_CCOMP);

            while (contur != null && contur.HNext != null)
            {
                if (counter == 0) { counter++; }

                contur = contur.HNext;
                counter++;
            }

            MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 0.8f, 0.8f);
            MCvScalar color = new MCvScalar(255, 255, 255);

            CvInvoke.cvPutText(imgS, "counter:" + counter, new Point(10, 20), ref font, color);

            imgS.Save(output);

            return counter;
        }