Exemplo n.º 1
0
        /* Displaying current frames hand joints */
        private void DisplayJoints(PXCMHandData handOutput, long timeStamp = 0)
        {
            if (form.GetJointsState() || form.GetSkeletonState())
            {
                //Iterate hands
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handOutput.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    //PXCMHandAnalysis.HandData handData = new PXCMHandAnalysis.HandData();
                    PXCMHandData.IHand handData;
                    if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            } // end iterating over joints
                        }
                    }
                } // end itrating over hands

                form.DisplayJoints(nodes, numOfHands);
            }
            else
            {
                form.DisplayJoints(null, 0);
            }
        }
Exemplo n.º 2
0
        public void updateData(PXCMHandData.IHand handData)
        {
            this.handJoint = new PXCMHandData.JointData[22];



            var jointTypes = Enum.GetValues(typeof(PXCMHandData.JointType)).Cast <PXCMHandData.JointType>();

            int index = 0;

            foreach (var jtmp in jointTypes)
            {
                PXCMHandData.JointData jdata = null;
                handData.QueryTrackedJoint(jtmp, out jdata);
                handJoint[index] = jdata;
                index++;
            }

            index = 0;

            this.handFinger = new PXCMHandData.FingerData[5];
            var fingerTypes = Enum.GetValues(typeof(PXCMHandData.FingerType)).Cast <PXCMHandData.FingerType>();

            foreach (var fmp in fingerTypes)
            {
                PXCMHandData.FingerData fdata = null;
                handData.QueryFingerData(fmp, out fdata);
                handFinger[index] = fdata;
                index++;
            }

            this.handContourInner = new List <PXCMPointI32[]>();
            this.handContourOuter = new List <PXCMPointI32[]>();
            int contourNumber = handData.QueryNumberOfContours();

            if (contourNumber > 0)
            {
                PXCMPointI32[] pointOuter;
                PXCMPointI32[] pointInner;
                for (int k = 0; k < contourNumber; ++k)
                {
                    PXCMHandData.IContour contour;
                    pxcmStatus            sts = handData.QueryContour(k, out contour);
                    if (sts == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (contour.IsOuter() == true)
                        {
                            contour.QueryPoints(out pointOuter);
                            handContourOuter.Add(pointOuter);
                        }
                        else
                        {
                            contour.QueryPoints(out pointInner);
                            handContourInner.Add(pointInner);
                        }
                    }
                }
            }
        }
        private void SetVisibleJointPosition(Item item, PXCMHandData.JointData jointData)
        {
            var imagePosition = ToPoint3D(jointData.positionImage);
            var worldPosition = ToPoint3D(jointData.positionWorld);

            item.IsVisible = true;
            item.Position  = CreatePosition(imagePosition, worldPosition);
        }
        /* Displaying current frames hand joints */
        private void DisplayJoints(PXCMHandData handOutput, long timeStamp = 0)
        {
            if (form.GetJointsState() || form.GetSkeletonState())
            {
                //Iterate hands
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handOutput.QueryNumberOfHands();
                if (numOfHands > 1)
                {
                    numOfHands = 1;
                }
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    //PXCMHandAnalysis.HandData handData = new PXCMHandAnalysis.HandData();
                    PXCMHandData.IHand handData;
                    if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            float xsum = 0;
                            float ysum = 0;
                            int   num  = 0;
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                                if (jointData.positionImage.x > 0 && jointData.positionImage.y > 0)
                                {
                                    xsum += jointData.positionImage.x;
                                    ysum += jointData.positionImage.y;
                                    num++;
                                }
                            } // end iterating over joints
                            float xmean = xsum / num;
                            float ymean = ysum / num;
                            //Console.WriteLine(String.Format("({0},{0})",xsum/num ,ysum/num ));
                            form.DisplayHandPointAndPressKey(xmean, ymean);
                        }
                    }
                } // end itrating over hands

                form.DisplayJoints(nodes, numOfHands);
            }
            else
            {
                form.DisplayJoints(null, 0);
            }
        }
Exemplo n.º 5
0
	public bool isRight;/* whether right hand is existed */

	public HandsModel(){
		jointData = new PXCMHandData.JointData[MaxHands][];
		isLeft = false;
		isRight = false;
		
		for (int i = 0; i < MaxHands; i++) {
			jointData [i] = new PXCMHandData.JointData[MaxJoints];
		}
		
		for (int i = 0; i < MaxHands; i++)
		for (int j = 0; j < MaxJoints; j++) {
			jointData [i] [j] = new PXCMHandData.JointData ();
		}
	}
Exemplo n.º 6
0
    //Populate bones and joints gameobjects
    void InitializeGameobjects()
    {
        myJoints  = new GameObject[MaxHands][];
        myBones   = new GameObject[MaxHands][];
        jointData = new PXCMHandData.JointData[MaxHands][];
        for (int i = 0; i < MaxHands; i++)
        {
            myJoints[i]   = new GameObject[MaxJoints];
            myBones[i]    = new GameObject[MaxJoints];
            smoother3D[i] = new PXCMSmoother.Smoother3D[MaxJoints];
            jointData[i]  = new PXCMHandData.JointData[MaxJoints];
        }

        for (int i = 0; i < MaxHands; i++)
        {
            for (int j = 0; j < MaxJoints; j++)
            {
                smoother3D[i][j] = smoother.Create3DWeighted(weightsNum);
                jointData[i][j]  = new PXCMHandData.JointData();

                if (j == 1)
                {
                    myJoints[i][j] = (GameObject)Instantiate(PalmCenterPrefab, Vector3.zero, Quaternion.identity);
                }
                else if (j == 21 || j == 17 || j == 13 || j == 9 || j == 5)
                {
                    myJoints[i][j] = (GameObject)Instantiate(TipPrefab, Vector3.zero, Quaternion.identity);
                }
                else
                {
                    myJoints[i][j] = (GameObject)Instantiate(JointPrefab, Vector3.zero, Quaternion.identity);
                }

                if (j != 1)
                {
                    myBones[i][j] = (GameObject)Instantiate(BonePrefab, Vector3.zero, Quaternion.identity);
                }
            }
        }
    }
Exemplo n.º 7
0
    PXCMHandData.JointData[,] getHandInfo()
    {
        int handNum = handData.QueryNumberOfHands();

        PXCMHandData.JointData[,] nodes = new PXCMHandData.JointData[handNum, PXCMHandData.NUMBER_OF_JOINTS];

        // Iterate through hands
        for (int i = 0; i < handNum; i++)
        {
            // Get hand joints by time of appearance
            PXCMHandData.IHand ihandData;
            if (handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out ihandData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                for (int j = 0; j < PXCMHandData.NUMBER_OF_JOINTS; j++)
                {
                    ihandData.QueryTrackedJoint((PXCMHandData.JointType)j, out nodes[i, j]);
                }
            }
        }

        return(nodes);
    }
 public MainWindow2()
 {
     InitializeComponent();
     nodes               = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
     currentPoint        = new Point();
     gesture             = Gesture.Undefined;
     xValues             = new float[arraySize];
     yValues             = new float[arraySize];
     zValues             = new float[arraySize];
     xyzValueIndex       = 0;
     detectionAlert      = string.Empty;
     calibrationAlert    = string.Empty;
     bordersAlert        = string.Empty;
     detectionStatusOk   = false;
     calibrationStatusOk = false;
     borderStatusOk      = false;
     processingThread    = new Thread(new ThreadStart(ProcessingThread));
     senseManager        = PXCMSenseManager.CreateInstance();
     senseManager.EnableHand();
     senseManager.Init();
     ConfigureHandModule();
     processingThread.Start();
 }
Exemplo n.º 9
0
        pxcmStatus newHandFrame(PXCMHandModule hand)
        {
            if (hand != null)
            {
                PXCMHandData handData = hand.CreateOutput();
                handData.Update();

                PXCMHandData.IHand     iHandDataLeft = null, iHandDataRight = null;
                PXCMHandData.JointData jointData = null;
                PXCMImage image = null;

                handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_LEFT_HANDS, 0, out iHandDataLeft);
                handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_RIGHT_HANDS, 0, out iHandDataRight);
                if (handForm != null && !handForm.IsDisposed)
                {
                    this.handForm.HandCount = handData.QueryNumberOfHands();
                    if (iHandDataLeft != null)
                    {
                        iHandDataLeft.QuerySegmentationImage(out image);
                        if (image != null)
                        {
                            PXCMImage.ImageData data = new PXCMImage.ImageData();
                            image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data);
                            handForm.LeftHand = data.ToBitmap(0, image.info.width, image.info.height);
                            image.ReleaseAccess(data);
                        }
                    }
                    if (iHandDataRight != null)
                    {
                        iHandDataRight.QuerySegmentationImage(out image);
                        if (image != null)
                        {
                            PXCMImage.ImageData data = new PXCMImage.ImageData();
                            image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32, out data);
                            handForm.RightHand = data.ToBitmap(0, image.info.width, image.info.height);
                            image.ReleaseAccess(data);
                        }
                    }
                }
                if (iHandDataLeft != null)
                {
                    if (jointData == null)
                    {
                        iHandDataLeft.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out jointData);
                    }
                }
                if (iHandDataRight != null)
                {
                    if (jointData == null)
                    {
                        iHandDataRight.QueryTrackedJoint(PXCMHandData.JointType.JOINT_INDEX_TIP, out jointData);
                    }
                }
                if (jointData != null && canTrack.Checked)
                {
                    Cursor.Position = new System.Drawing.Point(
                        (int)((640.0f - jointData.positionImage.x) * Screen.PrimaryScreen.Bounds.Width / 640.0f),
                        (int)(jointData.positionImage.y * Screen.PrimaryScreen.Bounds.Height / 480.0f));
                    PXCMHandData.GestureData gestureData = null;
                    if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData))
                    {
                        Program.DoMouseClick();
                    }
                    Console.WriteLine("Z Position: " + jointData.positionWorld.z);
                }

                handData.Dispose();
            }
            return(pxcmStatus.PXCM_STATUS_NO_ERROR);
        }
Exemplo n.º 10
0
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands, MaxJoints];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        myJoints = new Joint[MaxHands, MaxJoints];

        Joint[] joints;
        if (RightHand != null)
        {
            HandMapping RightMapping = RightHand.GetComponent <HandMapping>();
            joints = RightMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[0, j] = joints[j];
            }
        }

        if (LeftHand != null)
        {
            HandMapping LeftMapping = LeftHand.GetComponent <HandMapping>();
            joints = LeftMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[1, j] = joints[j];
            }
        }

        jointData = new PXCMHandData.JointData[MaxHands, MaxJoints];

        for (int i = 0; i < MaxHands; i++)
        {
            for (int j = 0; j < MaxJoints; j++)
            {
                Joint joint = myJoints[i, j];
                if (joint != null)
                {
                    joint.originalPosition = joint.transform.position;
                    joint.originalRotation = joint.transform.rotation;

                    //Calculate orientation
                    Vector3 v          = Vector3.zero;
                    Vector3 parent     = joint.transform.position;
                    int     childcount = 0;

                    foreach (Joint.Neighbour n in joint.neighbours)
                    {
                        if (n.index < j)
                        {
                            parent = n.joint.transform.position;
                        }
                        else
                        {
                            v += n.joint.transform.position;
                            childcount++;
                        }
                    }
                    Vector3 direction = v - parent * childcount;
                    joint.originalOrientation = direction + parent - joint.transform.position;

                    //Joint extensions
                    foreach (Joint e in joint.extensions)
                    {
                        e.originalPosition    = e.transform.position;
                        e.originalRotation    = e.transform.rotation;
                        e.originalOrientation = joint.transform.position - e.transform.position;
                    }
                }

                smoother3D[i, j] = smoother.Create3DWeighted(smoothing);
                jointData[i, j]  = new PXCMHandData.JointData();

                //Test output to check Hand Mapping
                if (myJoints[i, j] == null)
                {
                    Debug.Log("null");
                }
                else
                {
                    Debug.Log(myJoints[i, j].transform.name);
                }
            }
        }
    }
Exemplo n.º 11
0
Arquivo: source.cs Projeto: sbst/code
        pxcmStatus OnModuleProcessedFrame(Int32 mid, PXCMBase module, PXCMCapture.Sample sample)
        {
            thread.Wait();
            if (mid == PXCMHandModule.CUID)
            {
                PXCMHandModule hand = module.QueryInstance<PXCMHandModule>();
                PXCMHandData handData = hand.CreateOutput();
                handData.Update();
                if (handData == null)
                {
                    Console.WriteLine("Failed Create Output");
                    Console.WriteLine("That`s all...");
                    Console.ReadKey();
                    return 0;
                }
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handData.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    PXCMHandData.IHand IhandData;
                    if (handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out IhandData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                IhandData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            } // end iterating over joints
                        }
                    }
                } // end itrating over hands
                int numOfGestures = handData.QueryFiredGesturesNumber();
                if (numOfGestures > 0)
                {
                    for (int i = 0; i < numOfGestures; i++)
                    {
                        PXCMHandData.GestureData gestureData;
                        if (handData.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            switch (gestureData.name)
                            {
                                case "thumb_up":
                                    break;

                                case "thumb_down":
                                    break;

                                case "fist":
                                    break;

                                case "spreadfingers":
                                    textSpeed.Invoke(new Inform((s) => textSpeed.Text = s), vol[0].ToString("F"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Spreadfingers" + "\n");
                                    break;

                                case "full_pinch":
                                    textPanorama.Invoke(new Inform((s) => textPanorama.Text = s), vol[4].ToString("0.##"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Full pinch" + "\n");
                                    break;

                                case "v_sign":
                                    textVolume.Invoke(new Inform((s) => textVolume.Text = s), vol[3].ToString("F"));
                                    textSpeed.Invoke(new Inform((s) => textSpeed.Text = s), vol[0].ToString("F"));
                                    textPanorama.Invoke(new Inform((s) => textPanorama.Text = s), vol[4].ToString("0.##"));
                                    logTextBox.Invoke(new Inform((s) =>  logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: V sign" + "\n");
                                    break;
                            }
                        }

                    }
                }

            }
            return pxcmStatus.PXCM_STATUS_NO_ERROR;
        }
Exemplo n.º 12
0
        protected void DisplayGesturesNew(PXCMHandData.JointData[][] nodes, int numOfHands)
        {
            string handsR = "";
            string handsC = "";

            string info = "";

            // reversed (?)
            bool reversed = false;

            if (numOfHands >= 2)
            {
                PXCMHandData.JointData joint1 = nodes[0][1];
                PXCMHandData.JointData joint2 = nodes[1][1];
                if (joint1 != null && joint2 != null)
                {
                    reversed = joint1.positionImage.x < joint2.positionImage.x;
                }
            }

            if (reversed)
            {
                PXCMHandData.JointData[] hand0 = nodes[0];
                nodes[0] = nodes[1];
                nodes[1] = hand0;
            }

            // joints
            for (int h = 0; h < numOfHands; h++)
            {
                PXCMHandData.JointData joint = nodes[h][0];
                if (joint == null)
                {
                    continue;
                }



                string handInfo = "Hand " + h.ToString() + "\r\n";
                string folded   = GetFolded(nodes[h]);

                handInfo += folded + "\r\n";

                handsC += GetFoldedCount(nodes[h]);
                handsR += GetRoundFingers(nodes[h]);

                string rounded = GetRoundFingers(nodes[h]);
                handInfo += "\r\n" + GetRoundFingers(nodes[h]);
                handInfo += "\r\n" + getProportions(nodes[h]);

                info += handInfo + "\r\n";
            }

            string letter = "?";

            if (handsC == "41")
            {
                letter = findVovel(nodes, GetTip(nodes[1]), handsC);
            }
            if (handsC == "42")
            {
                letter = findVovel(nodes, GetTip(nodes[1]), handsC);
            }
            if (handsC == "43")
            {
                letter = findVovel(nodes, GetTip(nodes[1]), handsC);
            }


            if (letter == "?")
            {
                /*  int leftHandIndexTip = GetTip(nodes[0]);
                 * int rightHandIndexTip = GetTip(nodes[1]);
                 *
                 * PXCMPoint3DF32 leftIndex = nodes[0][5 + 4 * leftHandIndexTip].positionWorld;
                 * PXCMPoint3DF32 rightIndex = nodes[1][5 + 4 * rightHandIndexTip].positionWorld;
                 *
                 * float FDistance = Distance(leftIndex, rightIndex);
                 * bool isF = false;
                 *
                 * if (FDistance < 1000)
                 * {
                 *    isF = true;
                 * }*/

                letter = GetLetter(handsR, handsC);
            }

            info = reversed.ToString() + "\tLetter - " + letter + "\r\n" + "Hands - " + handsR + handsC + "\r\n" + info;
            form.UpdateLetter(letter);
            if (letter != "?")
            {
                form.UpdateKaraoke(letter);
            }
            form.UpdateGestureInfo(info);
        }
Exemplo n.º 13
0
        /* Displaying current frames hand joints */
        private void DisplayJoints(PXCMHandData handOutput, long timeStamp = 0)
        {
            //Iterate hands
            PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
            int numOfHands = handOutput.QueryNumberOfHands();
            for (int i = 0; i < numOfHands; i++)
            {
                //Get hand by time of appearence
                PXCMHandData.IHand handData;
                if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    if (handData != null)
                    {
                        Coordinate coor;
                        string handSide = "Unknown Hand";
                        handSide = handData.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_LEFT ? "Left Hand" : "Right Hand";
                        switch (handSide)
                        {
                            case ("Left Hand"): { coor.handside = 0; Rnum++; break; }
                            case ("Right Hand"): { coor.handside = 1; Lnum++; break; }
                            default: { coor.handside = 2; break; }
                        }

                        //Iterate Joints
                        for (int j = 0; j < 0x20; j++)
                        {
                            sr = File.CreateText(FILE_NAME);
                            PXCMHandData.JointData jointData;
                            handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                            nodes[i][j] = jointData;
                            if (handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData) == pxcmStatus.PXCM_STATUS_NO_ERROR && Handsinfo.JointToInt((PXCMHandData.JointType)j) != -1)
                            {
                                coor.finger = Handsinfo.JointToInt((PXCMHandData.JointType)j);
                                coor.x = jointData.positionWorld.x;
                                coor.y = jointData.positionWorld.y;
                                coor.z = jointData.positionWorld.z;

                                //right 
                                if (coor.finger == 1 && coor.handside == 1)
                                {
                                    this.RHandMove(coor.x, coor.y);
                                    sr.WriteLine(coor.x + " " + coor.y + " " + coor.z + "\n");
                                    MYPoint p = new MYPoint(coor.x, coor.y, coor.z);
                                    int num = rightcp.checkNote(p);
                                    if (num != 0 && Rnum < 2 && Lnum < 2)
                                    {
                                        DateTime DateTime2 = DateTime.Now;
                                        diff = tim.ExecTimeDiff(starttmp, DateTime2);
                                        this.HandClick(num, (int)diff);
                                    }
                                }

                                //left
                                if (coor.finger == 1 && coor.handside == 0)
                                {
                                    this.LHandMove(coor.x, coor.y);
                                    sr.WriteLine(coor.x + " " + coor.y + " " + coor.z + "\n");
                                    MYPoint p = new MYPoint(coor.x, coor.y, coor.z);
                                    int num = leftcp.checkNote(p);
                                    if (num != 0 && Rnum < 2 && Lnum < 2)
                                    {
                                        DateTime DateTime2 = DateTime.Now;
                                        diff = tim.ExecTimeDiff(starttmp, DateTime2);
                                        this.HandClick(num, (int)diff);
                                    }
                                }
                            }
                            sr.Close();
                        } // end iterating over joints
                    }
                } // end itrating over hands
            }
            Lnum = 0; Rnum = 0;
        }
Exemplo n.º 14
0
        protected void DisplayGesturesNew(PXCMHandData.JointData[][] nodes, int numOfHands)
        {
            string handsR = "";
            string handsC = "";

            string info = "";

            // reversed (?)
            bool reversed = false;

            if (numOfHands >= 2)
            {
                PXCMHandData.JointData joint1 = nodes[0][1];
                PXCMHandData.JointData joint2 = nodes[1][1];
                if (joint1 != null && joint2 != null)
                {
                    reversed = joint1.positionImage.x < joint2.positionImage.x;
                }
            }

            if (reversed)
            {
                PXCMHandData.JointData[] hand0 = nodes[0];
                nodes[0] = nodes[1];
                nodes[1] = hand0;
            }

            // joints
            for (int h = 0; h < numOfHands; h++)
            {
                PXCMHandData.JointData joint = nodes[h][0];
                if (joint == null)
                {
                    continue;
                }



                string handInfo = "Hand " + h.ToString() + "\r\n";
                string folded   = GetFolded(nodes[h]);

                handInfo += folded + "\r\n";

                if (folded.Substring(1) == "||__")
                {
                    handInfo += "Victory";
                }
                if (folded == "||__|")
                {
                    form.UpdateKaraoke("*");
                    return;
                }
                if (folded == "|_|__")
                {
                    handInfo += "F**k";
                }


                handsC += GetFoldedCount(nodes[h]);
                handsR += GetRoundFingers(nodes[h]);

                string rounded = GetRoundFingers(nodes[h]);
                handInfo += "\r\n" + GetRoundFingers(nodes[h]);
                handInfo += "\r\n" + getProportions(nodes[h]);

                info += handInfo + "\r\n";
            }

            string letter = "?";

            if (handsC == "41")
            {
                letter = findVovel(nodes, GetTip(nodes[1]));
            }

            if (letter == "?")
            {
                letter = GetLetter(handsR, handsC);
            }

            info = reversed.ToString() + "\tLetter - " + letter + "\r\n" + "Hands - " + handsR + handsC + "\r\n" + info;
            form.UpdateLetter(letter);
            if (letter != "?")
            {
                form.UpdateKaraoke(letter);
            }
            form.UpdateGestureInfo(info);
        }
Exemplo n.º 15
0
        //  System.Windows.Forms.Timer _timer;
        pxcmStatus OnModuleProcessedFrame(Int32 mid, PXCMBase module, PXCMCapture.Sample sample)
        {
            thread.Wait();
            if (mid == PXCMHandModule.CUID)
            {
                PXCMHandModule hand = module.QueryInstance<PXCMHandModule>();
                PXCMHandData handData = hand.CreateOutput();
                handData.Update();
                if (handData == null)
                {
                    Console.WriteLine("Failed Create Output");
                    Console.WriteLine("That`s all...");
                    Console.ReadKey();
                    return 0;
                }
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handData.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    PXCMHandData.IHand IhandData;
                    if (handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out IhandData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                IhandData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            } // end iterating over joints
                        }
                    }
                } // end itrating over hands
                int numOfGestures = handData.QueryFiredGesturesNumber();
                if (numOfGestures > 0)
                {
                    for (int i = 0; i < numOfGestures; i++)
                    {
                        PXCMHandData.GestureData gestureData;
                        if (handData.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            switch (gestureData.name)
                            {
                                case "wave":
                                    string[] response = GET("http://168.63.82.20/api/login", "login=sbst&password=ebc1628c26f8515f81a5178a5abfcbd9").Split('\"');
                                    response = GET("http://168.63.82.20/api/thing", @"user_id=" + response[7] + @"&token=" + response[3] + @"&did=yk5ynj69aw7z").Split('\"'); ;
                                    label1.Invoke(new Inform((s) => label1.Text = s), response[15] + " C");
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text + WindState.ToString()), "GETDATA Temperature:" + response[15] + " C" + "\n");
                                    break;

                                case "tap":
                                    flagLight++;
                                    if (flagLight == 2)
                                    {
                                        if (LightState == 0)
                                            LightState = 1;
                                        else
                                            LightState = 0;
                                        flagLight = 0;
                                        logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), "MAKEDATA LightState:" + LightState + " WindState:" + WindState + "\n");
                                    }

                                    break;

                                case "swipe_up":
                                    flagWind++;
                                    if (flagWind == 2)
                                    {
                                        if (WindState == 0)
                                            WindState = 1;
                                        else
                                            WindState = 0;
                                        flagWind = 0;
                                        logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text + WindState.ToString()), "MAKEDATA LightState:" + LightState + " WindState:" + WindState + "\n");
                                    }
                                    break;

                                case "thumb_up":
                                    SendState++;
                                    if (SendState == 2)
                                    {
                                        if (LightState == 0)
                                            ChangeSwitch(DidLight, "501");
                                        else
                                            ChangeSwitch(DidLight, "498");

                                        if (WindState == 0)
                                            ChangeSwitch(DidWind, "501");
                                        else
                                            ChangeSwitch(DidWind, "498");
                                        logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), "SENDDATA LightState:" + LightState + " WindState:" + WindState + "\n");
                                        //SendState = 0;
                                    }
                                    break;
                                    //textVolume.Invoke(new Inform((s) => textVolume.Text = s), vol[3].ToString("F"));
                                    //textSpeed.Invoke(new Inform((s) => textSpeed.Text = s), vol[0].ToString("F"));
                                    //textPanorama.Invoke(new Inform((s) => textPanorama.Text = s), vol[4].ToString("0.##"));
                                    //logTextBox.Invoke(new Inform((s) =>  logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: V sign" + "\n");
                            }
                        }

                    }
                }
            }
            //Thread.Sleep(100);
            return pxcmStatus.PXCM_STATUS_NO_ERROR;
        }
Exemplo n.º 16
0
    /* Constructor */
    public HandsData(int MaxHands, int MaxJoints)
    {
        NumOfHands  = MaxHands;
        NumOfJoints = MaxJoints;
        JointData   = new PXCMHandData.JointData[NumOfHands][]; // Joint coordinates
        Coordinates = new Main.HandCoord[NumOfHands];

        /* Declaration of the array for the hand data*/
        for (int i = 0; i < NumOfHands; i++)
        {
            JointData[i]   = new PXCMHandData.JointData[NumOfJoints];
            Coordinates[i] = new Main.HandCoord(6, NumOfJoints);
            for (int j = 0; j < NumOfJoints; j++)
            {
                JointData[i][j] = new PXCMHandData.JointData();
            }
        }

        /* Initialization of SenseManager */
        SenseManager = PXCMSenseManager.CreateInstance();
        if (SenseManager == null)
        {
            Debug.LogError("Initialization of the SenseManager has failed");
        }

        /* Enable hand tracking and get an instance of an hand module */
        Status     = SenseManager.EnableHand();
        HandModule = SenseManager.QueryHand();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager --> EnableHand " + Status);
        }

        /* Create the connection to the Intel RealSense camera */
        Status = SenseManager.Init();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("Initialization of SenseManager: " + Status);
        }



        /* Settings for the hand module */
        PXCMHandConfiguration HandConfig = HandModule.CreateActiveConfiguration();

        if (HandConfig != null)
        {
            HandConfig.EnableAllGestures();
            HandConfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);

            PXCMHandData.JointType st = PXCMHandData.JointType.JOINT_WRIST;
            for (int i = 0; i < NumOfJoints; i++)
            {
                HandConfig.EnableJointSpeed(st, PXCMHandData.JointSpeedType.JOINT_SPEED_AVERAGE, 1000 / 10);
                st++;
            }

            //HandConfig.EnableJointSpeed(PXCMHandData.JointType.JOINT_WRIST, PXCMHandData.JointSpeedType.JOINT_SPEED_ABSOLUTE,1000/20);
            HandConfig.ApplyChanges();
            HandConfig.Dispose();
        }
    }
Exemplo n.º 17
0
        /* Displaying current frames hand joints */
        private void DisplayJoints(PXCMHandData handOutput, long timeStamp = 0)
        {
            if (form.GetJointsState() || form.GetSkeletonState())
            {
                //Iterate hands
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handOutput.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    //PXCMHandAnalysis.HandData handData = new PXCMHandAnalysis.HandData();
                    PXCMHandData.IHand handData;
                    if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;

                            } // end iterating over joints
                        }
                    }
                } // end itrating over hands

                form.DisplayJoints(nodes, numOfHands);
                DisplayGesturesNew(nodes, numOfHands);
            }
            else
            {
                form.DisplayJoints(null, 0);
            }
        }
Exemplo n.º 18
0
    //Populate bones and joints gameobjects
    void InitializeGameobjects()
    {
        myJoints = new GameObject[MaxHands][];
        myBones = new GameObject[MaxHands][];
        jointData = new PXCMHandData.JointData[MaxHands][];
        for (int i = 0; i < MaxHands; i++) {
            myJoints [i] = new GameObject[MaxJoints];
            myBones [i] = new GameObject[MaxJoints];
            smoother3D [i] = new PXCMDataSmoothing.Smoother3D[MaxJoints];
            jointData [i] = new PXCMHandData.JointData[MaxJoints];
        }

        for (int i = 0; i < MaxHands; i++)
            for (int j = 0; j < MaxJoints; j++) {

                smoother3D [i] [j] = ds.Create3DWeighted (weightsNum);
                jointData [i] [j] = new PXCMHandData.JointData ();

                if (j == 1)
                    myJoints [i] [j] = (GameObject)Instantiate (PalmCenterPrefab, transform.position, Quaternion.identity);
                else if (j == 21 || j == 17 || j == 13 || j == 9 || j == 5)
                    myJoints [i] [j] = (GameObject)Instantiate (TipPrefab, transform.position, Quaternion.identity);
                else
                    myJoints [i] [j] = (GameObject)Instantiate (JointPrefab, transform.position, Quaternion.identity);

                if (j != 1)
                    myBones [i] [j] = (GameObject)Instantiate (BonePrefab, transform.position, Quaternion.identity);
            }
    }
Exemplo n.º 19
0
    //Smoothen and Display the Joint Data by moving the Hand
    void MoveJoints(int i)
    {
        //Caclulate the target positions of the joints
        Vector3[] targetPositions = new Vector3[MaxJoints];
        for (int j = 0; j < MaxJoints; j++)
        {
            Joint joint = myJoints[i, j];
            PXCMHandData.JointData data = jointData[i, j];
            jointData[i, j] = null;
            if (joint == null || data == null || data.confidence != 100)
            {
                continue;
            }

            PXCMPoint3DF32 smoothedPoint  = smoother3D[i, j].SmoothValue(data.positionWorld);
            Vector3        targetPosition = new Vector3(-1 * smoothedPoint.x, smoothedPoint.y, smoothedPoint.z);

            targetPosition -= trackingOffset[i];

            //Clamp the offset
            Vector3 offset = targetPosition - joint.transform.position;
            if (offset.magnitude > speed)
            {
                offset = offset.normalized * speed;
            }
            targetPosition = joint.transform.position + offset;

            //Ensure that the bone length to the parent joint is kept
            //Should only have one valid iteration, because joints only have one parent
            //The joints are iterated hierarchically, so that the position of the joint's parent is already updated here
            foreach (Joint.Neighbour neighbour in joint.neighbours)
            {
                if (neighbour.index >= j)   // = Is neighbour a child?
                {
                    continue;
                }
                float bone_length = (neighbour.joint.originalPosition - joint.originalPosition).magnitude;
                //Set target position so that the bone length is kept
                targetPosition = neighbour.joint.transform.position + (targetPosition - neighbour.joint.transform.position).normalized * bone_length;
            }

            //Store the target position
            targetPositions[j] = targetPosition;
        }

        //Apply joint positions and rotate
        for (int j = 0; j < MaxJoints; j++)
        {
            Joint joint = myJoints[i, j];
            if (joint == null)
            {
                continue;
            }

            //Apply the position
            joint.transform.position = targetPositions[j];

            if (!applyRotation || joint.neighbours.Count == 0)
            {
                continue;
            }

            //Calculate orientation
            Vector3 v          = Vector3.zero;
            Vector3 parent     = joint.transform.position;
            int     childcount = 0;

            foreach (Joint.Neighbour n in joint.neighbours)
            {
                if (n.index < j)
                {
                    parent = n.joint.transform.position;
                }
                else
                {
                    v += n.joint.transform.position;
                    childcount++;
                }
            }

            Vector3 direction = v - parent * childcount;
            Debug.DrawLine(parent, direction + parent, Color.red);
            Debug.DrawLine(joint.transform.position, direction + parent, Color.blue);

            Vector3    orientation    = direction + parent - joint.transform.position;
            Quaternion targetRotation = Quaternion.FromToRotation(joint.originalOrientation, orientation);
            //Factor in the original rotation, if the joint transform didnt align with the target rotation
            targetRotation = targetRotation * joint.originalRotation;
            //Clamp rotation
            targetRotation = Quaternion.RotateTowards(joint.transform.rotation, targetRotation, rotateSpeedFactor * speed);

            //Move and Rotate Joint Extensions (skeleton joints that are not tracked)
            foreach (Joint e in joint.extensions)
            {
                Vector3 difference = e.originalPosition - joint.originalPosition;
                e.transform.position = targetPositions[j] + targetRotation * difference;
                e.transform.rotation = targetRotation * e.originalRotation;
            }

            //Joint extension could be a parent in the skeleton, reset position
            joint.transform.position = targetPositions[j];

            //Set own rotation
            joint.transform.rotation = targetRotation;
        }
    }
Exemplo n.º 20
0
        /* Displaying current frames hand joints */
        private void DisplayJoints(PXCMHandData handOutput, long timeStamp = 0)
        {
            if (form.GetJointsState() || form.GetSkeletonState())
            {
                //Iterate hands
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handOutput.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    //PXCMHandAnalysis.HandData handData = new PXCMHandAnalysis.HandData();
                    PXCMHandData.IHand handData;
                    if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            Coordinate coor;
                            string handSide = "Unknown Hand";
                            handSide = handData.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_LEFT ? "Left Hand" : "Right Hand";
                            switch (handSide){
                                case("Left Hand"):
                                    coor.handside = 0;
                                    Rnum++;
                                    break;
                                case("Right Hand"):
                                    coor.handside = 1;
                                    Lnum++;
                                    break;
                                default:
                                    coor.handside = 2;
                                    break;
                            }

                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                                if (handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData) == pxcmStatus.PXCM_STATUS_NO_ERROR && Handsinfo.JointToInt((PXCMHandData.JointType)j) != -1)
                                {
                                    coor.finger = Handsinfo.JointToInt((PXCMHandData.JointType)j);
                                    coor.x = jointData.positionWorld.x;
                                    coor.y = jointData.positionWorld.y;
                                    coor.z = jointData.positionWorld.z;

                                     //right 
                                    if (coor.finger == 1 && coor.handside == 1)// && Rnum == 1)
                                    {
                                        sr.WriteLine(coor.x + " " + coor.y + " " + coor.z + "\n");
                                        MYPoint p = new MYPoint(coor.x, coor.y, coor.z);
                                        int num = rightcp.checkNote(p);

                                        if (num != 0 && Rnum < 2 && Lnum < 2)
                                        {
                                            DateTime DateTime2 = DateTime.Now;
                                            diff = tim.ExecTimeDiff(starttmp, DateTime2);
                                            //form.UpdateInfo("play sound" + num.ToString(), Color.RoyalBlue);
                                            playwave.play(num);
                                            playwave.savehistory(num, (int)diff);
                                        }                                  
                                    }

                                    //left
                                    if (coor.finger == 1 && coor.handside == 0)// && Lnum == 1)
                                    {
                                        sr.WriteLine(coor.x + " " + coor.y + " " + coor.z + "\n");
                                        MYPoint p = new MYPoint(coor.x, coor.y, coor.z);
                                        int num = leftcp.checkNote(p);

                                        if (num != 0 && Rnum < 2 && Lnum < 2)
                                        {
                                            DateTime DateTime2 = DateTime.Now;
                                            diff = tim.ExecTimeDiff(starttmp, DateTime2);
                                            //form.UpdateInfo("play sound" + num.ToString(), Color.RoyalBlue);
                                            playwave.play(num);
                                            playwave.savehistory(num, (int)diff);
                                        } 
                                    }
                                }
                            } // end iterating over joints
                        }
                    } // end itrating over hands
                }
                Lnum = 0; Rnum = 0;
                form.DisplayJoints(nodes, numOfHands);
            }
            else
            {
                form.DisplayJoints(null, 0);
            }
        }
Exemplo n.º 21
0
Arquivo: Form1.cs Projeto: sbst/code
        pxcmStatus OnModuleProcessedFrame(Int32 mid, PXCMBase module, PXCMCapture.Sample sample)
        {
            // check if the callback is from the hand tracking module.
            if (mid == PXCMHandModule.CUID)
            {
                PXCMHandModule hand = module.QueryInstance<PXCMHandModule>();
                PXCMHandData handData = hand.CreateOutput();
                handData.Update();
                if (handData == null)
                {
                    Console.WriteLine("Failed Create Output");
                    Console.WriteLine("That`s all...");
                    Console.ReadKey();
                    return 0;
                }
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handData.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    PXCMHandData.IHand IhandData;
                    if (handData.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out IhandData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                IhandData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            } // end iterating over joints
                        }
                    }
                } // end itrating over hands
                int numOfGestures = handData.QueryFiredGesturesNumber();
                if (numOfGestures > 0)
                {
                    for (int i = 0; i < numOfGestures; i++)
                    {
                        PXCMHandData.GestureData gestureData;
                        if (handData.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            switch (gestureData.name)
                            {
                                case "thumb_up":
                                    if (vol[3] > 10F)
                                        break;
                                    vol[3] += 0.4F;
                                    textVolume.Invoke(new Inform((s) => textVolume.Text = s), vol[3].ToString("F"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Thumb up" + "\n");
                                    Send("/vol4", vol[3]);
                                    break;

                                case "thumb_down":
                                    vol[3] -= 0.4F;
                                    textVolume.Invoke(new Inform((s) => textVolume.Text = s), vol[3].ToString("F"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Thumb down" + "\n");
                                    Send("/vol4", vol[3]);
                                    break;

                                case "fist":
                                    if (vol[0] < 1.6F)
                                        vol[0] += 0.1F;
                                    textSpeed.Invoke(new Inform((s) => textSpeed.Text = s), vol[0].ToString("F"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Fist" + "\n");
                                    Send("/vol1", vol[0]);
                                    break;

                                case "spreadfingers":
                                    if (vol[0] > 0.4F)
                                        vol[0] -= 0.1F;
                                    textSpeed.Invoke(new Inform((s) => textSpeed.Text = s), vol[0].ToString("F"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Spreadfingers" + "\n");
                                //    Send("/vol1", vol[0]);
                                    break;

                                case "full_pinch":
                                    if (vol[4] > 0.9F)
                                        flag3 = 1;

                                    if (vol[4] < 0.1F)
                                        flag3 = 0;

                                    if (flag3 == 0)
                                        vol[4] += 0.1F;
                                    else
                                        vol[4] -= 0.1F;
                                    textPanorama.Invoke(new Inform((s) => textPanorama.Text = s), vol[4].ToString("0.##"));
                                    logTextBox.Invoke(new Inform((s) => logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: Full pinch" + "\n");
                                    Send("/vol2", vol[4]);
                                    break;

                                case "v_sign":
                                    vol[0] = 1F;
                                    Send("/vol1", vol[0]);
                                    vol[4] = 1F;
                                    Send("/vol2", vol[4]);
                                    //vol[2] = 0F;
                                    //Send("/vol3", vol[2]);
                                    vol[3] = 2F;
                                    Send("/vol4", vol[3]);
                                    textVolume.Invoke(new Inform((s) => textVolume.Text = s), vol[3].ToString("F"));
                                    textSpeed.Invoke(new Inform((s) => textSpeed.Text = s), vol[0].ToString("F"));
                                    textPanorama.Invoke(new Inform((s) => textPanorama.Text = s), vol[4].ToString("0.##"));
                                    logTextBox.Invoke(new Inform((s) =>  logTextBox.Text = s + logTextBox.Text), DateTime.Now.ToString("hh:mm:ss") + " Gesture: V sign" + "\n");
                                    //vol[4] = 0.5F;
                                    //Send("/vol5", vol[4]);
                                    //vol[5] = 0F;
                                    //Send("/vol6", vol[5]);
                                    break;
                            }
                            Thread.Sleep(500);//100
                        }

                    }
                }

            }
            // return NO_ERROR to continue, or any error to abort.
            return pxcmStatus.PXCM_STATUS_NO_ERROR;
        }
        /* Displaying current frames hand joints */
        private void DisplayJoints(PXCMHandData handOutput, long timeStamp = 0)
        {
            //if (form.GetJointsState() || form.GetSkeletonState())
            //{

            //Iterate hands
                PXCMHandData.JointData[][] nodes = new PXCMHandData.JointData[][] { new PXCMHandData.JointData[0x20], new PXCMHandData.JointData[0x20] };
                int numOfHands = handOutput.QueryNumberOfHands();
                for (int i = 0; i < numOfHands; i++)
                {
                    //Get hand by time of appearence
                    //PXCMHandAnalysis.HandData handData = new PXCMHandAnalysis.HandData();
                    String jointString = String.Empty;

                    PXCMHandData.IHand handData;
                    if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, i, out handData) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        if (handData != null)
                        {
                            //Iterate Joints
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                handData.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            } // end iterating over joints

                            //for (int j = 0; j < 22; j++)
                            //{
                            //    Single x, y, z, w;
                            //    x = nodes[i][j].localRotation.x;
                            //    y = nodes[i][j].localRotation.y;
                            //    z = nodes[i][j].localRotation.z;
                            //    w = nodes[i][j].localRotation.w;
                            //    jointString = i + "x" + j + ", " + x + "," + y + "," + z + "," + w +"\n";
                            //    form.UpdateInfo(jointString, Color.Red);
                            //} // end iterating over joints
                        }
                    }
                } // end itrating over hands

                form.DisplayJoints(nodes, numOfHands);
            //}
            //else
            //{
            //    form.DisplayJoints(null, 0);
            //}
        }
        private int DisplayHandOrientation(PXCMHandData handAnalysis)
        {
            // HAND ORIENTATION
            PXCMHandData handOutput = handAnalysis;
            int numOfHands = handOutput.QueryNumberOfHands();
            int value = -1;

            if (numOfHands != 2)
                return -1;

            if (numOfHands == 2)
            {
                PXCMHandData.IHand hand1Data;
                PXCMHandData.IHand hand2Data;
                if (handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out hand1Data) == pxcmStatus.PXCM_STATUS_NO_ERROR &&
                handOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 1, out hand2Data) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    PXCMHandData.JointData[] joint1Data = new PXCMHandData.JointData[3];
                    PXCMHandData.JointData[] joint2Data = new PXCMHandData.JointData[3];
                    hand1Data.QueryTrackedJoint((PXCMHandData.JointType)0, out joint1Data[0]);
                    hand1Data.QueryTrackedJoint((PXCMHandData.JointType)1, out joint1Data[1]);
                    hand1Data.QueryTrackedJoint((PXCMHandData.JointType)10, out joint1Data[2]);
                    hand2Data.QueryTrackedJoint((PXCMHandData.JointType)0, out joint2Data[0]);
                    hand2Data.QueryTrackedJoint((PXCMHandData.JointType)1, out joint2Data[1]);
                    hand2Data.QueryTrackedJoint((PXCMHandData.JointType)10, out joint2Data[2]);

                    Single[] x1 = {
                        joint1Data[0].globalOrientation.x,
                        joint1Data[1].globalOrientation.x,
                        joint1Data[2].globalOrientation.x
                   };

                    Single[] x2 = {
                        joint2Data[0].globalOrientation.x,
                        joint2Data[1].globalOrientation.x,
                        joint2Data[2].globalOrientation.x
                    };

                    form.updateXlabel(form.label1, x1[0].ToString());
                    form.updateXlabel(form.label2, x1[1].ToString());
                    form.updateXlabel(form.label3, x1[2].ToString());
                    form.updateXlabel(form.label6, x2[0].ToString());
                    form.updateXlabel(form.label7, x2[1].ToString());
                    form.updateXlabel(form.label8, x2[2].ToString());

                    int x1_pos = -1;
                    int x2_pos = -1;

                    if (x1[0] > 0.9 && x1[1] > 0.9 && x1[2] > 0.9)
                    {
                        x1_pos = 1;
                    }
                    else if (x1[0] < 0.85 && x1[1] < 0.85 && x1[2] < 0.85 )
                    {
                        x1_pos = 2;
                    }

                    if (x2[0] > 0.9 && x2[1] > 0.9 && x2[2] > 0.9)
                    {
                        x2_pos = 1;
                    }
                    else if (x2[0] < 0.85 && x2[1] < 0.85 && x2[2] < 0.85 )
                    {
                        x2_pos = 2;
                    }

                    if (x1_pos == 1 && x2_pos == 1)
                    {
                        value = 0;
                    }
                    else if (x1_pos == 2 && x2_pos == 1)
                    {
                        value = 1;
                    }
                    else if (x1_pos == 1 && x2_pos == 2)
                    {
                        value = 2;
                    }
                    else if (x1_pos == 2 && x2_pos == 2)
                    {
                        value = 3;
                    }

                    form.updateXlabel(form.label4, x1_pos.ToString());
                    form.updateXlabel(form.label5, x2_pos.ToString());
                    form.updateXlabel(form.label9, value.ToString());

                    if (value != -1)
                    {
                        //form.UpdateInfo("Orientation: " + value + "\n", Color.SeaGreen);
                        return value;
                    }

                }
            }

            return -1;
        }