/// <summary> /// Kinect が複数種類のフレームを取得したとき実行されるメソッド(イベントハンドラ)。 /// </summary> /// <param name="sender"> /// イベントを通知したオブジェクト。ここでは Kinect になる。 /// </param> /// <param name="e"> /// イベントの発生時に渡されるデータ。 /// </param> void MultiSourceFrameReader_MultiSourceFrameArrived (object sender, MultiSourceFrameArrivedEventArgs e) { MultiSourceFrame frames = this.multiSourceFrameReader.AcquireLatestFrame(); if (frames == null) { return; } DepthFrame depthFrame = frames.DepthFrameReference.AcquireFrame(); if (depthFrame == null) { return; } BodyIndexFrame bodyIndexFrame = frames.BodyIndexFrameReference.AcquireFrame(); if (bodyIndexFrame == null) { depthFrame.Dispose(); return; } this.canvas.Background = new ImageBrush (GetBitmapSource(depthFrame, bodyIndexFrame, this.depthFrameDescription, this.bodyIndexFrameDescription)); depthFrame.Dispose(); bodyIndexFrame.Dispose(); }
private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var mSourceFrame = e.FrameReference.AcquireFrame(); // If the Frame has expired by the time we process this event, return. if (mSourceFrame == null) { return; } DepthFrame depthFrame = null; ColorFrame colorFrame = mSourceFrame.ColorFrameReference.AcquireFrame(); using (colorFrame) { if (colorFrame != null) { cameraIMG.Source = KinectExtensions.ToBitmap(colorFrame); colorFrame.CopyConvertedFrameDataToArray(lastNotNullColorData, ColorImageFormat.Bgra); (Parent as MainWindow).PlaygroundWindow.ShowImage(cameraIMG.Source); } try { depthFrame = mSourceFrame.DepthFrameReference.AcquireFrame(); if (depthFrame != null) { // Access the depth frame data directly via LockImageBuffer to avoid making a copy using (KinectBuffer depthFrameData = depthFrame.LockImageBuffer()) { kinectSensor.CoordinateMapper.MapColorFrameToDepthSpaceUsingIntPtr( depthFrameData.UnderlyingBuffer, depthFrameData.Size, colorMappedToDepthSpace); depthFrame.CopyFrameDataToArray(lastNotNullDepthData); } // We're done with the DepthFrame depthFrame.Dispose(); depthFrame = null; } } finally { if (depthFrame != null) { depthFrame.Dispose(); } if (colorFrame != null) { colorFrame.Dispose(); } } } }
protected virtual void Dispose(bool disposing) { if (!disposed) { // Dispose managed resource. if (disposing) { } // Release unmanaged resources. If disposing is false, // only the following code is executed. if (ColorFrame != null) { ColorFrame.Dispose(); ColorFrame = null; } if (DepthFrame != null) { DepthFrame.Dispose(); DepthFrame = null; } if (SkeletonFrame != null) { SkeletonFrame.Dispose(); SkeletonFrame = null; } } disposed = true; }
private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { ColorFrame colorFrame = null; DepthFrame depthFrame = null; MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame(); if (multiSourceFrame == null) { return; } colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame(); depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame(); if (colorFrame == null | depthFrame == null) { return; } this.camera.Source = this.msi.FrameTreatment(colorFrame, depthFrame, this.mode.ToString()); if (colorFrame != null) { colorFrame.Dispose(); } if (depthFrame != null) { depthFrame.Dispose(); } }
/// <summary> /// Kinect が複数種類のフレームを取得したとき実行されるメソッド(イベントハンドラ)。 /// </summary> /// <param name="sender"> /// イベントを通知したオブジェクト。ここでは Kinect になる。 /// </param> /// <param name="e"> /// イベントの発生時に渡されるデータ。 /// </param> void MultiSourceFrameReader_MultiSourceFrameArrived (object sender, MultiSourceFrameArrivedEventArgs e) { MultiSourceFrame frames = this.multiSourceFrameReader.AcquireLatestFrame(); if (frames == null) { return; } ColorFrame colorFrame = frames.ColorFrameReference.AcquireFrame(); if (colorFrame == null) { return; } DepthFrame depthFrame = frames.DepthFrameReference.AcquireFrame(); if (depthFrame == null) { //忘れないように注意する。 colorFrame.Dispose(); return; } this.colorCanvas.Background = new ImageBrush(GetBitmapSource(colorFrame, colorFrameDescription)); this.depthCanvas.Background = new ImageBrush(GetBitmapSource(depthFrame, depthFrameDescription)); colorFrame.Dispose(); depthFrame.Dispose(); }
private void processDepthFrame(DepthFrame depthFrame) { if (depthFrame != null) { Box dimensions = Box.With(depthFrame.FrameDescription.Width, depthFrame.FrameDescription.Height); frameResolutions[SourceType.DEPTH] = Box.With(depthFrame.FrameDescription.Width, depthFrame.FrameDescription.Height); framePixelFormats[SourceType.DEPTH] = PixelFormats.Gray16; min = depthFrame.DepthMinReliableDistance; max = depthFrame.DepthMaxReliableDistance; if (depthPixels == null) { depthPixels = new byte[dimensions.Area * (39 / 8)]; } UInt16[] tempPixels = new UInt16[dimensions.Area]; depthFrame.CopyFrameDataToArray(tempPixels); int colorIndex = 0; for (int index = 0; index < tempPixels.Length; ++index) { UInt16 pixel = tempPixels[index]; byte intensity = (byte)(pixel); /// ((pixel - min) % (max - min));//(byte)((pixel >= minDepth && pixel <= maxDepth) ? pixel : 0); //depthPixels[colorIndex++] = intensity; colorIndex++; depthPixels[colorIndex++] = intensity; } depthFrame?.Dispose(); } }
// Event handler for the DepthSensorUpdate event private void onDepthSensorUpdate(DepthFrame depthFrame) { if (_depthFrame != null) { _depthFrame.Dispose(); } _depthFrame = (DepthFrame)depthFrame.Clone(); }
/// <summary> /// Kinect が複数種類のフレームを取得したとき実行されるメソッド(イベントハンドラ)。 /// </summary> /// <param name="sender"> /// イベントを通知したオブジェクト。ここでは Kinect になる。 /// </param> /// <param name="e"> /// イベントの発生時に渡されるデータ。 /// </param> void MultiSourceFrameReader_MultiSourceFrameArrived (object sender, MultiSourceFrameArrivedEventArgs e) { MultiSourceFrame frames = this.multiSourceFrameReader.AcquireLatestFrame(); if (frames == null) { return; } ColorFrame colorFrame = frames.ColorFrameReference.AcquireFrame(); if (colorFrame == null) { return; } DepthFrame depthFrame = frames.DepthFrameReference.AcquireFrame(); if (depthFrame == null) { colorFrame.Dispose(); return; } BodyIndexFrame bodyIndexFrame = frames.BodyIndexFrameReference.AcquireFrame(); if (bodyIndexFrame == null) { colorFrame.Dispose(); depthFrame.Dispose(); return; } this.colorCanvas.Background = new ImageBrush(GetColorImage(colorFrame)); this.userMaskCanvas.Background = new ImageBrush (GetUserMaskImage(colorFrame, depthFrame, bodyIndexFrame)); colorFrame.Dispose(); depthFrame.Dispose(); bodyIndexFrame.Dispose(); }
void updateDepth(DepthFrame depthFrame) { if (depthFrame != null) { depthFrame.CopyFrameDataToArray(depthData); depthFrame.Dispose(); depthFrame = null; } }
/// <summary> /// Display the depth data when a frame is received /// </summary> private void DepthReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e) { DepthFrameReference frameReference = e.FrameReference; DepthFrame frame = frameReference.AcquireFrame(); if (frame != null) { Dispatcher.Invoke(() => { depthRenderer.RenderDepthFrame(e); frame.Dispose(); }); } }
/// <summary> /// Kinect が深度情報を取得したとき実行されるメソッド(イベントハンドラ)。 /// </summary> /// <param name="sender"> /// イベントを通知したオブジェクト。ここでは Kinect になる。 /// </param> /// <param name="e"> /// イベントの発生時に渡されるデータ。ここでは深度画像の情報が含まれる。 /// </param> void DepthFrameReader_FrameArrived(object sender, DepthFrameArrivedEventArgs e) { DepthFrame depthFrame = e.FrameReference.AcquireFrame(); if (depthFrame == null) { return; } //深度情報を確保する領域(バッファ)を用意して取得する。 ushort[] depths = new ushort[this.depthFrameDescription.Width * this.depthFrameDescription.Height]; depthFrame.CopyFrameDataToArray(depths); //深度情報を画像(深度画像)として可視化するために、画像を構成する配列を用意する。 //"高さ * 幅 * 1画素あたりのデータ量(Bgra32 なら 4byte)" byte[] depthColors = new byte[this.depthFrameDescription.Width * this.depthFrameDescription.Height * 4]; //深度情報を利用して、画像の各画素の色を決定する。 for (int i = 0; i < depths.Length; i += 1) { ushort depth = depths[i]; byte grayColor = (byte)(depth % 255); //深度画像の画素を指すインデックス。 int depthColorsIndex = i * 4; //BGRA の順にデータを入れる depthColors[depthColorsIndex] = grayColor; //B depthColors[depthColorsIndex + 1] = grayColor; //G depthColors[depthColorsIndex + 2] = grayColor; //R depthColors[depthColorsIndex + 3] = 255; //A } //画素情報をビットマップとして扱う。 //正しいストライドの大きさを算出すること。 BitmapSource bitmapSource = BitmapSource.Create(this.depthFrameDescription.Width, this.depthFrameDescription.Height, 96, 96, PixelFormats.Bgra32, null, depthColors, this.depthFrameDescription.Width * 4); //キャンバスに表示する。 this.canvas.Background = new ImageBrush(bitmapSource); //取得したフレームを破棄する。 depthFrame.Dispose(); }
// ************************************************************************************************************************* bool RefreshFrame(MultiSourceFrame _frame) //updateframe to our array { if (_frame == null) { return(false); } try{ bodyframe = _frame.BodyFrameReference.AcquireFrame(); depthFrame = _frame.DepthFrameReference.AcquireFrame(); colorFrame = _frame.ColorFrameReference.AcquireFrame(); bodyIndexFrame = _frame.BodyIndexFrameReference.AcquireFrame(); // If any frame has expired by the time we process this event, return. // The "finally" statement will Dispose any that are not null. if ((depthFrame == null) || (colorFrame == null) || (bodyIndexFrame == null || bodyframe == null)) { return(false); } else { if (BodyData == null) { BodyData = new Body[_Sensor.BodyFrameSource.BodyCount]; } // update all the array and points bodyframe.GetAndRefreshBodyData(BodyData); colorFrame.CopyConvertedFrameDataToArray(colorData, ColorImageFormat.Rgba); depthFrame.CopyFrameDataToArray(depthData); bodyIndexFrame.CopyFrameDataToArray(bodyIndexData); // update all the array and points _frame = null; return(true); } } finally { if (bodyframe != null) { bodyframe.Dispose(); } if (depthFrame != null) { depthFrame.Dispose(); } if (colorFrame != null) { colorFrame.Dispose(); } if (bodyIndexFrame != null) { bodyIndexFrame.Dispose(); } } }
public void Update() { DepthFrame frame = reader.AcquireLatestFrame(); if (frame != null) { frame.CopyFrameDataToArray(Data); frame.Dispose(); frame = null; } }
/// <summary> /// Handles the depth/color/body index frame data arriving from the sensor /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { DepthFrame depthFrame = null; ColorFrame colorFrame = null; BodyIndexFrame bodyIndexFrame = null; BodyFrame bodyFrame = null; _isBitmapLocked = false; var multiSourceFrame = e.FrameReference.AcquireFrame(); // If the Frame has expired by the time we process this event, return. if (multiSourceFrame == null) { return; } // We use a try/finally to ensure that we clean up before we exit the function. // This includes calling Dispose on any Frame objects that we may have and unlocking the bitmap back buffer. try { depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame(); colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame(); bodyIndexFrame = multiSourceFrame.BodyIndexFrameReference.AcquireFrame(); bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame(); // If any frame has expired by the time we process this event, return. // The "finally" statement will Dispose any that are not null. if ((depthFrame == null) || (colorFrame == null) || (bodyIndexFrame == null) || bodyFrame == null) { return; } ProcessBackgroundOld(depthFrame, colorFrame, bodyIndexFrame); ProcessBody(bodyFrame, false); } finally { if (_isBitmapLocked) { _bitmap.Unlock(); } depthFrame?.Dispose(); colorFrame?.Dispose(); bodyIndexFrame?.Dispose(); bodyFrame?.Dispose(); } }
// Token: 0x060029FC RID: 10748 RVA: 0x000D5DB8 File Offset: 0x000D41B8 private void Update() { if (this._Reader != null) { DepthFrame depthFrame = this._Reader.AcquireLatestFrame(); if (depthFrame != null) { depthFrame.CopyFrameDataToArray(this._Data); depthFrame.Dispose(); } } }
void Update() { if (depthReader != null) { using (DepthFrame frame = depthReader.AcquireLatestFrame()) { if (frame != null) { frame.CopyFrameDataToArray(Depth); frame.Dispose(); } } } }
/// <summary> /// Store depth image /// </summary> /// <param name="depthFrame">depth frame to be stored</param> /// <param name="frameNumber">frame number</param> public static void Handle_DepthFrame(DepthFrame depthFrame, String frameNumber) { using (Microsoft.Kinect.KinectBuffer depthBuffer = depthFrame.LockImageBuffer()) { BitmapSource bitmapSource = BitmapSource.Create(depthWidth, depthHeight, 96.0, 96.0, PixelFormats.Gray16, null, depthBuffer.UnderlyingBuffer, (int)depthBuffer.Size, depthWidth << 1); String depthPath = FramesAndPaths.GetImageFilePath(FramesAndPaths.FileType.DepthImage, frameNumber); bitmapSource.Save(depthPath + ".png", ImageFormat.Png); } // Release depthFrame depthFrame.Dispose(); }
//深度情報 void DepthFrame_Arrived(object sender, DepthFrameArrivedEventArgs e) { DepthFrame depthFrame = e.FrameReference.AcquireFrame(); //フレームがなければ終了、あれば格納 if (depthFrame == null) { return; } int[] depthBitdata = new int[depthBuffer.Length]; depthFrame.CopyFrameDataToArray(this.depthBuffer); this.package.K_DdepthBuffer = this.depthBuffer; //破棄 depthFrame.Dispose(); }
/// <summary> /// Handles depth/color/body index frame data arriving from sensor /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private static void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { DepthFrame depthFrame = null; BodyFrame bodyFrame = null; MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame(); // if the Frame has expired by the time we process this event, return. if (multiSourceFrame == null) { return; } // try/finally to ensure that we clean up before we exit the function. try { depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame(); bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame(); if ((depthFrame == null) || (bodyFrame == null)) { return; } // frame data processing MapDepthFrame(depthFrame); UpdateBodyData(bodyFrame); DrawController.DrawPoints(); DrawController.DrawMap(); DrawController.DrawJoints(); DrawController.UpdateGestureResult(); } finally { if (depthFrame != null) { depthFrame.Dispose(); } if (bodyFrame != null) { bodyFrame.Dispose(); } } }
/// <summary> /// Update Kinect depth map /// </summary> private void UpdateDepthData() { if (_isInitialized) { DepthFrame depthFrame = _depthReader.AcquireLatestFrame(); if (depthFrame != null) { depthFrame.CopyFrameDataToArray(_depthData); depthFrame.Dispose(); depthFrame = null; } } }
void HandleOnDepthSensorUpdateEvent(nuitrack.DepthFrame frame) { if (DepthFrame != null) { DepthFrame.Dispose(); } DepthFrame = (nuitrack.DepthFrame)frame.Clone(); try { onDepthUpdate?.Invoke(DepthFrame); } catch (Exception ex) { Debug.LogException(ex); } }
public void UpdateDepthFrame(DepthFrame frame) { if (frame == null) { return; } ushort[] depthData = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels]; frame.CopyFrameDataToArray(depthData); frame.Dispose(); frame = null; int Y = (int)rightHandPos.Y; int X = (int)rightHandPos.X; rightHandDepth = depthData [X + Y * depthFrameWidth]; }
void multiFrameReader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { MultiSourceFrameReference frameReference = e.FrameReference; MultiSourceFrame multiSourceFrame = null; DepthFrame depthFrame = null; ColorFrame colorFrame = null; try { multiSourceFrame = frameReference.AcquireFrame(); if (multiSourceFrame == null) { return; } depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame(); colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame(); if (depthFrame == null || colorFrame == null) { return; } depthFrame.CopyFrameDataToArray(depthImagePixels); colorFrame.CopyConvertedFrameDataToArray(colorImagePixels, ColorImageFormat.Bgra); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { if (depthFrame != null) { depthFrame.Dispose(); depthFrame = null; } if (colorFrame != null) { colorFrame.Dispose(); colorFrame = null; } if (multiSourceFrame != null) { multiSourceFrame = null; } } UpdateFusionFrame(); DrawFusionFrame(); }
/// <summary> /// Processes and sends data /// </summary> /// <param name="colorFrame">Color frame</param> /// <param name="depthFrame">Depth frame</param> private void FindAName(ColorFrame colorFrame, DepthFrame depthFrame) { // Arrays initialization & copy data, then dispose frames // Color int colorWidth = colorFrame.FrameDescription.Width; int colorHeight = colorFrame.FrameDescription.Height; this.colorPixelsSending = new Byte[colorWidth * colorHeight * 2]; colorFrame.CopyRawFrameDataToArray(this.colorPixelsSending); PixelFormat format = PixelFormats.Bgr32; this.colorPixels = new Byte[colorWidth * colorHeight * ((format.BitsPerPixel + 7) / 8)]; colorFrame.CopyConvertedFrameDataToArray(this.colorPixels, ColorImageFormat.Bgra); colorFrame.Dispose(); // Sending color data this.SendingColorData(); // Depth int depthWidth = depthFrame.FrameDescription.Width; int depthHeight = depthFrame.FrameDescription.Height; ushort minDepth = depthFrame.DepthMinReliableDistance; ushort maxDepth = depthFrame.DepthMaxReliableDistance; this.depthPixels = new byte[depthWidth * depthHeight]; this.depthPixelData = new ushort[depthWidth * depthHeight]; depthFrame.CopyFrameDataToArray(this.depthPixelData); depthFrame.Dispose(); this.ProcessDepthFrameData(minDepth, maxDepth); // Mapping float factor = 0.2547f; int smallWidth = (int)(colorWidth * factor); int smallHeight = (int)(colorHeight * factor); this.mappedPixels = new Byte[smallWidth * smallHeight]; this.mask = Enumerable.Repeat((Byte)1, smallWidth * smallHeight).ToArray(); this.colorPoints = new ColorSpacePoint[depthWidth * depthHeight]; // Mapping both rgb & depth and then sending this mapping & the corresponding mask this.ProcessMapping(factor, smallWidth, smallHeight); this.SendingMapping(); }
void updateKinect() { if (!kinectIsInit || !sensor.IsOpen || depthReader == null) { Debug.Log("Kinect is not init or open"); initKinect(); return; } DepthFrame depthFrame = depthReader.AcquireLatestFrame(); if (depthFrame != null) { depthFrame.CopyFrameDataToArray(frameData); mapper.MapDepthFrameToCameraSpace(frameData, cameraPoints); depthFrame.Dispose(); for (int i = 0; i < frameData.Length; ++i) { depthTexData[3 * i + 0] = (byte)(frameData[i] * 1f / 20); depthTexData[3 * i + 1] = (byte)(frameData[i] * 1f / 20); depthTexData[3 * i + 2] = (byte)(frameData[i] * 1f / 20); } depthTex.LoadRawTextureData(depthTexData); depthTex.Apply(); } ColorFrame colorFrame = colorReader.AcquireLatestFrame(); if (colorFrame != null) { colorFrame.CopyConvertedFrameDataToArray(colorData, ColorImageFormat.Rgba); colorFrame.Dispose(); colorTex.LoadRawTextureData(colorData); colorTex.Apply(); mapper.MapColorFrameToCameraSpace(frameData, colorPoints); } }
private void MultiFrameReader_FrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var frame = e.FrameReference.AcquireFrame(); if ((this.whichFrames & FrameSourceTypes.Body) == FrameSourceTypes.Body) { this.BodyFrameReader_FrameArrived(frame.BodyFrameReference); } Shared <Image> colorImage = null; if ((this.whichFrames & FrameSourceTypes.Color) == FrameSourceTypes.Color) { this.ColorFrameReader_FrameArrived(frame.ColorFrameReference, out colorImage); } DepthFrame depthFrame = null; if ((this.whichFrames & FrameSourceTypes.Depth) == FrameSourceTypes.Depth) { depthFrame = frame.DepthFrameReference.AcquireFrame(); this.DepthFrameReader_FrameArrived(depthFrame); } if (depthFrame != null && colorImage != null) { this.MapColorToDepth(depthFrame, colorImage); } colorImage?.Dispose(); depthFrame?.Dispose(); if ((this.whichFrames & FrameSourceTypes.Infrared) == FrameSourceTypes.Infrared) { this.InfraredFrameReader_FrameArrived(frame.InfraredFrameReference); } if ((this.whichFrames & FrameSourceTypes.LongExposureInfrared) == FrameSourceTypes.LongExposureInfrared) { this.LongExposureInfraredFrameReader_FrameArrived(frame.LongExposureInfraredFrameReference); } }
void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { // Get a reference to the multi-frame var reference = e.FrameReference.AcquireFrame(); ColorFrame colorFrame = null; BodyIndexFrame biFrame = null; DepthFrame depthFrame = null; try { rightImageFrameCount++; if (rightImageFrameCount == 1) { colorFrame = reference.ColorFrameReference.AcquireFrame(); if (colorFrame != null) { ColorSection(colorFrame); } depthFrame = reference.DepthFrameReference.AcquireFrame(); if (depthFrame != null) { //DepthSection(depthFrame); GetRightImage(depthFrame, colorFrame); } rightImageFrameCount = 0; } } finally { if (colorFrame != null) { colorFrame.Dispose(); } if (depthFrame != null) { depthFrame.Dispose(); } } }
void ProcessFrame(DepthFrame frame) { if (frame != null) { if (Monitor.TryEnter(_DataLock, 5)) { try { frame.CopyFrameDataToArray(_Data); newData = true; } finally { Monitor.Exit(_DataLock); } } frame.Dispose(); frame = null; } }
//深度情報取得 void DepthFrame_Arrived(object sender, DepthFrameArrivedEventArgs e) { try { DepthFrame depthFrame = e.FrameReference.AcquireFrame(); //フレームがなければ終了、あれば格納 if (depthFrame == null) { return; } int[] depthBitdata = new int[depthBuffer.Length]; depthFrame.CopyFrameDataToArray(this.depthBuffer); //破棄 depthFrame.Dispose(); } catch { this.ErrorPoint(System.Reflection.MethodBase.GetCurrentMethod().ToString()); } }
void Update() { if (m_pMultiSourceFrameReader == null) { return; } MultiSourceFrame pMultiSourceFrame = m_pMultiSourceFrameReader.AcquireLatestFrame(); if (pMultiSourceFrame != null) { frameCount++; using (DepthFrame pDepthFrame = pMultiSourceFrame.DepthFrameReference.AcquireFrame()) { using (ColorFrame pColorFrame = pMultiSourceFrame.ColorFrameReference.AcquireFrame()) { // Get Depth Frame Data if (pDepthFrame != null) { GCHandle pDepthData = GCHandle.Alloc(pDepthBuffer, GCHandleType.Pinned); pDepthFrame.CopyFrameDataToIntPtr(pDepthData.AddrOfPinnedObject(), (uint)pDepthBuffer.Length * sizeof(ushort)); pDepthData.Free(); pDepthFrame.Dispose(); } // Get Color Frame Data if (pColorFrame != null) { GCHandle pColorData = GCHandle.Alloc(pColorBuffer, GCHandleType.Pinned); pColorFrame.CopyConvertedFrameDataToIntPtr(pColorData.AddrOfPinnedObject(), (uint)pColorBuffer.Length, ColorImageFormat.Rgba); pColorData.Free(); pColorFrame.Dispose(); } ProcessFrame(); } } } }
void GreenScreenMappingDepthToColorSplats(ref DepthFrame depthFrame, ref ColorFrame colorFrame, ref BodyIndexFrame bodyIndexFrame, int depthWidth, int depthHeight, int colorWidth, int colorHeight) { m_stopwatch.Restart(); using (KinectBuffer depthFrameData = depthFrame.LockImageBuffer()) { // Need to know the color space point for each depth space point, but this is much less data // and much faster to compute than mapping the other way m_coordinateMapper.MapDepthFrameToColorSpaceUsingIntPtr( depthFrameData.UnderlyingBuffer, depthFrameData.Size, m_depthToColorSpacePoints); } m_depthMapTimer.Update(m_stopwatch.ElapsedMilliseconds); m_stopwatch.Restart(); // We're done with the DepthFrame depthFrame.Dispose(); depthFrame = null; lock (m_displayPixels) { // [KinectThread] avoid racing display buffer refresh with render (can cause missing images) // have to clear the display pixels so we can copy only the BGRA image of the player(s) Array.Clear(m_displayPixels, 0, m_displayPixels.Length); unsafe { fixed (byte* colorFrameDataPtr = &m_colorFrameData[0]) { colorFrame.CopyConvertedFrameDataToIntPtr(new IntPtr(colorFrameDataPtr), (uint)m_colorFrameData.Length, ColorImageFormat.Bgra); } } // done with the colorFrame colorFrame.Dispose(); colorFrame = null; m_colorCopyTimer.Update(m_stopwatch.ElapsedMilliseconds); m_stopwatch.Restart(); // We'll access the body index data directly to avoid a copy using (KinectBuffer bodyIndexData = bodyIndexFrame.LockImageBuffer()) { unsafe { byte* bodyIndexDataPointer = (byte*)bodyIndexData.UnderlyingBuffer; uint bodyIndexDataLength = bodyIndexData.Size; int colorMappedToDepthPointCount = m_colorToDepthSpacePoints.Length; fixed (ColorSpacePoint* depthMappedToColorPointsPointer = m_depthToColorSpacePoints) { fixed (byte* bitmapPixelsBytePointer = &m_displayPixels[0]) { fixed (byte* sourcePixelsBytePointer = &m_colorFrameData[0]) { uint* bitmapPixelsPointer = (uint*)bitmapPixelsBytePointer; uint* sourcePixelsPointer = (uint*)sourcePixelsBytePointer; // We don't go all the way to the edge of the depth buffer, to eliminate a chance // that a splat will go outside the edge of the color buffer when mapped to color // space. In the x direction this will never happen anyway since the depth FOV // is so much narrower than the color FOV. const int Margin = 2; for (int y = Margin; y < depthHeight - Margin; y++) { for (int x = 0; x < depthWidth; x++) { // Scan forwards until we find a non-0xff value in the body index data. int depthIndex = y * depthWidth + x; if (bodyIndexDataPointer[depthIndex] != 0xff) { int depthIndex2 = depthIndex; // We found the beginning of a horizontal run of player pixels. // Scan to the end. int runWidth; for (runWidth = 1; runWidth + x < depthWidth; runWidth++) { depthIndex2++; if (bodyIndexDataPointer[depthIndex2] == 0xff) { break; } } // Now splat from (x, y) to (x + runWidth, y) float depthMappedToColorLeftX = depthMappedToColorPointsPointer[depthIndex].X; float depthMappedToColorLeftY = depthMappedToColorPointsPointer[depthIndex].Y; float depthMappedToColorRightX = depthMappedToColorPointsPointer[depthIndex2 - 1].X; float depthMappedToColorRightY = depthMappedToColorPointsPointer[depthIndex2 - 1].Y; // Now copy color pixels along that rectangle. const int splatHMargin = 2; // X margin of splat rectangle in color pixels const int splatVMargin = 3; // Y margin of splat rectangle in color pixels int minX = (int)Math.Min(depthMappedToColorLeftX, depthMappedToColorRightX) - splatHMargin; int minY = (int)Math.Min(depthMappedToColorLeftY, depthMappedToColorRightY) - splatVMargin; int maxX = (int)Math.Max(depthMappedToColorLeftX, depthMappedToColorRightX) + splatHMargin; int maxY = (int)Math.Max(depthMappedToColorLeftY, depthMappedToColorRightY) + splatVMargin; // Some edge of screen situations can result in color space points that are negative or otherwise // actually outside the color space coordinate range. Clamp(ref minX, colorWidth - 1); Clamp(ref minY, colorHeight - 1); Clamp(ref maxX, colorWidth - 1); Clamp(ref maxY, colorHeight - 1); for (int colorY = minY; colorY < maxY; colorY++) { int colorIndex = colorY * colorWidth + minX; for (int colorX = minX; colorX < maxX; colorX++) { bitmapPixelsPointer[colorIndex] = sourcePixelsPointer[colorIndex]; colorIndex++; } } x += runWidth; } } } } } } } } // Done with bodyIndexFrame bodyIndexFrame.Dispose(); bodyIndexFrame = null; } m_colorScanTimer.Update(m_stopwatch.ElapsedMilliseconds); m_stopwatch.Restart(); m_displayTexture.SetData(m_displayPixels); m_textureSetDataTimer.Update(m_stopwatch.ElapsedMilliseconds); m_stopwatch.Restart(); Spam.TopLine1 = string.Format("depth map: {0} msec; color copy: {1} msec; color scan: {2} msec; texture set: {3} msec", m_depthMapTimer.Average, m_colorCopyTimer.Average, m_colorScanTimer.Average, m_textureSetDataTimer.Average); }
public void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { var reference = e.FrameReference.AcquireFrame(); // Color colorFrame = reference.ColorFrameReference.AcquireFrame(); { if (colorFrame != null) { if (_mode == CameraMode.Color) { camera.Source = colorFrame.ToBitmap(); } } } // Depth depthFrame = reference.DepthFrameReference.AcquireFrame(); { if (depthFrame != null) { if (_mode == CameraMode.Depth) { cameraDepth.Source = depthFrame.ToBitmap(); } } } Ellipse ellipse1 = new Ellipse { Fill = Brushes.Green, Width = 30, Height = 30 }; Ellipse ellipse2 = new Ellipse { Fill = Brushes.Red, Width = 30, Height = 30 }; Ellipse ellipse3 = new Ellipse { Fill = Brushes.Green, Width = 30, Height = 30 }; Ellipse ellipse4 = new Ellipse { Fill = Brushes.Red, Width = 30, Height = 30 }; Ellipse ellipse5 = new Ellipse { Fill = Brushes.Green, Width = 30, Height = 30 }; Ellipse ellipse6 = new Ellipse { Fill = Brushes.Red, Width = 30, Height = 30 }; Ellipse ellipse7 = new Ellipse { Fill = Brushes.Green, Width = 30, Height = 30 }; Ellipse ellipse8 = new Ellipse { Fill = Brushes.Red, Width = 30, Height = 30 }; Ellipse ellipse9 = new Ellipse { Fill = Brushes.Green, Width = 30, Height = 30 }; Ellipse ellipse10 = new Ellipse { Fill = Brushes.Red, Width = 30, Height = 30 }; Ellipse ellipse11 = new Ellipse { Fill = Brushes.Green, Width = 30, Height = 30 }; Ellipse ellipse12 = new Ellipse { Fill = Brushes.Red, Width = 30, Height = 30 }; if (finishedCountdown) { if (_mode == CameraMode.Color) { camera.Visibility = Visibility.Visible; canvas.Visibility = Visibility.Visible; cameraDepth.Visibility = Visibility.Hidden; canvasDepth.Visibility = Visibility.Hidden; finishedCountdown = false; } if (_mode == CameraMode.Depth) { camera.Visibility = Visibility.Hidden; canvas.Visibility = Visibility.Hidden; cameraDepth.Visibility = Visibility.Visible; canvasDepth.Visibility = Visibility.Visible; finishedCountdown = false; } } // Body using (var frame = reference.BodyFrameReference.AcquireFrame()) { if (frame != null) { this.canvas.Children.Clear(); this.canvasDepth.Children.Clear(); _bodies = new Body[frame.BodyFrameSource.BodyCount]; frame.GetAndRefreshBodyData(_bodies); //int bodyIndex = 0; foreach (var body in _bodies) { //if (bodyIndex != 0) continue; //bodyIndex++; var cameraSpacePoint = new CameraSpacePoint(); DepthSpacePoint depthPointWristLeft = new DepthSpacePoint(); DepthSpacePoint depthPointWristRight = new DepthSpacePoint(); DepthSpacePoint depthPointHead = new DepthSpacePoint(); DepthSpacePoint depthPointSpineMid = new DepthSpacePoint(); DepthSpacePoint depthPointKneeLeft = new DepthSpacePoint(); DepthSpacePoint depthPointKneeRight = new DepthSpacePoint(); ColorSpacePoint colorPointWristLeft = new ColorSpacePoint(); ColorSpacePoint colorPointWristRight = new ColorSpacePoint(); ColorSpacePoint colorPointHead = new ColorSpacePoint(); ColorSpacePoint colorPointSpineMid = new ColorSpacePoint(); ColorSpacePoint colorPointKneeLeft = new ColorSpacePoint(); ColorSpacePoint colorPointKneeRight = new ColorSpacePoint(); if (body.IsTracked) { BodyStructure currentFrameBody = new BodyStructure(); var lines = new List<string>(); foreach (var joint in body.Joints.Values) { cameraSpacePoint.X = joint.Position.X;//(float)currentFrameBody.currentFrameBody[joint.JointType].X; cameraSpacePoint.Y = joint.Position.Y; //(float)currentFrameBody.currentFrameBody[joint.JointType].Y; cameraSpacePoint.Z = joint.Position.Z; //(float)currentFrameBody.currentFrameBody[joint.JointType].Z; if (PressSpaced && !escape && jointsOfInterest.Contains(joint.JointType)) { curNumOfFrames++; distanceSum[joint.JointType] += cameraSpacePoint.Z; meanDistanceToSensor[joint.JointType] = distanceSum[joint.JointType] / ( (curNumOfFrames/6) + 1); } else if(escape && movementVector != null && jointsOfInterest.Contains(joint.JointType)) { distanceScale[joint.JointType] = cameraSpacePoint.Z / meanDistanceToSensor[joint.JointType]; } var colorPoint = _sensor.CoordinateMapper.MapCameraPointToColorSpace(cameraSpacePoint); var depthPoint = _sensor.CoordinateMapper.MapCameraPointToDepthSpace(cameraSpacePoint); if (_mode == CameraMode.Depth) { /* Ellipse ellipseBlue = new Ellipse { Fill = Brushes.Blue, Width = 10, Height = 10 }; var xPos = depthPoint.X - ellipseBlue.Width / 2; var yPos = depthPoint.Y - ellipseBlue.Height / 2; if (xPos >= 0 && xPos < this.canvasDepth.ActualWidth && yPos >= 0 && yPos < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipseBlue, xPos); Canvas.SetTop(ellipseBlue, yPos); canvasDepth.Children.Add(ellipseBlue); } */ Extensions.DrawSkeleton(canvas, body, jointsOfInterest, _sensor); //currentFrameBody.currentFrameBody.Add(joint.JointType, new Point3D()); if (jointsOfInterest.Contains(joint.JointType)) { if (joint.JointType == JointType.HandLeft) depthPointWristLeft = depthPoint; else if (joint.JointType == JointType.HandRight) depthPointWristRight = depthPoint; else if (joint.JointType == JointType.Head) depthPointHead = depthPoint; else if (joint.JointType == JointType.SpineMid) depthPointSpineMid = depthPoint; else if (joint.JointType == JointType.KneeRight) depthPointKneeRight = depthPoint; else if (joint.JointType == JointType.KneeLeft) depthPointKneeLeft = depthPoint; currentFrameBody.currentFrameBody.Add(joint.JointType, new Point3D(depthPoint.X, depthPoint.Y, 0)); } } else { Ellipse ellipseBlue = new Ellipse { Fill = Brushes.Blue, Width = 10, Height = 10 }; var xPos = colorPoint.X - ellipseBlue.Width / 2; var yPos = colorPoint.Y - ellipseBlue.Height / 2; if (xPos >= 0 && xPos < this.canvas.ActualWidth && yPos >= 0 && yPos < this.canvas.ActualHeight) { Canvas.SetLeft(ellipseBlue, xPos); Canvas.SetTop(ellipseBlue, yPos); canvas.Children.Add(ellipseBlue); } Extensions.DrawSkeleton(canvas, body, jointsOfInterest, _sensor); //currentFrameBody.currentFrameBody.Add(joint.JointType, new Point3D()); if (jointsOfInterest.Contains(joint.JointType)) { if (joint.JointType == JointType.HandLeft) colorPointWristLeft = colorPoint; else if (joint.JointType == JointType.HandRight) colorPointWristRight = colorPoint; else if (joint.JointType == JointType.Head) colorPointHead = colorPoint; else if (joint.JointType == JointType.SpineMid) colorPointSpineMid = colorPoint; else if (joint.JointType == JointType.KneeRight) colorPointKneeRight = colorPoint; else if (joint.JointType == JointType.KneeLeft) colorPointKneeLeft = colorPoint; var pointCurJoint = new Point3D(colorPoint.X, colorPoint.Y, 0); this.dictAllMovementPositions[joint.JointType].Add(pointCurJoint); currentFrameBody.currentFrameBody.Add(joint.JointType, pointCurJoint); } } } /*TODO - null or empty Dictionary (.Count == 0)*/ // if (movementVector == null) if (PressSpaced && !escape) { if (movementVector != null && jointsChange) { movementVector.Clear(); } jointsChange = false; movementVector = record.GetMovementVectors(currentFrameBody); } //else if(movementVector != null) else if (escape && movementVector != null) { var curFrameResult = benchPress.ValidateCurrentSkeletonFrame(movementVector, currentFrameBody, distanceScale); var resultWristLeft = curFrameResult.BoneStates[JointType.HandLeft]; var resultWristRight = curFrameResult.BoneStates[JointType.HandRight]; Extensions.DrawSkeleton(canvas, body, jointsOfInterest, _sensor); if (recordVisualization) { recordVisualization = false; Color colorHandLeft = Color.FromArgb(255, 35, 63, 147); Color colorHandRight = Color.FromArgb(255, 0, 136, 170); Color colorHead = Color.FromArgb(255, 193, 84, 151); Color colorSpineMid = Color.FromArgb(255, 238, 198, 20); Color colorKneeLeft = Color.FromArgb(255, 116, 81, 67); Color colorKneeRight = Color.FromArgb(255, 94, 58, 106); foreach (var joy in this.dictAllMovementPositions) { Color fillColor = Color.FromArgb(255, 255, 255, 255); switch (joy.Key) { case JointType.HandLeft: fillColor = colorHandLeft; break; case JointType.HandRight: fillColor = colorHandRight; break; case JointType.Head: fillColor = colorHead; break; case JointType.SpineMid: fillColor = colorSpineMid; break; case JointType.KneeLeft: fillColor = colorKneeLeft; break; case JointType.KneeRight: fillColor = colorKneeRight; break; } foreach (var point in joy.Value) { float opacityFactor = joy.Value.Count / 255 ; if (opacityFactor == 0.0f) opacityFactor = 1.0f; int alpha = (int)opacityFactor * (joy.Value.IndexOf(point) + 1); fillColor = SetTransparency(alpha, fillColor); Brush fill = new SolidColorBrush(fillColor); Ellipse newEllipse = new Ellipse { Fill = fill, Width = 20, Height = 20 }; var xPosRecord = point.X - newEllipse.Width / 2; var yPosRecord = point.Y - newEllipse.Height / 2; if (xPosRecord >= 0 && xPosRecord < this.Record.ActualWidth && yPosRecord >= 0 && yPosRecord < this.Record.ActualHeight) { Canvas.SetLeft(newEllipse, xPosRecord); Canvas.SetTop(newEllipse, yPosRecord); Record.Children.Add(newEllipse); } } } } if (sixJoints.IsChecked == true) { var resultHead = curFrameResult.BoneStates[JointType.Head]; var resultSpineMid = curFrameResult.BoneStates[JointType.SpineMid]; var resultKneeLeft = curFrameResult.BoneStates[JointType.KneeLeft]; var resultKneeRight = curFrameResult.BoneStates[JointType.KneeRight]; if (_mode == CameraMode.Depth) { if (resultSpineMid == SkeletonBoneState.Matched) { var xPosMid = depthPointSpineMid.X - ellipse7.Width / 2; var yPosMid = depthPointSpineMid.Y - ellipse7.Height / 2; if (xPosMid >= 0 && xPosMid < this.canvasDepth.ActualWidth && yPosMid >= 0 && yPosMid < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse7, xPosMid); Canvas.SetTop(ellipse7, yPosMid); canvasDepth.Children.Add(ellipse7); } } else { var xPosMid = depthPointSpineMid.X - ellipse8.Width / 2; var yPosMid = depthPointSpineMid.Y - ellipse8.Height / 2; if (xPosMid >= 0 && xPosMid < this.canvasDepth.ActualWidth && yPosMid >= 0 && yPosMid < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse8, xPosMid); Canvas.SetTop(ellipse8, yPosMid); canvasDepth.Children.Add(ellipse8); } } if (resultKneeLeft == SkeletonBoneState.Matched) { var xPosKneeLeft = depthPointKneeLeft.X - ellipse9.Width / 2; var yPosKneeLeft = depthPointKneeLeft.Y - ellipse9.Height / 2; if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvasDepth.ActualWidth && yPosKneeLeft >= 0 && yPosKneeLeft < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse9, xPosKneeLeft); Canvas.SetTop(ellipse9, yPosKneeLeft); canvasDepth.Children.Add(ellipse9); } } else { var xPosKneeLeft = depthPointKneeLeft.X - ellipse10.Width / 2; var yPosKneeLeft = depthPointKneeLeft.Y - ellipse10.Height / 2; if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvasDepth.ActualWidth && yPosKneeLeft >= 0 && yPosKneeLeft < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse10, xPosKneeLeft); Canvas.SetTop(ellipse10, yPosKneeLeft); canvasDepth.Children.Add(ellipse10); } } if (resultKneeRight == SkeletonBoneState.Matched) { var xPosKneeRight = depthPointKneeRight.X - ellipse11.Width / 2; var yPosKneeRight = depthPointKneeRight.Y - ellipse11.Height / 2; if (xPosKneeRight >= 0 && xPosKneeRight < this.canvasDepth.ActualWidth && yPosKneeRight >= 0 && yPosKneeRight < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse11, xPosKneeRight); Canvas.SetTop(ellipse11, yPosKneeRight); canvasDepth.Children.Add(ellipse11); } } else { var xPosKneeRight = depthPointKneeRight.X - ellipse12.Width / 2; var yPosKneeRight = depthPointKneeRight.Y - ellipse12.Height / 2; if (xPosKneeRight >= 0 && xPosKneeRight < this.canvasDepth.ActualWidth && yPosKneeRight >= 0 && yPosKneeRight < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse12, xPosKneeRight); Canvas.SetTop(ellipse12, yPosKneeRight); canvasDepth.Children.Add(ellipse12); } } if (resultHead == SkeletonBoneState.Matched) { var xPosHead = depthPointHead.X - ellipse5.Width / 2; var yPosHead = depthPointHead.Y - ellipse5.Height / 2; if (xPosHead >= 0 && xPosHead < this.canvasDepth.ActualWidth && yPosHead >= 0 && yPosHead < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse5, xPosHead); Canvas.SetTop(ellipse5, yPosHead); canvasDepth.Children.Add(ellipse5); } } else { var xPosHead = depthPointHead.X - ellipse6.Width / 2; var yPosHead = depthPointHead.Y - ellipse6.Height / 2; if (xPosHead >= 0 && xPosHead < this.canvasDepth.ActualWidth && yPosHead >= 0 && yPosHead < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse6, xPosHead); Canvas.SetTop(ellipse6, yPosHead); canvasDepth.Children.Add(ellipse6); } } if (resultWristLeft == SkeletonBoneState.Matched) { var xPosLeft = depthPointWristLeft.X - ellipse1.Width / 2; var yPosLeft = depthPointWristLeft.Y - ellipse1.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse1, xPosLeft); Canvas.SetTop(ellipse1, yPosLeft); canvasDepth.Children.Add(ellipse1); } } else { var xPosLeft = depthPointWristLeft.X - ellipse2.Width / 2; var yPosLeft = depthPointWristLeft.Y - ellipse2.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse2, xPosLeft); Canvas.SetTop(ellipse2, yPosLeft); canvasDepth.Children.Add(ellipse2); } } if (resultWristRight == SkeletonBoneState.Matched) { var xPosRight = depthPointWristRight.X - ellipse3.Width / 2; var yPosRight = depthPointWristRight.Y - ellipse3.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth && yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse3, xPosRight); Canvas.SetTop(ellipse3, yPosRight); canvasDepth.Children.Add(ellipse3); } } else { var xPosRight = depthPointWristRight.X - ellipse4.Width / 2; var yPosRight = depthPointWristRight.Y - ellipse4.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth && yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse4, xPosRight); Canvas.SetTop(ellipse4, yPosRight); canvasDepth.Children.Add(ellipse4); } } } else { if (resultSpineMid == SkeletonBoneState.Matched) { var xPosMid = colorPointSpineMid.X - ellipse7.Width / 2; var yPosMid = colorPointSpineMid.Y - ellipse7.Height / 2; if (xPosMid >= 0 && xPosMid < this.canvas.ActualWidth && yPosMid >= 0 && yPosMid < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse7, xPosMid); Canvas.SetTop(ellipse7, yPosMid); canvas.Children.Add(ellipse7); } } else { var xPosMid = colorPointSpineMid.X - ellipse8.Width / 2; var yPosMid = colorPointSpineMid.Y - ellipse8.Height / 2; if (xPosMid >= 0 && xPosMid < this.canvas.ActualWidth && yPosMid >= 0 && yPosMid < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse8, xPosMid); Canvas.SetTop(ellipse8, yPosMid); canvas.Children.Add(ellipse8); } } if (resultKneeLeft == SkeletonBoneState.Matched) { var xPosKneeLeft = colorPointKneeLeft.X - ellipse9.Width / 2; var yPosKneeLeft = colorPointKneeLeft.Y - ellipse9.Height / 2; if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvas.ActualWidth && yPosKneeLeft >= 0 && yPosKneeLeft < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse9, xPosKneeLeft); Canvas.SetTop(ellipse9, yPosKneeLeft); canvas.Children.Add(ellipse9); } } else { var xPosKneeLeft = colorPointKneeLeft.X - ellipse10.Width / 2; var yPosKneeLeft = colorPointKneeLeft.Y - ellipse10.Height / 2; if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvas.ActualWidth && yPosKneeLeft >= 0 && yPosKneeLeft < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse10, xPosKneeLeft); Canvas.SetTop(ellipse10, yPosKneeLeft); canvas.Children.Add(ellipse10); } } if (resultKneeRight == SkeletonBoneState.Matched) { var xPosKneeRight = colorPointKneeRight.X - ellipse11.Width / 2; var yPosKneeRight = colorPointKneeRight.Y - ellipse11.Height / 2; if (xPosKneeRight >= 0 && xPosKneeRight < this.canvas.ActualWidth && yPosKneeRight >= 0 && yPosKneeRight < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse11, xPosKneeRight); Canvas.SetTop(ellipse11, yPosKneeRight); canvas.Children.Add(ellipse11); } } else { var xPosKneeRight = colorPointKneeRight.X - ellipse12.Width / 2; var yPosKneeRight = colorPointKneeRight.Y - ellipse12.Height / 2; if (xPosKneeRight >= 0 && xPosKneeRight < this.canvas.ActualWidth && yPosKneeRight >= 0 && yPosKneeRight < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse12, xPosKneeRight); Canvas.SetTop(ellipse12, yPosKneeRight); canvas.Children.Add(ellipse12); } } if (resultHead == SkeletonBoneState.Matched) { var xPosHead = colorPointHead.X - ellipse5.Width / 2; var yPosHead = colorPointHead.Y - ellipse5.Height / 2; if (xPosHead >= 0 && xPosHead < this.canvas.ActualWidth && yPosHead >= 0 && yPosHead < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse5, xPosHead); Canvas.SetTop(ellipse5, yPosHead); canvas.Children.Add(ellipse5); } } else { var xPosHead = colorPointHead.X - ellipse6.Width / 2; var yPosHead = colorPointHead.Y - ellipse6.Height / 2; if (xPosHead >= 0 && xPosHead < this.canvas.ActualWidth && yPosHead >= 0 && yPosHead < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse6, xPosHead); Canvas.SetTop(ellipse6, yPosHead); canvas.Children.Add(ellipse6); } } if (resultWristLeft == SkeletonBoneState.Matched) { var xPosLeft = colorPointWristLeft.X - ellipse1.Width / 2; var yPosLeft = colorPointWristLeft.Y - ellipse1.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse1, xPosLeft); Canvas.SetTop(ellipse1, yPosLeft); canvas.Children.Add(ellipse1); } } else { var xPosLeft = colorPointWristLeft.X - ellipse2.Width / 2; var yPosLeft = colorPointWristLeft.Y - ellipse2.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse2, xPosLeft); Canvas.SetTop(ellipse2, yPosLeft); canvas.Children.Add(ellipse2); } } if (resultWristRight == SkeletonBoneState.Matched) { var xPosRight = colorPointWristRight.X - ellipse3.Width / 2; var yPosRight = colorPointWristRight.Y - ellipse3.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth && yPosRight >= 0 && yPosRight < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse3, xPosRight); Canvas.SetTop(ellipse3, yPosRight); canvas.Children.Add(ellipse3); } } else { var xPosRight = colorPointWristRight.X - ellipse4.Width / 2; var yPosRight = colorPointWristRight.Y - ellipse4.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth && yPosRight >= 0 && yPosRight < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse4, xPosRight); Canvas.SetTop(ellipse4, yPosRight); canvas.Children.Add(ellipse4); } } } } else { if (_mode == CameraMode.Depth) { if (resultWristLeft == SkeletonBoneState.Matched) { var xPosLeft = depthPointWristLeft.X - ellipse1.Width / 2; var yPosLeft = depthPointWristLeft.Y - ellipse1.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse1, xPosLeft); Canvas.SetTop(ellipse1, yPosLeft); canvasDepth.Children.Add(ellipse1); } } else { var xPosLeft = depthPointWristLeft.X - ellipse2.Width / 2; var yPosLeft = depthPointWristLeft.Y - ellipse2.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse2, xPosLeft); Canvas.SetTop(ellipse2, yPosLeft); canvasDepth.Children.Add(ellipse2); } } if (resultWristRight == SkeletonBoneState.Matched) { var xPosRight = depthPointWristRight.X - ellipse3.Width / 2; var yPosRight = depthPointWristRight.Y - ellipse3.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth && yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse3, xPosRight); Canvas.SetTop(ellipse3, yPosRight); canvasDepth.Children.Add(ellipse3); } } else { var xPosRight = depthPointWristRight.X - ellipse4.Width / 2; var yPosRight = depthPointWristRight.Y - ellipse4.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth && yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight) { Canvas.SetLeft(ellipse4, xPosRight); Canvas.SetTop(ellipse4, yPosRight); canvasDepth.Children.Add(ellipse4); } } } else { if (resultWristLeft == SkeletonBoneState.Matched) { var xPosLeft = colorPointWristLeft.X - ellipse1.Width / 2; var yPosLeft = colorPointWristLeft.Y - ellipse1.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse1, xPosLeft); Canvas.SetTop(ellipse1, yPosLeft); canvas.Children.Add(ellipse1); } } else { var xPosLeft = colorPointWristLeft.X - ellipse2.Width / 2; var yPosLeft = colorPointWristLeft.Y - ellipse2.Height / 2; if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth && yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse2, xPosLeft); Canvas.SetTop(ellipse2, yPosLeft); canvas.Children.Add(ellipse2); } } if (resultWristRight == SkeletonBoneState.Matched) { var xPosRight = colorPointWristRight.X - ellipse3.Width / 2; var yPosRight = colorPointWristRight.Y - ellipse3.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth && yPosRight >= 0 && yPosRight < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse3, xPosRight); Canvas.SetTop(ellipse3, yPosRight); canvas.Children.Add(ellipse3); } } else { var xPosRight = colorPointWristRight.X - ellipse4.Width / 2; var yPosRight = colorPointWristRight.Y - ellipse4.Height / 2; if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth && yPosRight >= 0 && yPosRight < this.canvas.ActualHeight) { Canvas.SetLeft(ellipse4, xPosRight); Canvas.SetTop(ellipse4, yPosRight); canvas.Children.Add(ellipse4); } } } } } else { escape = false; } } } } } if (depthFrame != null) depthFrame.Dispose(); depthFrame = null; if (colorFrame != null) colorFrame.Dispose(); colorFrame = null; }
private void processDepthFrame(DepthFrame depthFrame, int depthWidth, int depthHeight) { FrameDescription depthFrameDescription = depthFrame.FrameDescription; depthWidth = depthFrameDescription.Width; depthHeight = depthFrameDescription.Height; // Access the depth frame data directly via LockImageBuffer to avoid making a copy using (KinectBuffer depthFrameData = depthFrame.LockImageBuffer()) { this.coordinateMapper.MapColorFrameToDepthSpaceUsingIntPtr( depthFrameData.UnderlyingBuffer, depthFrameData.Size, this.colorMappedToDepthPoints); } // We're done with the DepthFrame depthFrame.Dispose(); depthFrame = null; }
private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e) { if (!(KinectStreamerConfig.ProvideBodyData || KinectStreamerConfig.ProvideColorData || KinectStreamerConfig.ProvideDepthData)) { return; } depthFrame = null; colorFrame = null; bodyFrame = null; multiSourceFrame = e.FrameReference.AcquireFrame(); // If the Frame has expired by the time we process this event, return. if (multiSourceFrame == null) { return; } // We use a try/finally to ensure that we clean up before we exit the function. // This includes calling Dispose on any Frame objects that we may have and unlocking the bitmap back buffer. try { depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame(); colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame(); bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame(); // If any frame has expired by the time we process this event, return. // The "finally" statement will Dispose any that are not null. if ((depthFrame == null) || (colorFrame == null) || (bodyFrame == null)) { return; } // Process color stream if needed if (KinectStreamerConfig.ProvideColorData) { ProcessColorData(); } // Process depth frame if needed if (KinectStreamerConfig.ProvideDepthData) { ProcessDepthData(); } // Process body data if needed if (KinectStreamerConfig.ProvideBodyData) { ProcessBodyData(); } } finally { if (depthFrame != null) { depthFrame.Dispose(); } if (colorFrame != null) { colorFrame.Dispose(); } if (bodyFrame != null) { bodyFrame.Dispose(); } } }