Exemplo n.º 1
0
        private void DoRecognition()
        {
            HandsRecognition gr = new HandsRecognition(this);

            gr.SimplePipeline();
            this.Invoke(new DoRecognitionCompleted(
                            delegate
            {
                Start.Enabled    = true;
                Stop.Enabled     = false;
                MainMenu.Enabled = true;
                if (closing)
                {
                    Close();
                }
            }
                            ));
        }
Exemplo n.º 2
0
        private void Panel_Paint(object sender, PaintEventArgs e)
        {
            lock (this)
            {
                if (bitmap == null || bitmap.Width == 0 || bitmap.Height == 0)
                {
                    return;
                }
                Bitmap bitmapNew = new Bitmap(bitmap);
                try
                {
                    if (Mirror.Checked)
                    {
                        bitmapNew.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    }

                    if (Scale2.Checked)
                    {
                        /* Keep the aspect ratio */
                        Rectangle rc      = (sender as PictureBox).ClientRectangle;
                        float     xscale  = (float)rc.Width / (float)bitmap.Width;
                        float     yscale  = (float)rc.Height / (float)bitmap.Height;
                        float     xyscale = (xscale < yscale) ? xscale : yscale;
                        int       width   = (int)(bitmap.Width * xyscale);
                        int       height  = (int)(bitmap.Height * xyscale);
                        rc.X      = (rc.Width - width) / 2;
                        rc.Y      = (rc.Height - height) / 2;
                        rc.Width  = width;
                        rc.Height = height;
                        e.Graphics.DrawImage(bitmapNew, rc);
                    }
                    else
                    {
                        e.Graphics.DrawImageUnscaled(bitmapNew, 0, 0);
                    }
                    HandsRecognition.SetBitmap(bitmapNew);
                }
                finally
                {
                    bitmapNew.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        public void Tick()
        {
            long now;

            QueryPerformanceCounter(out now);
            fps++;
            if (now - last > freq) // update every second
            {
                last = now;
                form.UpdateFPSStatus("FPS=" + fps);
                fps = 0;
            }
            if (now - clast > cfreq)
            {
                clast = now;
                HandsRecognition.Show();
                fps = 0;
            }
        }
Exemplo n.º 4
0
 private void DoRecognition()
 {
     HandsRecognition gr = new HandsRecognition(this);
     gr.SimplePipeline();
     this.Invoke(new DoRecognitionCompleted(
         delegate
         {
             Start.Enabled = true;
             Stop.Enabled = false;
             MainMenu.Enabled = true;
             if (closing) Close();
         }
     ));
 }
Exemplo n.º 5
0
        public void DisplayJoints(JointData[][] nodes, int numOfHands)
        {
            if (bitmap == null)
            {
                return;
            }
            if (nodes == null)
            {
                return;
            }

            bool needUpdate = false;
            long now;

            QueryPerformanceCounter(out now);
            if (now - last > freq)
            {
                last       = now;
                needUpdate = true;
            }

            if (Joints.Checked || Skeleton.Checked)
            {
                lock (this)
                {
                    int scaleFactor = 1;

                    Graphics g = Graphics.FromImage(bitmap);

                    using (Pen boneColor = new Pen(Color.DodgerBlue, 3.0f))
                    {
                        for (int i = 0; i < numOfHands; i++)
                        {
                            if (nodes[i][0] == null)
                            {
                                continue;
                            }
                            int baseX = (int)nodes[i][0].positionImage.x / scaleFactor;
                            int baseY = (int)nodes[i][0].positionImage.y / scaleFactor;

                            int wristX = (int)nodes[i][0].positionImage.x / scaleFactor;
                            int wristY = (int)nodes[i][0].positionImage.y / scaleFactor;

                            if (Skeleton.Checked)
                            {
                                for (int j = 1; j < 22; j++)
                                {
                                    if (nodes[i][j] == null)
                                    {
                                        continue;
                                    }
                                    int x = (int)nodes[i][j].positionImage.x / scaleFactor;
                                    int y = (int)nodes[i][j].positionImage.y / scaleFactor;

                                    if (nodes[i][j].confidence <= 0)
                                    {
                                        continue;
                                    }

                                    if (j == 2 || j == 6 || j == 10 || j == 14 || j == 18)
                                    {
                                        baseX = wristX;
                                        baseY = wristY;
                                    }

                                    g.DrawLine(boneColor, new Point(baseX, baseY), new Point(x, y));
                                    baseX = x;
                                    baseY = y;
                                }
                            }

                            if (Joints.Checked)
                            {
                                using (
                                    Pen red = new Pen(Color.Red, 3.0f),
                                    black = new Pen(Color.Black, 3.0f),
                                    green = new Pen(Color.Green, 3.0f),
                                    blue = new Pen(Color.Blue, 3.0f),
                                    cyan = new Pen(Color.Cyan, 3.0f),
                                    yellow = new Pen(Color.Yellow, 3.0f),
                                    orange = new Pen(Color.Orange, 3.0f))
                                {
                                    Pen currnetPen = black;

                                    for (int j = 0; j < HandData.NUMBER_OF_JOINTS; j++)
                                    {
                                        float sz = 4;
                                        if (Labelmap.Checked)
                                        {
                                            sz = 2;
                                        }

                                        int   x    = (int)nodes[i][j].positionImage.x / scaleFactor;
                                        int   y    = (int)nodes[i][j].positionImage.y / scaleFactor;
                                        float ledX = LED.WIDTH - ((float)LED.WIDTH / bitmap.Width) * x;
                                        float ledY = ((float)LED.HEIGHT / bitmap.Height) * y;

                                        if (nodes[i][j].confidence <= 0)
                                        {
                                            continue;
                                        }

                                        //Wrist
                                        if (j == 0)
                                        {
                                            currnetPen = black;
                                        }

                                        //Center
                                        if (j == 1)
                                        {
                                            currnetPen = red;
                                            sz        += 4;
                                        }

                                        //Thumb
                                        FixedSizedQueue <Point> target = null;
                                        if (j == 2 || j == 3 || j == 4 || j == 5)
                                        {
                                            currnetPen = green;
                                            if (j == 5)
                                            {
                                                target = this.fingerBuffer[i][0];
                                                target.Enqueue(new Point(x, y));
                                            }
                                        }
                                        //Index Finger
                                        if (j == 6 || j == 7 || j == 8 || j == 9)
                                        {
                                            currnetPen = blue;
                                            if (j == 9)
                                            {
                                                target = this.fingerBuffer[i][1];
                                                target.Enqueue(new Point(x, y));
                                            }
                                        }
                                        //Finger
                                        if (j == 10 || j == 11 || j == 12 || j == 13)
                                        {
                                            currnetPen = yellow;
                                            if (j == 13)
                                            {
                                                target = this.fingerBuffer[i][2];
                                                target.Enqueue(new Point(x, y));
                                            }
                                        }
                                        //Ring Finger
                                        if (j == 14 || j == 15 || j == 16 || j == 17)
                                        {
                                            currnetPen = cyan;
                                            if (j == 17)
                                            {
                                                target = this.fingerBuffer[i][3];
                                                target.Enqueue(new Point(x, y));
                                            }
                                        }
                                        //Pinkey
                                        if (j == 18 || j == 19 || j == 20 || j == 21)
                                        {
                                            currnetPen = orange;
                                            if (j == 21)
                                            {
                                                target = this.fingerBuffer[i][4];
                                                target.Enqueue(new Point(x, y));
                                            }
                                        }


                                        if (j == 5 || j == 9 || j == 13 || j == 17 || j == 21)
                                        {
                                            if (target != null && isHandDistanceGreaterThan(target, 50))
                                            {
                                                if (j == 9)
                                                {
                                                    HandsRecognition.addObjectOnWave(new LED3DRipple(ledX, ledY, RGB.randamBG(), LED.Direction.Front, 3));
                                                }
                                            }

                                            if (j == 9)
                                            {
                                                //Console.WriteLine("positionWorld:" + nodes[i][j].positionWorld.x + " " + nodes[i][j].positionWorld.y + " " + nodes[i][j].positionWorld.z);
                                                HandsRecognition.addObject(new LED3DEphemeralDot(ledX, ledY, 0, new RGB(0xcc, 0xcc, 0xcc)));
                                            }

                                            sz += 4;
                                        }



                                        g.DrawEllipse(currnetPen, x - sz / 2, y - sz / 2, sz, sz);
                                    }
                                }
                            }
                        }
                    }
                    g.Dispose();
                }
            }
        }
Exemplo n.º 6
0
        //public enum mode
        //{
        //    piano = 0,
        //    drum = 1
        //}

        public void Start(int mode)
        {
            HandsRecognition gr = new HandsRecognition(this);
            gr.SimplePipeline(mode);
            stop = false;
        }