void GetNoTrackingTexture(KinectOneDepth depth) { ushort[] data = depth.GetData(); Debug.Log(outputPixels.Length); for (int i = 0; i < outputPixels.Length; i++) { int depthValue = Mathf.Clamp(data[i], 0, depthToColor.Length - 1); outputPixels[i] = depthToColor[depthValue]; } }
void UpdateHistogram(KinectOneDepth depth) { int i, numOfPoints = 0; System.Array.Clear(depthHistogramMap, 0, depthHistogramMap.Length); short[] rawDepthMap = depth.data; int depthIndex = 0; // assume only downscaling // calculate the amount of source pixels to move per column and row in // output pixels int factorX = depth.xres / textureSize.Width; int factorY = ((depth.yres / textureSize.Height) - 1) * depth.xres; for (int y = 0; y < textureSize.Height; ++y, depthIndex += factorY) { for (int x = 0; x < textureSize.Width; ++x, depthIndex += factorX) { int pixel = rawDepthMap[depthIndex]; pixel = Mathf.Clamp(pixel, 0, depthHistogramMap.Length - 1); if (pixel != 0) { depthHistogramMap[pixel]++; numOfPoints++; } } } depthHistogramMap[0] = 0; if (numOfPoints > 0) { for (i = 1; i < depthHistogramMap.Length; i++) { depthHistogramMap[i] += depthHistogramMap[i - 1]; } depthToColor[0] = Color.black; for (i = 1; i < depthHistogramMap.Length; i++) { float intensity = (1.0f - (depthHistogramMap[i] / numOfPoints)); //depthHistogramMap[i] = intensity * 255; depthToColor[i].r = (byte)(BaseColor.r * intensity); depthToColor[i].g = (byte)(BaseColor.g * intensity); depthToColor[i].b = (byte)(BaseColor.b * intensity); depthToColor[i].a = 255;//(byte)(BaseColor.a * intensity); } } }
void Start() { KinectOneInput input = ((KinectOneInput)KinectOneInput.Instance); _mapper = input.GetMapper(); depthInfo = input.GetDepthSensor(); textureSize = new ResolutionData(depthInfo.Sensor.DepthFrameSource.FrameDescription.Width, depthInfo.Sensor.DepthFrameSource.FrameDescription.Height); texture = new Texture2D(depthInfo.Sensor.DepthFrameSource.FrameDescription.Width, depthInfo.Sensor.DepthFrameSource.FrameDescription.Height,TextureFormat.RGBA32,false); texture.wrapMode = TextureWrapMode.Clamp; depthHistogramMap = new float[depthInfo.Sensor.DepthFrameSource.DepthMaxReliableDistance]; depthToColor = new Color32[depthInfo.Sensor.DepthFrameSource.DepthMaxReliableDistance]; outputPixels = new Color32[textureSize.Width * textureSize.Height]; if (null != target) { target.material.mainTexture = texture; } m_engageuser = this.GetComponent<KinectOneEngageSingleUser>(); CalImage2Screen(DepthImagePos.LeftMain); }
void Start() { KinectOneInput input = ((KinectOneInput)KinectOneInput.Instance); _mapper = input.GetMapper(); depthInfo = input.GetDepthSensor(); textureSize = new ResolutionData(depthInfo.Sensor.DepthFrameSource.FrameDescription.Width, depthInfo.Sensor.DepthFrameSource.FrameDescription.Height); texture = new Texture2D(depthInfo.Sensor.DepthFrameSource.FrameDescription.Width, depthInfo.Sensor.DepthFrameSource.FrameDescription.Height, TextureFormat.RGBA32, false); texture.wrapMode = TextureWrapMode.Clamp; depthHistogramMap = new float[depthInfo.Sensor.DepthFrameSource.DepthMaxReliableDistance]; depthToColor = new Color32[depthInfo.Sensor.DepthFrameSource.DepthMaxReliableDistance]; outputPixels = new Color32[textureSize.Width * textureSize.Height]; if (null != target) { target.material.mainTexture = texture; } m_engageuser = this.GetComponent <KinectOneEngageSingleUser>(); CalImage2Screen(DepthImagePos.LeftMain); }
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 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 UpdateHistogram(KinectOneDepth depth) { int i, numOfPoints = 0; System.Array.Clear(depthHistogramMap, 0, depthHistogramMap.Length); short[] rawDepthMap = depth.data; int depthIndex = 0; // assume only downscaling // calculate the amount of source pixels to move per column and row in // output pixels int factorX = depth.xres / textureSize.Width; int factorY = ((depth.yres / textureSize.Height) - 1) * depth.xres; for (int y = 0; y < textureSize.Height; ++y, depthIndex += factorY) { for (int x = 0; x < textureSize.Width; ++x, depthIndex += factorX) { int pixel = rawDepthMap[depthIndex]; pixel=Mathf.Clamp(pixel, 0, depthHistogramMap.Length-1); if (pixel != 0) { depthHistogramMap[pixel]++; numOfPoints++; } } } depthHistogramMap[0] = 0; if (numOfPoints > 0) { for (i = 1; i < depthHistogramMap.Length; i++) { depthHistogramMap[i] += depthHistogramMap[i - 1]; } depthToColor[0] = Color.black; for (i = 1; i < depthHistogramMap.Length; i++) { float intensity = (1.0f - (depthHistogramMap[i] / numOfPoints)); //depthHistogramMap[i] = intensity * 255; depthToColor[i].r = (byte)(BaseColor.r * intensity); depthToColor[i].g = (byte)(BaseColor.g * intensity); depthToColor[i].b = (byte)(BaseColor.b * intensity); depthToColor[i].a = 255;//(byte)(BaseColor.a * intensity); } } }