Exemplo n.º 1
0
        private void SaveHandData(PXCMHandData handAnalysis)
        {
            int numOfHands = handAnalysis.QueryNumberOfHands();

            for (int j = 0; j < numOfHands; j++)
            {
                int id;
                PXCMImage.ImageData data;

                handAnalysis.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, j, out id);
                //Get hand by time of appearance
                PXCMHandData.IHand handData;
                handAnalysis.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, j, out handData);

                if (handData != null)
                {
                    HandData hd = new HandData();
                    hd.updateData(handData);

                    dbhelper.saveEntity(hd);
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessingHandThread()
        {
            // Start AcquireFrame/ReleaseFrame loop
            while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                hand = senseManager.QueryHand();

                if (hand != null)
                {

                    // Retrieve the most recent processed data
                    handData = hand.CreateOutput();
                    handData.Update();

                    // Get number of tracked hands
                    nhands = handData.QueryNumberOfHands();

                    if (nhands > 0)
                    {
                        // Retrieve hand identifier
                        handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out handId);

                        // Retrieve hand data
                        handData.QueryHandDataById(handId, out ihand);

                        // Retrieve all hand joint data
                        for (int i = 0; i < nhands; i++)
                        {
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                ihand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            }
                        }

                        // Get world coordinates for tip of middle finger on the first hand in camera range
                        handTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.x;
                        handTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.y;
                        handTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.z;

                        // Retrieve gesture data
                        if (handData.IsGestureFired("spreadfingers", out gestureData))
                        {
                            gesture = Gesture.FingerSpread;
                        }
                        else if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData))
                        {
                            gesture = Gesture.Pinch;
                        }
                        else if (handData.IsGestureFired("wave", out gestureData))
                        {
                            gesture = Gesture.Wave;
                        }
                    }
                    else
                    {
                        gesture = Gesture.Undefined;
                    }

                    // Get alert status
                    for (int i = 0; i < handData.QueryFiredAlertsNumber(); i++)
                    {
                        PXCMHandData.AlertData alertData;
                        if (handData.QueryFiredAlertData(i, out alertData) != pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; }

                        //Displaying last alert
                        switch (alertData.label)
                        {
                            case PXCMHandData.AlertType.ALERT_HAND_DETECTED:
                                detectionAlert = "Hand Detected";
                                detectionStatusOk = true;
                                break;
                            case PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED:
                                detectionAlert = "Hand Not Detected";
                                detectionStatusOk = false;
                                break;
                            case PXCMHandData.AlertType.ALERT_HAND_CALIBRATED:
                                calibrationAlert = "Hand Calibrated";
                                calibrationStatusOk = true;
                                break;
                            case PXCMHandData.AlertType.ALERT_HAND_NOT_CALIBRATED:
                                calibrationAlert = "Hand Not Calibrated";
                                calibrationStatusOk = false;
                                break;
                            case PXCMHandData.AlertType.ALERT_HAND_INSIDE_BORDERS:
                                bordersAlert = "Hand Inside Borders";
                                borderStatusOk = true;
                                break;
                            case PXCMHandData.AlertType.ALERT_HAND_OUT_OF_BORDERS:
                                bordersAlert = "Hand Out Of Borders";
                                borderStatusOk = false;
                                break;
                        }
                    }

                    UpdateUI();
                    if (handData != null) handData.Dispose();
                }
                senseManager.ReleaseFrame();
            }
        }
        public void ProcessingThread()
        {
            // Start AcquireFrame/ReleaseFrame loop
            while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                hand = senseManager.QueryHand();

                if (hand != null)
                {
                    // Retrieve the most recent processed data
                    handData = hand.CreateOutput();
                    handData.Update();

                    // Get number of tracked hands
                    nhands = handData.QueryNumberOfHands();

                    if (nhands > 0)
                    {
                        // Retrieve hand identifier
                        handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out handId);

                        // Retrieve hand data
                        handData.QueryHandDataById(handId, out ihand);

                        PXCMHandData.BodySideType bodySideType = ihand.QueryBodySide();
                        if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_LEFT)
                        {
                            leftHand = true;
                        }
                        else if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_RIGHT)
                        {
                            leftHand = false;
                        }



                        // Retrieve all hand joint data
                        for (int i = 0; i < nhands; i++)
                        {
                            for (int j = 0; j < 0x20; j++)
                            {
                                PXCMHandData.JointData jointData;
                                ihand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData);
                                nodes[i][j] = jointData;
                            }
                        }

                        // Get world coordinates for tip of middle finger on the first hand in camera range
                        handTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.x;
                        handTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.y;
                        handTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.z;


                        swipehandTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.x;
                        swipehandTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.y;
                        swipehandTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.z;

                        //Console.Out.WriteLine("Before x={0}", swipehandTipX);
                        //Console.Out.WriteLine("Before speed={0}", nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].speed.x);

                        // Retrieve gesture data
                        if (handData.IsGestureFired("spreadfingers", out gestureData))
                        {
                            gesture = Gesture.FingerSpread;
                        }
                        else if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData))
                        {
                            gesture = Gesture.Pinch;
                        }
                        else if (handData.IsGestureFired("wave", out gestureData))
                        {
                            gesture = Gesture.Wave;
                        }
                        else if (handData.IsGestureFired("swipe_left", out gestureData))
                        {
                            gesture = Gesture.SwipeLeft;
                        }
                        else if (handData.IsGestureFired("swipe_right", out gestureData))
                        {
                            gesture = Gesture.SwipeRight;
                        }
                        else if (handData.IsGestureFired("fist", out gestureData))
                        {
                            gesture = Gesture.Fist;
                        }
                        else if (handData.IsGestureFired("thumb_up", out gestureData))
                        {
                            gesture = Gesture.Thumb;
                        }
                    }
                    else
                    {
                        gesture = Gesture.Undefined;
                    }

                    UpdateUI();
                    if (handData != null)
                    {
                        handData.Dispose();
                    }
                }
                senseManager.ReleaseFrame();
            }
        }
Exemplo n.º 4
0
        /* Displaying Depth/Mask Images - for depth image only we use a delay of NumberOfFramesToDelay to sync image with tracking */
        private unsafe void DisplayPicture(PXCMImage depth, PXCMHandData handAnalysis)
        {
            if (depth == null)
            {
                return;
            }

            PXCMImage image = depth;

            //Mask Image
            if (form.GetLabelmapState())
            {
                Bitmap labeledBitmap = null;
                try
                {
                    labeledBitmap = new Bitmap(image.info.width, image.info.height, PixelFormat.Format32bppRgb);
                }
                catch (Exception)
                {
                    image.Dispose();
                    return;
                }

                for (int j = 0; j < handAnalysis.QueryNumberOfHands(); j++)
                {
                    int id;
                    PXCMImage.ImageData data;

                    handAnalysis.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, j, out id);
                    //Get hand by time of appearance
                    PXCMHandData.IHand handData;
                    handAnalysis.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, j, out handData);
                    if (handData != null &&
                        (handData.QuerySegmentationImage(out image) >= pxcmStatus.PXCM_STATUS_NO_ERROR))
                    {
                        if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_Y8,
                                                out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            Rectangle rect = new Rectangle(0, 0, image.info.width, image.info.height);

                            BitmapData bitmapdata = labeledBitmap.LockBits(rect, ImageLockMode.ReadWrite, labeledBitmap.PixelFormat);
                            byte *     numPtr     = (byte *)bitmapdata.Scan0; //dst
                            byte *     numPtr2    = (byte *)data.planes[0];   //row
                            int        imagesize  = image.info.width * image.info.height;
                            byte       num2       = (byte)handData.QueryBodySide();

                            byte tmp = 0;
                            for (int i = 0; i < imagesize; i++, numPtr += 4, numPtr2++)
                            {
                                tmp       = (byte)(LUT[numPtr2[0]] * num2 * 100);
                                numPtr[0] = (Byte)(tmp | numPtr[0]);
                                numPtr[1] = (Byte)(tmp | numPtr[1]);
                                numPtr[2] = (Byte)(tmp | numPtr[2]);
                                numPtr[3] = 0xff;
                            }

                            bool isError = false;

                            try
                            {
                                labeledBitmap.UnlockBits(bitmapdata);
                            }
                            catch (Exception)
                            {
                                isError = true;
                            }
                            try
                            {
                                image.ReleaseAccess(data);
                            }
                            catch (Exception)
                            {
                                isError = true;
                            }

                            if (isError)
                            {
                                labeledBitmap.Dispose();
                                image.Dispose();
                                return;
                            }
                        }
                    }
                }
                if (labeledBitmap != null)
                {
                    form.DisplayBitmap(labeledBitmap);
                    labeledBitmap.Dispose();
                }
                image.Dispose();
            }//end label image

            //Depth Image
            else
            {
                //collecting 3 images inside a queue and displaying the oldest image
                PXCMImage.ImageInfo info;
                PXCMImage           image2;

                info   = image.QueryInfo();
                image2 = form.g_session.CreateImage(info);
                image2.CopyImage(image);
                m_images.Enqueue(image2);
                if (m_images.Count == NumberOfFramesToDelay)
                {
                    Bitmap depthBitmap;
                    try
                    {
                        depthBitmap = new Bitmap(image.info.width, image.info.height, PixelFormat.Format32bppRgb);
                    }
                    catch (Exception)
                    {
                        image.Dispose();
                        PXCMImage queImage = m_images.Dequeue();
                        queImage.Dispose();
                        return;
                    }

                    PXCMImage.ImageData data3;
                    PXCMImage           image3 = m_images.Dequeue();
                    if (image3.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, out data3) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        float fMaxValue = _maxRange;
                        byte  cVal;

                        Rectangle  rect       = new Rectangle(0, 0, image.info.width, image.info.height);
                        BitmapData bitmapdata = depthBitmap.LockBits(rect, ImageLockMode.ReadWrite, depthBitmap.PixelFormat);

                        byte * pDst = (byte *)bitmapdata.Scan0;
                        short *pSrc = (short *)data3.planes[0];
                        int    size = image.info.width * image.info.height;

                        for (int i = 0; i < size; i++, pSrc++, pDst += 4)
                        {
                            cVal = (byte)((*pSrc) / fMaxValue * 255);
                            if (cVal != 0)
                            {
                                cVal = (byte)(255 - cVal);
                            }

                            pDst[0] = cVal;
                            pDst[1] = cVal;
                            pDst[2] = cVal;
                            pDst[3] = 255;
                        }
                        try
                        {
                            depthBitmap.UnlockBits(bitmapdata);
                        }
                        catch (Exception)
                        {
                            image3.ReleaseAccess(data3);
                            depthBitmap.Dispose();
                            image3.Dispose();
                            return;
                        }

                        form.DisplayBitmap(depthBitmap);
                        image3.ReleaseAccess(data3);
                    }
                    depthBitmap.Dispose();
                    image3.Dispose();
                }
            }
        }
Exemplo n.º 5
0
    private void getCursorPositions()
    {
        var numHands = mHand.QueryNumberOfHands();
        int handId   = -1;

        if (numHands < 1)
        {
            mCursor0.transform.localPosition = Vector3.zero;
            mCursor1.transform.localPosition = Vector3.zero;
        }

        if (!UseTwoHands)
        {
            mCursor1.transform.localPosition = Vector3.zero;
        }
        for (var i = 0; i < numHands; ++i)
        {
            mHand.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_ID, i, out handId);
            PXCMHandData.IHand handData;
            if (mHand.QueryHandDataById(handId, out handData) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                if (handData.HasCursor())
                {
                    PXCMHandData.ICursor cursor;
                    if (handData.QueryCursor(out cursor) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        var pos = cursor.QueryPointWorld();
                        if (MapZ)
                        {
                            var newZ = lmap(pos.z, ZRange.x, ZRange.y, ZRange.z, ZRange.w);
                            pos.z = newZ;
                        }
                        Vector3 newPos = new Vector3(pos.x, pos.y, pos.z) * CursorScale;
                        if (handData.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_RIGHT)
                        {
                            mCursor0.transform.localPosition = newPos;
                            if (getGestureState(PXCMHandData.BodySideType.BODY_SIDE_RIGHT))
                            {
                                mCursor0Active = !mCursor0Active;
                                if (mCursor0Active)
                                {
                                    mCursor0.transform.localScale = new Vector3(CursorSize * 3, CursorSize * 3, CursorSize * 3);
                                }
                                else
                                {
                                    mCursor0.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize);
                                }
                            }
                        }
                        else if (handData.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_LEFT && UseTwoHands)
                        {
                            mCursor1.transform.localPosition = newPos;
                            if (getGestureState(PXCMHandData.BodySideType.BODY_SIDE_LEFT))
                            {
                                mCursor1Active = !mCursor1Active;
                                if (mCursor1Active)
                                {
                                    mCursor1.transform.localScale = new Vector3(CursorSize * 3, CursorSize * 3, CursorSize * 3);
                                }
                                else
                                {
                                    mCursor1.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (i == 0)
                    {
                        mCursor0.transform.localPosition = Vector3.zero;
                    }
                    else if (i == 1)
                    {
                        mCursor1.transform.localPosition = Vector3.zero;
                    }
                }
            }
        }
    }
        /* Displaying Depth/Mask Images - for depth image only we use a delay of NumberOfFramesToDelay to sync image with tracking */
        private unsafe void DisplayPicture(PXCMImage depth, PXCMHandData handAnalysis)
        {
            if (depth == null)
                return;

            PXCMImage image = depth;

            //Mask Image
            if (form.GetLabelmapState())
            {
                Bitmap labeledBitmap = null;
                try
                {
                    labeledBitmap = new Bitmap(image.info.width, image.info.height, PixelFormat.Format32bppRgb);
                    for (int j = 0; j < handAnalysis.QueryNumberOfHands(); j++)
                    {
                        int id;
                        PXCMImage.ImageData data;

                        handAnalysis.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, j, out id);
                        //Get hand by time of appearance
                        PXCMHandData.IHand handData;
                        handAnalysis.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, j, out handData);
                        if (handData != null &&
                            (handData.QuerySegmentationImage(out image) >= pxcmStatus.PXCM_STATUS_NO_ERROR))
                        {
                            if (image.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_Y8,
                                out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                Rectangle rect = new Rectangle(0, 0, image.info.width, image.info.height);

                                BitmapData bitmapdata = labeledBitmap.LockBits(rect, ImageLockMode.ReadWrite,
                                    labeledBitmap.PixelFormat);
                                byte* numPtr = (byte*) bitmapdata.Scan0; //dst
                                byte* numPtr2 = (byte*) data.planes[0]; //row
                                int imagesize = image.info.width*image.info.height;
                                byte num2 = (byte) handData.QueryBodySide();

                                byte tmp = 0;
                                for (int i = 0; i < imagesize; i++, numPtr += 4, numPtr2++)
                                {
                                    tmp = (byte) (LUT[numPtr2[0]]*num2*100);
                                    numPtr[0] = (Byte) (tmp | numPtr[0]);
                                    numPtr[1] = (Byte) (tmp | numPtr[1]);
                                    numPtr[2] = (Byte) (tmp | numPtr[2]);
                                    numPtr[3] = 0xff;
                                }

                                labeledBitmap.UnlockBits(bitmapdata);
                                image.ReleaseAccess(data);

                            }
                        }
                    }
                    if (labeledBitmap != null)
                    {
                        form.DisplayBitmap(labeledBitmap);
                        labeledBitmap.Dispose();
                    }
                    image.Dispose();
                }
                catch (Exception)
                {
                    if (labeledBitmap != null)
                    {
                        labeledBitmap.Dispose();
                    }
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }

            }//end label image

            //Depth Image
            else
            {
                //collecting 3 images inside a queue and displaying the oldest image
                PXCMImage.ImageInfo info;
                PXCMImage image2;

                info = image.QueryInfo();
                image2 = form.g_session.CreateImage(info);
                if (image2 == null) { return; }
                image2.CopyImage(image);
                m_images.Enqueue(image2);
                if (m_images.Count == NumberOfFramesToDelay)
                {
                    Bitmap depthBitmap;
                    try
                    {
                        depthBitmap = new Bitmap(image.info.width, image.info.height, PixelFormat.Format32bppRgb);
                    }
                    catch (Exception)
                    {
                        image.Dispose();
                        PXCMImage queImage = m_images.Dequeue();
                        queImage.Dispose();
                        return;
                    }

                    PXCMImage.ImageData data3;
                    PXCMImage image3 = m_images.Dequeue();
                    if (image3.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, out data3) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        float fMaxValue = _maxRange;
                        byte cVal;

                        Rectangle rect = new Rectangle(0, 0, image.info.width, image.info.height);
                        BitmapData bitmapdata = depthBitmap.LockBits(rect, ImageLockMode.ReadWrite, depthBitmap.PixelFormat);

                        byte* pDst = (byte*)bitmapdata.Scan0;
                        short* pSrc = (short*)data3.planes[0];
                        int size = image.info.width * image.info.height;

                        for (int i = 0; i < size; i++, pSrc++, pDst += 4)
                        {
                            cVal = (byte)((*pSrc) / fMaxValue * 255);
                            if (cVal != 0)
                                cVal = (byte)(255 - cVal);

                            pDst[0] = cVal;
                            pDst[1] = cVal;
                            pDst[2] = cVal;
                            pDst[3] = 255;
                        }
                        try
                        {
                            depthBitmap.UnlockBits(bitmapdata);
                        }
                        catch (Exception)
                        {
                            image3.ReleaseAccess(data3);
                            depthBitmap.Dispose();
                            image3.Dispose();
                            return;
                        }

                        form.DisplayBitmap(depthBitmap);
                        image3.ReleaseAccess(data3);
                    }
                    depthBitmap.Dispose();
                    image3.Dispose();
                }
            }
        }
Exemplo n.º 7
0
        private static void ProcessHands(PXCMHandData handData)
        {
            // Querying how many hands were detected
            int numberOfHands = handData.QueryNumberOfHands();
            //Console.WriteLine("{0} hand(s) were detected.", numberOfHands);

            // Querying the information about detected hands
            for (int i = 0; i < numberOfHands; i++)
            {
                // Querying hand id
                int handId;
                pxcmStatus queryHandIdStatus = handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, i, out handId);
                if (queryHandIdStatus != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    Console.WriteLine("Failed to query the hand Id.");
                    continue;
                }
                //Console.WriteLine("Hand id: {0}", handId);

                // Querying the hand data
                PXCMHandData.IHand hand;
                pxcmStatus queryHandStatus = handData.QueryHandDataById(handId, out hand);

                if (queryHandStatus == pxcmStatus.PXCM_STATUS_NO_ERROR && hand != null)
                {

                    // Querying the body side (Left/Right)
                    PXCMHandData.BodySideType bodySide = hand.QueryBodySide();
                    //Console.WriteLine("Body Side: {0}", bodySide);

                    // Querying the hand openness
                    int handOpenness = hand.QueryOpenness();
                    //Console.WriteLine("Hand openness: {0}", handOpenness);

                    //SendMqttMessage(String.Format("surfboard2/red?{0}", (255 *handOpenness)/100));

                    // Querying Hand 2D Position
                    PXCMPointF32 massCenterImage = hand.QueryMassCenterImage();
                    //Console.WriteLine("Hand position on image: {0} | {1}", massCenterImage.x, massCenterImage.y);

                    PXCMPoint4DF32 palmOrientation = hand.QueryPalmOrientation();
                    rotationHelper.SetFromQuaternion(palmOrientation);

                    PXCMPoint3DF32 rotationEuler = rotationHelper.QueryEulerAngles();

                    double angleInDegrees = (180 * rotationEuler.y / Math.PI) + 180;
                    Console.WriteLine("Angle in degrees: {0}", angleInDegrees);
                    SendMqttMessage(String.Format("servo?{0}", (int)angleInDegrees));

                    // Console.WriteLine("Rotation x:{0},y:{1},z:{2}", rotationEuler.x, rotationEuler.y, rotationEuler.z);

                    // Querying Hand 3D Position
                    PXCMPoint3DF32 massCenterWorld = hand.QueryMassCenterWorld();
                    //Console.WriteLine("Hand position on world: {0} | {1} | {2}", massCenterWorld.x, massCenterWorld.y, massCenterWorld.z);

                    /*
                    // Querying Hand Joints
                    if (hand.HasTrackedJoints())
                    {
                        foreach (PXCMHandData.JointType jointType in Enum.GetValues(typeof(PXCMHandData.JointType)))
                        {
                            PXCMHandData.JointData jointData;
                            pxcmStatus queryStatus = hand.QueryTrackedJoint(jointType, out jointData);

                            if (queryStatus == pxcmStatus.PXCM_STATUS_NO_ERROR && jointData != null)
                            {
                                // Printing joint label and tracking confidence
                                Console.WriteLine("Joint {0} with confidence {1}", jointType, jointData.confidence);

                                // Printing the 2D position (image)
                                Console.WriteLine("\t2D Position: {0} | {1}", jointData.positionImage.x, jointData.positionImage.y);

                                // Printing the 3D position (depth)
                                Console.WriteLine("\t3D Position: {0} | {1} | {2}", jointData.positionWorld.x, jointData.positionWorld.y, jointData.positionWorld.z);
                            }
                        }
                    }*/

                }

                //Console.WriteLine("----------");
                //Console.Clear();
            }
        }
Exemplo n.º 8
0
        private static void ProcessHands(PXCMHandData handData)
        {
            // Querying how many hands were detected
            int numberOfHands = handData.QueryNumberOfHands();

            //Console.WriteLine("{0} hand(s) were detected.", numberOfHands);

            // Querying the information about detected hands
            for (int i = 0; i < numberOfHands; i++)
            {
                // Querying hand id
                int        handId;
                pxcmStatus queryHandIdStatus = handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, i, out handId);
                if (queryHandIdStatus != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    Console.WriteLine("Failed to query the hand Id.");
                    continue;
                }
                //Console.WriteLine("Hand id: {0}", handId);

                // Querying the hand data
                PXCMHandData.IHand hand;
                pxcmStatus         queryHandStatus = handData.QueryHandDataById(handId, out hand);

                if (queryHandStatus == pxcmStatus.PXCM_STATUS_NO_ERROR && hand != null)
                {
                    // Querying the body side (Left/Right)
                    PXCMHandData.BodySideType bodySide = hand.QueryBodySide();
                    //Console.WriteLine("Body Side: {0}", bodySide);

                    // Querying the hand openness
                    int handOpenness = hand.QueryOpenness();
                    //Console.WriteLine("Hand openness: {0}", handOpenness);

                    SendMqttMessage(String.Format("red?{0}", (255 * handOpenness) / 100));

                    // Querying Hand 2D Position
                    PXCMPointF32 massCenterImage = hand.QueryMassCenterImage();
                    //Console.WriteLine("Hand position on image: {0} | {1}", massCenterImage.x, massCenterImage.y);

                    PXCMPoint4DF32 palmOrientation = hand.QueryPalmOrientation();
                    rotationHelper.SetFromQuaternion(palmOrientation);

                    PXCMPoint3DF32 rotationEuler = rotationHelper.QueryEulerAngles();

                    double angleInDegrees = (180 * rotationEuler.y / Math.PI) + 180;
                    Console.WriteLine("Angle in degrees: {0}", angleInDegrees);
                    SendMqttMessage(String.Format("red?{0}", (int)angleInDegrees));


                    // Console.WriteLine("Rotation x:{0},y:{1},z:{2}", rotationEuler.x, rotationEuler.y, rotationEuler.z);

                    // Querying Hand 3D Position
                    PXCMPoint3DF32 massCenterWorld = hand.QueryMassCenterWorld();
                    //Console.WriteLine("Hand position on world: {0} | {1} | {2}", massCenterWorld.x, massCenterWorld.y, massCenterWorld.z);

                    /*
                     * // Querying Hand Joints
                     * if (hand.HasTrackedJoints())
                     * {
                     *  foreach (PXCMHandData.JointType jointType in Enum.GetValues(typeof(PXCMHandData.JointType)))
                     *  {
                     *      PXCMHandData.JointData jointData;
                     *      pxcmStatus queryStatus = hand.QueryTrackedJoint(jointType, out jointData);
                     *
                     *      if (queryStatus == pxcmStatus.PXCM_STATUS_NO_ERROR && jointData != null)
                     *      {
                     *          // Printing joint label and tracking confidence
                     *          Console.WriteLine("Joint {0} with confidence {1}", jointType, jointData.confidence);
                     *
                     *          // Printing the 2D position (image)
                     *          Console.WriteLine("\t2D Position: {0} | {1}", jointData.positionImage.x, jointData.positionImage.y);
                     *
                     *          // Printing the 3D position (depth)
                     *          Console.WriteLine("\t3D Position: {0} | {1} | {2}", jointData.positionWorld.x, jointData.positionWorld.y, jointData.positionWorld.z);
                     *      }
                     *  }
                     * }*/
                }

                //Console.WriteLine("----------");
                //Console.Clear();
            }
        }