void GetRemoveBackground(KinectOneLabelMap labelmap, KinectOneImage image, Kinect.ColorSpacePoint[] colorSpaces)
    {
        byte[]    data       = labelmap.GetData();
        Color32[] _image     = image.GetColorTexture().GetPixels32();
        int       imageWidth = image.Sensor.ColorFrameSource.FrameDescription.Width;

        for (int i = 0; i < outputPixels.Length; i++)
        {
            byte indexValue = data[i];
            if (IsValidFloatValue(colorSpaces[i].X) || IsValidFloatValue(colorSpaces[i].Y) || indexValue == 255)
            {
                outputPixels[i] = new Color32(0, 0, 0, 0);
            }
            else
            {
                float x = colorSpaces[i].X, y = colorSpaces[i].Y;
                int   colorIndex = (int)y * imageWidth + (int)x;
                outputPixels[i] = (indexValue > 0) ? ((indexValue <= labelToColor.Length) ? labelToColor[indexValue - 1] : defaultColor) : bgColor;
                if (indexValue == m_engageuser.engagedTrackedUser.Id && colorIndex < _image.Length && colorIndex > 0)
                {
                    outputPixels[i] = _image[colorIndex];
                }
            }
        }
    }
    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;
    }
    void UpdateTexture(KinectOneDepth depth, KinectOneLabelMap labelmap, KinectOneImage image)
    {
        int trackedUserId = -1;

        if (m_engageuser != null && m_engageuser.engagedTrackedUser != null)
        {
            trackedUserId = m_engageuser.engagedTrackedUser.Id;
        }
        if (trackedUserId == -1)
        {
            GetNoTrackingTexture(depth);
        }
        else
        {
            Kinect.ColorSpacePoint[] colorSpacePoints = new Kinect.ColorSpacePoint[depth.xres * depth.yres];
            _mapper.MapDepthFrameToColorSpace(depth.GetData(), colorSpacePoints);
            GetRemoveBackground(labelmap, image, colorSpacePoints);
        }
        texture.SetPixels32(outputPixels);
        texture.Apply();
    }
 void GetRemoveBackground(KinectOneLabelMap labelmap, KinectOneImage image, Kinect.ColorSpacePoint[] colorSpaces)
 {
     byte[] data = labelmap.GetData();
     Color32[] _image = image.GetColorTexture().GetPixels32();
     int imageWidth = image.Sensor.ColorFrameSource.FrameDescription.Width;
     for (int i = 0; i < outputPixels.Length; i++)
     {
         byte indexValue = data[i];
         if (IsValidFloatValue(colorSpaces[i].X) || IsValidFloatValue(colorSpaces[i].Y) || indexValue == 255)
         {
             outputPixels[i] = new Color32(0, 0, 0, 0);
         }
         else
         {
             float x=colorSpaces[i].X, y=colorSpaces[i].Y;
             int colorIndex = (int)y * imageWidth + (int)x;
             outputPixels[i] = (indexValue > 0) ? ((indexValue <= labelToColor.Length) ? labelToColor[indexValue - 1] : defaultColor) : bgColor;
             if (indexValue == m_engageuser.engagedTrackedUser.Id && colorIndex < _image.Length && colorIndex > 0)
             {
                 outputPixels[i] = _image[colorIndex];
             }
         }
     }
 }
 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;
 }
 void UpdateTexture(KinectOneDepth depth, KinectOneLabelMap labelmap, KinectOneImage image)
 {
     int trackedUserId = -1;
     if (m_engageuser != null && m_engageuser.engagedTrackedUser != null)
         trackedUserId = m_engageuser.engagedTrackedUser.Id;
     if (trackedUserId == -1)
     {
         GetNoTrackingTexture(depth);
     }
     else
     {
         Kinect.ColorSpacePoint[] colorSpacePoints = new Kinect.ColorSpacePoint[depth.xres * depth.yres];
         _mapper.MapDepthFrameToColorSpace(depth.GetData(), colorSpacePoints);
         GetRemoveBackground(labelmap, image, colorSpacePoints);
     }
     texture.SetPixels32(outputPixels);
     texture.Apply();
 }