public PointDepth3D GetDepth3DPosition(FingerType id) { if (this[id].TrackingState == FingerTrackingState.Tracked) { CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.sensor); return mapper.MapSkeletonPointToDepthPoint(this[id].Position, this.sensor.DepthStream.Format); } return new PointDepth3D(); }
void Sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e) { if (!skeletonReadyFlag || CurrViewType != ViewEnum.CameraView) //return if no person is detected return; using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame != null) { depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.Sensor); PointDepth3D leftDepth3D = mapper.MapSkeletonPointToDepthPoint(leftHand, this.Sensor.DepthStream.Format); PointDepth3D rightDepth3D = mapper.MapSkeletonPointToDepthPoint(rightHand, this.Sensor.DepthStream.Format); int index = rightDepth3D.Y * DepthFrameWidth + rightDepth3D.X; if (index < 0 || index > this.depthPixels.Length) return; short currDepth = depthPixels[index].Depth; int indexColor = 0; int rectSize = 0; for (int i = 0; i < this.DepthFrameWidth; i++) { for (int j = 0; j < this.DepthFrameHeight; j++) { indexColor = (j * this.DepthFrameWidth + i) * 4; if (KinectUtil.isInTrackRegion(i, j, rightDepth3D.X, rightDepth3D.Y)) { int indexDepthPixels = j * this.DepthFrameWidth + i; rectDepth3D[rectSize++] = new PointDepth3D(i, j, depthPixels[indexDepthPixels].Depth); } } } if (rectSize == rectWidth * rectHeight) { detector.RightHand = new Hand(rectDepth3D, rightDepth3D, rectWidth, rectHeight); detector.DetectAndSmooth(timeStamp); Fingers.Identify3(this.Sketelon3DFingerTips, timeStamp); timeStamp = (++timeStamp) % KinectUtil.LOOP_TIMES; } this.DepthBitmap.WritePixels( new Int32Rect(0, 0, this.DepthBitmap.PixelWidth, this.DepthBitmap.PixelHeight), this.depthColor, this.DepthBitmap.PixelWidth * sizeof(int), 0); } } }