public Point2D GetPoint2Position(FingerType id) { if (this[id].TrackingState == FingerTrackingState.Tracked) { CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.sensor); return(mapper.MapSkeletonPointToColorPoint(this[id].Position, this.sensor.ColorStream.Format)); } return(new Point2D()); }
/// <summary> /// Call Core Track Algo and Smooth Algo to Track and Smooth FingerTips /// </summary> /// <param name="timeStamp"></param> public void DetectAndSmooth(int timeStamp) { if (null == sensor) { return; } RightHand.FingerDetect(0); CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.sensor); List <PointSkeleton3D> currFingerTips = mapper.MapDepthPointsToSketelonPoints(sensor.DepthStream.Format, RightHand.FingerTips); smoother.Smooth(currFingerTips, timeStamp); }
/// <summary> /// Depth Frame Ready /// According to the Hand position tracked by Kinect, extract small Rectangular pixels matrix for hand tracking /// Extract pixels for each frame, each pixel in matrix has the X,Y,Depth information /// Construct Hand instance, do hand tracking, draw with returning positions of fingertips and palm /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e) { if (!skeletonReadyFlag) { return; } using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame != null) { depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.sensor); PointDepth3D palmDepth3D = mapper.MapSkeletonPointToDepthPoint(rightHand, this.sensor.DepthStream.Format); int index = palmDepth3D.Y * DepthFrameWidth + palmDepth3D.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, palmDepth3D.X, palmDepth3D.Y)) { int indexDepthPixels = j * this.DepthFrameWidth + i; rectDepth3D[rectSize++] = new PointDepth3D(i, j, depthPixels[indexDepthPixels].Depth); //Draw depth pixel according to different distance this.depthColor[indexColor + BLUE] = 255; this.depthColor[indexColor + GREEN] = 0; this.depthColor[indexColor + RED] = 0; this.depthColor[indexColor + AlPHA] = 0; if (depthPixels[indexDepthPixels].Depth >= currDepth - 100 && depthPixels[indexDepthPixels].Depth <= currDepth + 100) { this.depthColor[indexColor + BLUE] = 255; this.depthColor[indexColor + GREEN] = 255; this.depthColor[indexColor + RED] = 255; this.depthColor[indexColor + AlPHA] = 0; } } else { this.depthColor[indexColor + BLUE] = 0; this.depthColor[indexColor + GREEN] = 0; this.depthColor[indexColor + RED] = 0; this.depthColor[indexColor + AlPHA] = 0; } } } #region //for (int i = 0,depthColorIndex = 0; i < this.depthPixels.Length; i++, depthColorIndex += 4) //{ // if (pointRight.X >= (int)(i % this.sensor.DepthStream.FrameWidth) - 50 && // pointRight.X <= (int)(i % this.sensor.DepthStream.FrameWidth) + 50 && // pointRight.Y >= (int)(i / this.sensor.DepthStream.FrameWidth) - 40 && // pointRight.Y <= (int)(i / this.sensor.DepthStream.FrameWidth) + 60) // { // this.depthColor[depthColorIndex + BLUE] = 255; // this.depthColor[depthColorIndex + GREEN] = 0; // this.depthColor[depthColorIndex + RED] = 0; // this.depthColor[depthColorIndex + AlPHA] = 0; // if (depthPixels[i].Depth >= nearDepth - 100 && depthPixels[i].Depth <= nearDepth + 100) // { // this.depthColor[depthColorIndex + BLUE] = 255; // this.depthColor[depthColorIndex + GREEN] = 255; // this.depthColor[depthColorIndex + RED] = 255; // this.depthColor[depthColorIndex + AlPHA] = 0; // } // } // else // { // this.depthColor[depthColorIndex + BLUE] = 0; // this.depthColor[depthColorIndex + GREEN] = 0; // this.depthColor[depthColorIndex + RED] = 0; // this.depthColor[depthColorIndex + AlPHA] = 0; // } //} #endregion //Construct Hand instance for tracker, then do hand tracking if (rectSize == rectWidth * rectHeight) { detector.RightHand = new Hand(rectDepth3D, palmDepth3D, rectWidth, rectHeight); detector.DetectAndSmooth(timeStamp); //Fingers.Identify(this.Sketelon3DFingerTips,timeStamp); //Fingers.Identify2(this.Sketelon3DFingerTips,rightHand, rightWrist); Fingers.Identify3(this.Sketelon3DFingerTips, timeStamp); timeStamp = (++timeStamp) % KinectUtil.LOOP_TIMES; foreach (var element in detector.Depth3DFingerTips) { int k = (element.Y * DepthFrameWidth + element.X) * 4; for (int i = k - 20; i < k + 20; i += 4) { depthColor[i + BLUE] = 0; depthColor[i + GREEN] = 0; depthColor[i + RED] = 255; } } } this.depthBitmap.WritePixels( new Int32Rect(0, 0, this.depthBitmap.PixelWidth, this.depthBitmap.PixelHeight), this.depthColor, this.depthBitmap.PixelWidth * sizeof(int), 0); readyEvent.afterDepthReady(); } } }
/// <summary> /// Depth Frame Ready /// According to the Hand position tracked by Kinect, extract small Rectangular pixels matrix for hand tracking /// Extract pixels for each frame, each pixel in matrix has the X,Y,Depth information /// Construct Hand instance, do hand tracking, draw with returning positions of fingertips and palm /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e) { if (!skeletonReadyFlag) return; using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { if (depthFrame != null) { depthFrame.CopyDepthImagePixelDataTo(this.depthPixels); CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.sensor); PointDepth3D palmDepth3D = mapper.MapSkeletonPointToDepthPoint(rightHand, this.sensor.DepthStream.Format); int index = palmDepth3D.Y * DepthFrameWidth + palmDepth3D.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, palmDepth3D.X, palmDepth3D.Y)) { int indexDepthPixels = j * this.DepthFrameWidth + i; rectDepth3D[rectSize++] = new PointDepth3D(i, j, depthPixels[indexDepthPixels].Depth); //Draw depth pixel according to different distance this.depthColor[indexColor + BLUE] = 255; this.depthColor[indexColor + GREEN] = 0; this.depthColor[indexColor + RED] = 0; this.depthColor[indexColor + AlPHA] = 0; if (depthPixels[indexDepthPixels].Depth >= currDepth - 100 && depthPixels[indexDepthPixels].Depth <= currDepth + 100) { this.depthColor[indexColor + BLUE] = 255; this.depthColor[indexColor + GREEN] = 255; this.depthColor[indexColor + RED] = 255; this.depthColor[indexColor + AlPHA] = 0; } } else { this.depthColor[indexColor + BLUE] = 0; this.depthColor[indexColor + GREEN] = 0; this.depthColor[indexColor + RED] = 0; this.depthColor[indexColor + AlPHA] = 0; } } } #region //for (int i = 0,depthColorIndex = 0; i < this.depthPixels.Length; i++, depthColorIndex += 4) //{ // if (pointRight.X >= (int)(i % this.sensor.DepthStream.FrameWidth) - 50 && // pointRight.X <= (int)(i % this.sensor.DepthStream.FrameWidth) + 50 && // pointRight.Y >= (int)(i / this.sensor.DepthStream.FrameWidth) - 40 && // pointRight.Y <= (int)(i / this.sensor.DepthStream.FrameWidth) + 60) // { // this.depthColor[depthColorIndex + BLUE] = 255; // this.depthColor[depthColorIndex + GREEN] = 0; // this.depthColor[depthColorIndex + RED] = 0; // this.depthColor[depthColorIndex + AlPHA] = 0; // if (depthPixels[i].Depth >= nearDepth - 100 && depthPixels[i].Depth <= nearDepth + 100) // { // this.depthColor[depthColorIndex + BLUE] = 255; // this.depthColor[depthColorIndex + GREEN] = 255; // this.depthColor[depthColorIndex + RED] = 255; // this.depthColor[depthColorIndex + AlPHA] = 0; // } // } // else // { // this.depthColor[depthColorIndex + BLUE] = 0; // this.depthColor[depthColorIndex + GREEN] = 0; // this.depthColor[depthColorIndex + RED] = 0; // this.depthColor[depthColorIndex + AlPHA] = 0; // } //} #endregion //Construct Hand instance for tracker, then do hand tracking if (rectSize == rectWidth * rectHeight) { detector.RightHand = new Hand(rectDepth3D, palmDepth3D, rectWidth, rectHeight); detector.DetectAndSmooth(timeStamp); //Fingers.Identify(this.Sketelon3DFingerTips,timeStamp); //Fingers.Identify2(this.Sketelon3DFingerTips,rightHand, rightWrist); Fingers.Identify3(this.Sketelon3DFingerTips,timeStamp); timeStamp = (++timeStamp) % KinectUtil.LOOP_TIMES; foreach (var element in detector.Depth3DFingerTips) { int k = (element.Y * DepthFrameWidth + element.X) * 4; for (int i = k - 20; i < k + 20; i += 4) { depthColor[i + BLUE] = 0; depthColor[i + GREEN] = 0; depthColor[i + RED] = 255; } } } this.depthBitmap.WritePixels( new Int32Rect(0, 0, this.depthBitmap.PixelWidth, this.depthBitmap.PixelHeight), this.depthColor, this.depthBitmap.PixelWidth * sizeof(int), 0); readyEvent.afterDepthReady(); } } }
public Point2D GetPoint2Position(FingerType id) { if (this[id].TrackingState == FingerTrackingState.Tracked) { CoordinateMapperPlus mapper = new CoordinateMapperPlus(this.sensor); return mapper.MapSkeletonPointToColorPoint(this[id].Position, this.sensor.ColorStream.Format); } return new Point2D(); }
/// <summary> /// Call Core Track Algo and Smooth Algo to Track and Smooth FingerTips /// </summary> /// <param name="timeStamp"></param> public void DetectAndSmooth(int timeStamp) { if(null == sensor) return; RightHand.FingerDetect(0); CoordinateMapperPlus mapper = new CoordinateMapperPlus (this.sensor); List<PointSkeleton3D> currFingerTips = mapper.MapDepthPointsToSketelonPoints(sensor.DepthStream.Format, RightHand.FingerTips); smoother.Smooth(currFingerTips,timeStamp); }