Пример #1
0
        /// <summary>
        /// Calibrate skin mask and detect gesture
        /// </summary>
        /// <param name="img">Input Image</param>
        /// <param name="sampleArea1">Skin mask sample area 1</param>
        /// <param name="sampleArea2">Skin mask sample area 1</param>
        /// <returns>Image with debug information and detected gesture</returns>
        public static Mat GetGestureFromImage(Mat img, Rectangle sampleArea1, Rectangle sampleArea2)
        {
            SkinDetector  skinDetector  = new SkinDetector();
            FingerCounter fingerCounter = new FingerCounter();
            Gesture       gesture       = Gesture.None;

            if (img != null)
            {
                skinDetector.Calibrate(img, sampleArea1, sampleArea2);
                Mat skinMask = skinDetector.GetSkinMask(img);
                var newImage = fingerCounter.FindFingersCount(skinMask);
                img = newImage;
                switch (fingerCounter.NumberOfFingersRaised)
                {
                case 0:
                    gesture = Gesture.None;
                    break;

                case 1:
                    gesture = Gesture.Pointing;
                    break;

                case 2:
                    gesture = Gesture.Sign_2;
                    break;

                case 3:
                    gesture = Gesture.Sign_3;
                    break;

                case 4:
                    gesture = Gesture.Sign_4;
                    break;

                case 5:
                    gesture = Gesture.OpenHand;
                    break;

                default:
                    break;
                }
            }
            Console.WriteLine(gesture.ToString());
            CvInvoke.PutText(img, gesture.ToString(), new Point(50, 50), FontFace.HersheyComplex, 1, new Bgr(255, 255, 255).MCvScalar, 3);
            return(img);
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();

            ToolStripItem[] sampleImages = new ToolStripItem[] {
                /*new ToolStripMenuItem("Closed Hand", null, new EventHandler(LoadSample)), //Non-Functional samples
                 * new ToolStripMenuItem("1 Finger", null, new EventHandler(LoadSample)),
                 * new ToolStripMenuItem("2 Fingers", null, new EventHandler(LoadSample)),
                 * new ToolStripMenuItem("3 Fingers", null, new EventHandler(LoadSample)),*/
                new ToolStripMenuItem("4 Fingers", null, new EventHandler(LoadSample)),
                new ToolStripMenuItem("Open Hand", null, new EventHandler(LoadSample)),
            };
            loadSampleToolStripMenuItem.DropDownItems.AddRange(sampleImages);

            this.SkinDetector  = new SkinDetector();
            this.FingerCounter = new FingerCounter();
        }