Example #1
0
        /// <summary>
        /// Class only constructor
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += DisplaySettingsChanged;


            x             = new List <HandTracking>(2);
            handCandiate  = new List <Contour <Point> >();
            detected_hand = new List <Contour <Point> >();

            hand_centers = new Dictionary <int, PointF>(2);

            grabber = new Emgu.CV.Capture();

            y = null;


            //height = (int)grabber.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT);
            //width = (int)grabber.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH);



            //detector = new AdaptiveSkinDetector(1, AdaptiveSkinDetector.MorphingMethod.NONE);


            //tempImage = new Image<Gray, Byte>(width, height);

            //current_image = new Image<Gray, byte>(width, height);

            //newImageG = new Image<Gray, byte>(width, height);

            sw = new System.Diagnostics.Stopwatch();

            Application.Idle += FrameGrabber;
        }
Example #2
0
        /// <summary>
        /// the main function in this class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FrameGrabber(object sender, EventArgs e)
        {
            sw.Start();
            newImage = grabber.QueryFrame();

            count++;
            if (newImage != null)
            {
                current_image = newImage.Convert <Gray, byte>();
                detector.Process(newImage, tempImage);

                tempImage = tempImage.ThresholdBinary(thresholdValue, MaxValue);
                tempImage = tempImage.Dilate(2);
                tempImage = tempImage.SmoothMedian(3);

                newImageG = current_image.ThresholdBinaryInv(new Gray(threshold), new Gray(255d));
                newImageG = newImageG.And(tempImage);
                newImageG = newImageG.Dilate(1);

                if (numberOfHands > 0)
                {
                    int tt = numberOfHands;
                    for (int i = 0; i < tt; i++)
                    {
                        if (x[i] != null)
                        {
                            try
                            {
                                x[i].StartTracking(elapsed_time);
                            }


                            catch (Exception ex)
                            {
                                Console.WriteLine("lost traking : number  of hands {0} & list x {1}", numberOfHands, x.Count);
                                int id = x[i].id;
                                hand_centers[id] = x[i].new_center_pt;
                                hand_centers.Remove(id);
                                x.RemoveAt(id);
                                --numberOfHands;
                            }
                        }
                    }
                }


                if (numberOfHands < hand_detected)
                {
                    detected_hand = HandDetection(newImageG);
                    if (detected_hand.Any())// any elements in the list
                    {
                        foreach (Contour <Point> h in detected_hand)
                        {
                            if (numberOfHands < hand_detected)
                            {
                                y = new HandTracking(current_image.Width, current_image.Height, hand_centers[numberOfHands]);

                                y.ExtractFeatures(h);
                                y.id = numberOfHands;
                                x.Add(y);

                                numberOfHands++;
                            }
                            else
                            {
                                Console.WriteLine("there is already 2 hands");
                            }
                        }
                        detected_hand.Clear();
                    }
                }

                sw.Stop();
                elapsed_time = sw.Elapsed.TotalMilliseconds;

                sw.Reset();
                imageBoxSkin.Image         = newImage;
                imageBoxFrameGrabber.Image = newImageG;
            }
        }
Example #3
0
        /// <summary>
        /// the main function in this class 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FrameGrabber(object sender, EventArgs e)
        {
            sw.Start();
            newImage = grabber.QueryFrame();

            count++;
            if (newImage != null)
            {
                current_image = newImage.Convert<Gray, byte>();
                detector.Process(newImage, tempImage);

                tempImage = tempImage.ThresholdBinary(thresholdValue, MaxValue);
                tempImage = tempImage.Dilate(2);
                tempImage = tempImage.SmoothMedian(3);

                newImageG = current_image.ThresholdBinaryInv(new Gray(threshold), new Gray(255d));
                newImageG = newImageG.And(tempImage);
                newImageG = newImageG.Dilate(1);

                if (numberOfHands > 0)
                {
                    int tt = numberOfHands;
                    for (int i = 0; i < tt; i++)
                    {
                        if (x[i] != null)
                        {
                            try
                            {
                                x[i].StartTracking(elapsed_time);
                            }

                     
                            catch(Exception ex)
                            {
                                Console.WriteLine("lost traking : number  of hands {0} & list x {1}", numberOfHands, x.Count);
                                int id = x[i].id;
                                hand_centers[id] = x[i].new_center_pt;
                                hand_centers.Remove(id);
                                x.RemoveAt(id);
                                --numberOfHands;

                            }
                        }

                    }

                }


                if (numberOfHands < hand_detected)
                {
                    detected_hand = HandDetection(newImageG);
                    if (detected_hand.Any())// any elements in the list
                    {
                        foreach (Contour<Point> h in detected_hand)
                        {
                            if (numberOfHands < hand_detected)
                            {

                                y = new HandTracking(current_image.Width, current_image.Height, hand_centers[numberOfHands]);

                                y.ExtractFeatures(h);
                                y.id = numberOfHands;
                                x.Add(y);

                                numberOfHands++;

                            }
                            else
                                Console.WriteLine("there is already 2 hands");
                        }
                        detected_hand.Clear();

                    }
                }

                sw.Stop();
                elapsed_time = sw.Elapsed.TotalMilliseconds;
           
                sw.Reset();
                imageBoxSkin.Image = newImage;
                imageBoxFrameGrabber.Image = newImageG;




            }
        }
Example #4
0
        /// <summary>
        /// Class only constructor
        /// </summary>
        public Form1()
        {
            

            InitializeComponent();
            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += DisplaySettingsChanged;
           

            x = new List<HandTracking>(2);
            handCandiate = new List<Contour<Point>>();
            detected_hand = new List<Contour<Point>>();

            hand_centers = new Dictionary<int, PointF>(2);

            grabber = new Emgu.CV.Capture();

            y = null;


            //height = (int)grabber.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT);
            //width = (int)grabber.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH);



            //detector = new AdaptiveSkinDetector(1, AdaptiveSkinDetector.MorphingMethod.NONE);


            //tempImage = new Image<Gray, Byte>(width, height);

            //current_image = new Image<Gray, byte>(width, height);

            //newImageG = new Image<Gray, byte>(width, height);

            sw = new System.Diagnostics.Stopwatch();

            Application.Idle += FrameGrabber;
        }