Esempio n. 1
0
    bool[] getStickIndex(ushort[] depthData)
    {
        bool[] stickIndex = new bool[depthData.Length];
        for (int i = 0; i < depthData.Length; i++)
        {
            stickIndex[i] = false;
        }

        Kinect.CameraSpacePoint leftHandCameraPoint  = joints[Kinect.JointType.HandLeft].Position;
        Kinect.DepthSpacePoint  leftHandDepthPoint   = mapper.MapCameraPointToDepthSpace(leftHandCameraPoint);
        Kinect.CameraSpacePoint rightHandCameraPoint = joints[Kinect.JointType.HandRight].Position;
        Kinect.DepthSpacePoint  rightHandDepthPoint  = mapper.MapCameraPointToDepthSpace(rightHandCameraPoint);

        depthData = (ushort[])depthData.Clone();
        cutDepthData(depthData, (int)Mathf.Min(leftHandDepthPoint.Y, rightHandDepthPoint.Y) + 300, (int)(Mathf.Max(leftHandCameraPoint.Z, rightHandCameraPoint.Z) * 1000));

        //  left hand
        int  leftStickEndInd = getStickEnd(depthData, leftHandCameraPoint, leftHandDepthPoint);
        bool useCache        = leftStickEndInd == 0;

        if (useCache)
        {
            return(null);
        }
        int rightStickEndInd = getStickEnd(depthData, rightHandCameraPoint, rightHandDepthPoint);

        useCache |= rightStickEndInd == 0;
        if (useCache)
        {
            return(null);
        }

        depthDataCache = (ushort[])depthData.Clone();

        addStickIndex(stickIndex, depthData, leftHandDepthPoint, leftStickEndInd);

        //  right hand
        addStickIndex(stickIndex, depthData, rightHandDepthPoint, rightStickEndInd);

        stickIndexCache = (bool[])stickIndex.Clone();


        return(stickIndex);
    }
    void ZigTrackedUserCenter(KinectOneLabelMap labelmap)
    {
        if (m_engageuser == null || m_engageuser.engagedTrackedUser == null)
        {
            trackedUserIndex = 255;
            return;
        }
        ZigTrackedUser _engagedUser = m_engageuser.engagedTrackedUser;

        Kinect.CameraSpacePoint positionPoint = new Kinect.CameraSpacePoint();
        positionPoint.X = _engagedUser.Position.x;
        positionPoint.Y = _engagedUser.Position.y;
        positionPoint.Z = _engagedUser.Position.z;
        Kinect.DepthSpacePoint depthSpacePoint = _mapper.MapCameraPointToDepthSpace(positionPoint);
        short[] labelData = labelmap.data;
        int     index     = (int)(depthSpacePoint.Y * depthInfo.xres + depthSpacePoint.X);

        trackedUserIndex = (index >= 0 && index < labelData.Length) ? labelData[index] : (short)255;
    }