private void DepthReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e) { if (recording) { //record each gesture frame SaveBitmap(gesturepath + "\\" + counter.ToString() + ".png"); ++counter; //reset timer if 3 seconds reached if (timer.Elapsed.TotalSeconds > 3) { timer.Reset(); recording = false; counter = 0; //kill Myo and Leap processes var myo = Process.GetProcesses().Where(pr => (pr.ProcessName == "MyoDataCapture") || (pr.ProcessName == "python")); foreach (var process in myo) { process.Kill(); } } } //update gesture information else { if (gestureindex < gestures.Count) { textBox1.Text = "Next gesture: " + gestures[gestureindex]; gestureImage.Source = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\images\\" + gestures[gestureindex] + ".gif")); } else { textBox1.Text = "Completed round!"; gestureImage.Source = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\images\\blank.png")); } } canvas.Children.Clear(); using (DepthFrame frame = e.FrameReference.AcquireFrame()) { if (frame != null) { // 2) Update the HandsController using the array (or pointer) of the depth depth data, and the tracked body. using (KinectBuffer buffer = frame.LockImageBuffer()) { _handsController.Update(buffer.UnderlyingBuffer, _body); } } } }
// every frame private void DepthReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e) { canvas.Children.Clear(); using (DepthFrame frame = e.FrameReference.AcquireFrame()) { if (frame != null) { using (KinectBuffer buffer = frame.LockImageBuffer()) { _handsController.Update(buffer.UnderlyingBuffer, _body); } } } }
private void DepthReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e) { canvas.Children.Clear(); using (DepthFrame frame = e.FrameReference.AcquireFrame()) { if (frame != null) { // 2) Update the HandsController using the array (or pointer) of the depth depth data, and the tracked body. using (KinectBuffer buffer = frame.LockImageBuffer()) { _handsController.Update(buffer.UnderlyingBuffer, _body); } } } }
/// <summary> /// Directly accesses the underlying image buffer of the DepthFrame to /// create a displayable bitmap. /// This function requires the /unsafe compiler option as we make use of direct /// access to the native memory pointed to by the depthFrameData pointer. /// </summary> /// <param name="depthFrameData">Pointer to the DepthFrame image data</param> /// <param name="depthFrameDataSize">Size of the DepthFrame image data</param> /// <param name="minDepth">The minimum reliable depth value for the frame</param> /// <param name="maxDepth">The maximum reliable depth value for the frame</param> private unsafe void ProcessDepthFrameData(IntPtr depthFrameData, uint depthFrameDataSize) { // depth frame data is a 16 bit value ushort *frameData = (ushort *)depthFrameData; flaghand = (flaghand + 1) % 20; if (flaghand % 20 == 0) { if (body != null && body.IsTracked) { // Find the right hand state if (body.HandRightState == HandState.Open) { text.Text = "৫"; } else { _handsController.Update(depthFrameData, body); } } } // convert depth to a visual representation for (int i = 0; i < (int)(depthFrameDataSize / this.depthFrameDescription.BytesPerPixel); ++i) { // Get the depth for this pixel var depth = frameData[i]; var y = i / (int)this.depthFrameDescription.Width; //var cmin = Length(x, y, minDepth); //var cmax = Length(x, y, maxDepth); // To convert to a byte, we're mapping the depth value to the byte range. // Values outside the reliable depth range are mapped to 0 (black). this.depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? 255 : 0); if (y >= spMidPosition.Y) { this.depthPixels[i] = 0; } } }
private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var frame = e.FrameReference.AcquireFrame(); #region colorFrame using (ColorFrame colorFrame = frame.ColorFrameReference.AcquireFrame()) { if (colorFrame != null) { FrameDescription frameDescription = colorFrame.FrameDescription; using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) { WriteableBitmap.Lock(); if ((frameDescription.Width == WriteableBitmap.PixelWidth) && (frameDescription.Height == WriteableBitmap.PixelHeight)) { colorFrame.CopyConvertedFrameDataToIntPtr(WriteableBitmap.BackBuffer, (uint)(frameDescription.Width * frameDescription.Height * 4), ColorImageFormat.Bgra); WriteableBitmap.AddDirtyRect(new Int32Rect(0, 0, WriteableBitmap.PixelWidth, WriteableBitmap.PixelHeight)); } WriteableBitmap.Unlock(); } } camera.Source = WriteableBitmap; } #endregion #region handTracking bool dataReceived = false; canvas.Children.Clear(); using (BodyFrame bodyFrame = frame.BodyFrameReference.AcquireFrame()) { if (bodyFrame != null) { if (bodies == null) { bodies = new Body[bodyFrame.BodyCount]; } bodyFrame.GetAndRefreshBodyData(bodies); dataReceived = true; } } if (dataReceived) { //body = bodies.Where(b => b.IsTracked).FirstOrDefault(); foreach (Body body in bodies) { if (body.IsTracked) { Dictionary <JointType, Joint> joints = new Dictionary <JointType, Joint>(); joints[JointType.ShoulderRight] = body.Joints[JointType.ShoulderRight]; joints[JointType.ElbowRight] = body.Joints[JointType.ElbowRight]; joints[JointType.WristRight] = body.Joints[JointType.WristRight]; joints[JointType.HandRight] = body.Joints[JointType.HandRight]; joints[JointType.ThumbRight] = body.Joints[JointType.ThumbRight]; joints[JointType.HandTipRight] = body.Joints[JointType.HandTipRight]; joints[JointType.ShoulderLeft] = body.Joints[JointType.ShoulderLeft]; joints[JointType.ElbowLeft] = body.Joints[JointType.ElbowLeft]; joints[JointType.WristLeft] = body.Joints[JointType.WristLeft]; joints[JointType.HandLeft] = body.Joints[JointType.HandLeft]; joints[JointType.ThumbLeft] = body.Joints[JointType.ThumbLeft]; joints[JointType.HandTipLeft] = body.Joints[JointType.HandTipLeft]; Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>(); foreach (JointType jointType in joints.Keys) { Point colorSpacePoint = Scale(joints[jointType], coordinateMapper); jointPoints[jointType] = new Point(colorSpacePoint.X, colorSpacePoint.Y); } if (position_idx == 1) { RecognizeStart(jointPoints); } DrawRec(canvas, jointPoints[JointType.HandLeft], jointPoints[JointType.ShoulderLeft]); DrawBody(joints, jointPoints, canvas); } } } #endregion #region fingerTracking using (DepthFrame depthFrame = frame.DepthFrameReference.AcquireFrame()) { if (depthFrame != null) { using (KinectBuffer kinectBuffer = depthFrame.LockImageBuffer()) { foreach (Body body in bodies) { handsController.Update(kinectBuffer.UnderlyingBuffer, body); } } } } #endregion }