/// <summary> /// Map PointDepth3D to PointSkeleton3D /// </summary> /// <param name="depthImageFormat"></param> /// <param name="pointDepth3D"></param> /// <returns></returns> public PointSkeleton3D MapDepthPointToSketelonPoint(DepthImageFormat depthImageFormat, PointDepth3D pointDepth3D) { DepthImagePoint point = new DepthImagePoint(); point.X = pointDepth3D.X; point.Y = pointDepth3D.Y; point.Depth = pointDepth3D.Depth; return new PointSkeleton3D(mapper.MapDepthPointToSkeletonPoint(depthImageFormat, point)); }
public Hand(PointDepth3D[] pixel3D, PointDepth3D trackPalm, int RWidth = 100, int RHeight = 100) { this.pixelDepth3D = pixel3D; this.kinectTrackPalm = trackPalm; this.kinectPalmDetph = trackPalm.Depth; this.rectWidth = RWidth; this.rectHeight = RHeight; contourPixels = new List<Point2D>(); interiorPixels = new List<Point2D>(); }
/// <summary> /// Depth Slice, generate the valid matrix /// </summary> /// <param name="pixel3D"></param> /// <param name="Depth"></param> /// <returns>bool[][] valid</returns> private bool[][] generateValidMatrix(PointDepth3D[] pixel3D, float Depth, int dalitionErosionMask) { bool[][] valid = new bool[rectWidth][]; for (int i = 0; i < valid.Length; i++) { valid[i] = new bool[rectHeight]; } for (int i = 0; i < valid.Length; i++) { for (int j = 0; j < valid[i].Length; j++) { int index = j * rectWidth + i; if (pixel3D[index].Depth <= Depth + 100 && pixel3D[index].Depth >= Depth - 100) { valid[i][j] = true; } else { valid[i][j] = false; } } } //Noisy Reduction if (dalitionErosionMask > 0) { valid = Denoise.Dilation(valid, dalitionErosionMask); valid = Denoise.Erosion(valid, dalitionErosionMask); } // Mark as not valid the borders of the matrix to improve the efficiency in some methods int m; // First row for (int j = 0; j < valid[0].Length; ++j) valid[0][j] = false; // Last row m = valid.Length - 1; for (int j = 0; j < valid[0].Length; ++j) valid[m][j] = false; // First column for (int i = 0; i < valid.Length; ++i) valid[i][0] = false; // Last column m = valid[0].Length - 1; for (int i = 0; i < valid.Length; ++i) valid[i][m] = false; return valid; }
public PointDepth3D(PointDepth3D point) { this.X = point.X; this.Y = point.Y; this.Depth = point.Depth; }
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); } } }