private void Reader_BodyIndexFrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { bodyIndexFrame.CopyFrameDataToArray(bodyIndexPixels); } for (int i = 0; i < bodyIndexPixels.Length; ++i) { if (bodyIndexPixels[i] != 255) { var color = bodyIndexColors[bodyIndexPixels[i]]; bitmapPixels[i * 4 + 0] = color.B; bitmapPixels[i * 4 + 1] = color.G; bitmapPixels[i * 4 + 2] = color.R; bitmapPixels[i * 4 + 3] = 255; } else { bitmapPixels[i * 4 + 0] = 0; bitmapPixels[i * 4 + 1] = 0; bitmapPixels[i * 4 + 2] = 0; bitmapPixels[i * 4 + 3] = 255; } } bodyIndexBitmap.WritePixels(new Int32Rect(0, 0, bodyIndexBitmap.PixelWidth, bodyIndexBitmap.PixelHeight), bitmapPixels, bodyIndexBitmap.PixelWidth * 4, 0); } }
private void BodyIndexReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { var bitmap = e.GetDisplayableBitmap(); bitmap = Interlocked.Exchange(ref _bodyIndexBackBuffer, bitmap); bitmap?.Dispose(); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed BodyIndexOutput.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { if (Interlocked.CompareExchange(ref _isRederingBodyIndex, 1, 0) == 0) { try { SoftwareBitmap availableFrame = null; while ((availableFrame = Interlocked.Exchange(ref _bodyIndexBackBuffer, null)) != null) { await((SoftwareBitmapSource)BodyIndexOutput.Source).SetBitmapAsync(availableFrame); availableFrame.Dispose(); } } finally { Interlocked.Exchange(ref _isRederingBodyIndex, 0); } } }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }
/// Handles the body index frame data arriving from the sensor /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Reader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { bool bodyIndexFrameProcessed = false; using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { // the fastest way to process the body index data is to directly access // the underlying buffer using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bodyIndexFrame.LockImageBuffer()) { // verify data and write the color data to the display bitmap if (((this._bodyIndexFrameDescription.Width * this._bodyIndexFrameDescription.Height) == bodyIndexBuffer.Size) && (this._bodyIndexFrameDescription.Width == this._bodyIndexBitmap.PixelWidth) && (this._bodyIndexFrameDescription.Height == this._bodyIndexBitmap.PixelHeight)) { this.ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); bodyIndexFrameProcessed = true; } } } } if (bodyIndexFrameProcessed) { this.RenderBodyIndexPixels(); } }
private void Runtime_PlayerFrameReady(object sender, BodyIndexFrameArrivedEventArgs e) { if (this.BodyFrameReady != null) { this.BodyFrameReady(sender, e); } }
/// <summary> /// Handles body index /// </summary> /// <param name="bodyIndexCollectedCancelTokenSource">cancelTokenSource used to stop the task</param> private static void HandleBodyIndex(CancellationTokenSource bodyIndexCollectedCancelTokenSource) { BodyIndexFrameArrivedEventArgs e = null; String frameNumber = String.Empty; BodyIndexFrame bodyIndexFrame; while (true) { bodyIndexFrame = null; if (bodyIndexCollectedCancelTokenSource.IsCancellationRequested) { break; } if (bodyIndexFrameQueue.Count != 0) { lock (FramesAndPaths.allFrameInfo) { if ((FramesAndPaths.allFrameInfo.allFrameFlag & 8) != 0) { continue; } try { e = bodyIndexFrameQueue.Dequeue(); } catch (InvalidOperationException) { continue; } try { bodyIndexFrame = e.FrameReference.AcquireFrame(); } catch (NullReferenceException) { } if (bodyIndexFrame == null) { continue; } frameNumber = FramesAndPaths.allFrameInfo.frameNumber; FramesAndPaths.allFrameInfo.allFrameFlag |= 8; if ((FramesAndPaths.allFrameInfo.allFrameFlag ^ 31) == 0) { FramesAndPaths.allFrameInfo.allFrameFlag = 0; FramesAndPaths.FrameNumberIncrement(); ++writtenCount; } } StoreFramesData.Handle_BodyIndexFrame(bodyIndexFrame, frameNumber); } } }
/// <summary> /// Handles the 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_BodyIndexFrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { bodyIndexFrame.CopyFrameDataToArray(bodyIndexDataArray); } } }
//frame取得時のイベント public void BodyIndexFrame_Arrived(object sender, BodyIndexFrameArrivedEventArgs e) #region { BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame(); if (bodyIndexFrame == null) return; bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); //人がいないところ0xff いるところ0-6? this.KinectImagetoMat(this.kinectImage, this.bodyIndexBuffer); //this._showImageEvent(); bodyIndexFrame.Dispose(); }
static void reader_BodyIndexFrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (var bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { BodyIndexFrameReady(bodyIndexFrame); } } }
void bodyIndexFrameReader_FrameArrived(BodyIndexFrameReader sender, BodyIndexFrameArrivedEventArgs args) { // ボディインデックスデータを取得する using (var bodyIndexFrame = args.FrameReference.AcquireFrame()) { if (bodyIndexFrame == null) { return; } bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); } // ボディインデックスデータをBGRAデータに変換する for (int i = 0; i < bodyIndexBuffer.Length; i++) { var index = bodyIndexBuffer[i]; var colorIndex = i * 4; if (index != 255) { // BodyIndexとビーム方向のTrackingIdのインデックスが // 一致している人の色を変える(青) if (index == AudioTrackingIndex) { bodyIndexColorBuffer[colorIndex + 0] = 255; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 255; bodyIndexColorBuffer[colorIndex + 3] = 255; } } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } } // ビットマップにする var stream = bodyIndexColorBitmap.PixelBuffer.AsStream(); stream.Write(bodyIndexColorBuffer, 0, bodyIndexColorBuffer.Length); bodyIndexColorBitmap.Invalidate(); }
// ボディインデックスフレームの更新 private void UpdateBodyIndexFrame(BodyIndexFrameArrivedEventArgs e) { using (var bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame == null) { return; } // ボディインデックスデータを取得する bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); } }
public void Reader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (BodyIndexFrame bodyindexFrame = e.FrameReference.AcquireFrame()) { if (bodyindexFrame != null) { byte[] bodyindexData = new byte[depthFrameWidth * depthFrameHeight]; bodyindexFrame.CopyFrameDataToArray(bodyindexData); bodyindexframes.Add(bodyindexData); } } }
private void BiReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (var frame = e.FrameReference.AcquireFrame()) { if (frame == null) { return; } var frameDescription = frame.FrameDescription; biFrameData = new byte[frameDescription.Width * frameDescription.Height]; frame.CopyFrameDataToArray(biFrameData); } }
void bodyIndexFrameReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { // ボディインデックスデータを取得する using (var bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame == null) { return; } bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); } // ボディインデックスデータをBGRAデータに変換する for (int i = 0; i < bodyIndexBuffer.Length; i++) { var index = bodyIndexBuffer[i]; var colorIndex = i * 4; if (index != 255) { // BodyIndexとビーム方向のTrackingIdのインデックスが // 一致している人の色を変える(青) if (index == AudioTrackingIndex) { bodyIndexColorBuffer[colorIndex + 0] = 255; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 255; bodyIndexColorBuffer[colorIndex + 3] = 255; } } else { bodyIndexColorBuffer[colorIndex + 0] = 255; bodyIndexColorBuffer[colorIndex + 1] = 255; bodyIndexColorBuffer[colorIndex + 2] = 255; bodyIndexColorBuffer[colorIndex + 3] = 255; } } // ビットマップにする bodyIndexColorImage.WritePixels(bodyIndexColorRect, bodyIndexColorBuffer, bodyIndexColorStride, 0); }
private void FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { var frame = e.FrameReference.AcquireFrame(); if (frame != null) { frame.CopyFrameDataToIntPtr(this.frameData.DataPointer, (uint)this.frameData.SizeInBytes); frame.Dispose(); if (this.FrameReceived != null) { this.FrameReceived(this, new BodyIndexFrameDataEventArgs(this.frameData)); } } }
//frame取得時のイベント public void BodyIndexFrame_Arrived(object sender, BodyIndexFrameArrivedEventArgs e) #region { BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame(); if (bodyIndexFrame == null) { return; } bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); //人がいないところ0xff いるところ0-6? this.KinectImagetoMat(this.kinectImage, this.bodyIndexBuffer); //this._showImageEvent(); bodyIndexFrame.Dispose(); }
private void DepthFrameReady(object sender, BodyIndexFrameArrivedEventArgs e) { BodyIndexFrame frame = e.FrameReference.AcquireFrame(); if (frame != null) { this.FInvalidate = true; this.frameindex = frame.RelativeTime.Ticks; lock (m_lock) { frame.CopyFrameDataToArray(this.rawdepth); } frame.Dispose(); } }
void BodyIndexFrameReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (var frame = e.FrameReference.AcquireFrame()) { if (frame == null) { return; } // Copy body index pixels to our memory. frame.CopyFrameDataToArray(BodyIndexPixels); } OnBodyIndexData(); }
private void BodyIndexReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { if (_bodyIndexDataBuf != null) { lock (_bodyIndexDataLock) { e.Bitmap.CopyToBuffer(_bodyIndexDataBuf.AsBuffer()); if (_saveLatestFrames) { _latestBodyIndexFrame = e.Frame; } _bodyIndexDataTime = DateTime.Now.Ticks; // bodyIndexFrame.RelativeTime.Ticks; _bodyIndexDataReady = true; } } }
void bodyIndexFrameReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { using (var bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame == null) { return; } // ボディインデックスデータを取得する bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); // ボディインデックスデータをBGRAデータに変換する for (int i = 0; i < bodyIndexBuffer.Length; i++) { var index = bodyIndexBuffer[i]; var colorIndex = i * 4; if (index != 255) { var color = bodyIndexColors[index]; bodyIndexColorBuffer[colorIndex + 0] = color.B; bodyIndexColorBuffer[colorIndex + 1] = color.G; bodyIndexColorBuffer[colorIndex + 2] = color.R; bodyIndexColorBuffer[colorIndex + 3] = 255; } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } } // ビットマップにする bodyIndexColorImage.WritePixels(bodyIndexColorRect, bodyIndexColorBuffer, bodyIndexColorStride, 0); // フレームレート更新 TextFps.Text = counter.Update().ToString(); } }
/// <summary> /// 人体索引帧临帧事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void Reader_BodyIndexFrameArrived(Object sender, BodyIndexFrameArrivedEventArgs e) { using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { // the fastest way to process the body index data is to directly access // the underlying buffer using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bodyIndexFrame.LockImageBuffer()) { // verify data and write the color data to the display bitmap if (((this.bodyIndexFrameDescription.Width * this.bodyIndexFrameDescription.Height) == bodyIndexBuffer.Size)) { //this.BodyIndexToDepth(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); this.ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); } } } } }
/// <summary> /// Handles the 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_BodyIndexFrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { bool bodyIndexFrameProcessed = false; using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { bodyIHandler.BodyIndexFrameArrival(bodyIndexFrame, ref bodyIndexFrameProcessed, this.fps, bodyIndexBitmap); indexResolutionText.Content = string.Format("Resolution : {0} x {1}", bodyIndexFrame.FrameDescription.Width.ToString(), bodyIndexFrame.FrameDescription.Height.ToString()); } } if (bodyIndexFrameProcessed) { this.RenderBodyIndexPixels(); } }
/* * The pixel values in this frame are 8-bit unsigned integers, where 0-5 map directly to the BodyData index in the BodyFrame. * Values greater than the value obtained from BodyCount indicate the pixel is part of the background, not associated with a tracked body. * This frame is useful for green screening applications, or any scenario where you want to display the silhouette of the user. * It also provides a good starting bounds for custom depth algorithms. */ private void updateBodyIndexEvent(object sender, BodyIndexFrameArrivedEventArgs e) { using (BodyIndexFrame frame = e.FrameReference.AcquireFrame()) { if (frame != null) { FrameDescription frameDescription = frame.FrameDescription; // verify data and write the data to the display bitmap if ((frameDescription.Width * frameDescription.Height) == 424 * 512) { WriteableBitmap Bitmap = BitmapFactory.New(frameDescription.Width, frameDescription.Height); byte[] frameData = new byte[frameDescription.Width * frameDescription.Height]; frame.CopyFrameDataToArray(frameData); for (int y = 0; y < frameDescription.Height; y++) { for (int x = 0; x < frameDescription.Width; x++) { int index = y * frameDescription.Width + x; if (frameData[index] != 0xff) { myColor.HSB hsb = new myColor.HSB(); hsb.H = x / frameDescription.Height * 255; hsb.S = Numbers.ConvertToRange(y, 0, frameDescription.Height / 2, 0, 1, true); hsb.B = Numbers.ConvertToRange(y, frameDescription.Height / 2, frameDescription.Height, 1, 0, true); System.Drawing.Color color = myColor.FromHSB(hsb); // make a dynamic image, also there can be up to 6 images so we need them to be a little different Bitmap.SetPixel(x, y, color.A, color.R, color.G, color.B); } else { Bitmap.SetPixel(x, y, 255, 0, 255, 0); // green } } } SendImage(Bitmap, "kinectbodyindex"); } } } }
private void DepthFrameReady(object sender, BodyIndexFrameArrivedEventArgs e) { BodyIndexFrame frame = e.FrameReference.AcquireFrame(); int bg = this.backcolor; if (frame != null) { this.FInvalidate = true; this.frameindex = frame.RelativeTime.Ticks; lock (m_lock) { frame.CopyFrameDataToArray(this.rawdepth); for (int i16 = 0; i16 < 512 * 424; i16++) { byte player = rawdepth[i16]; this.playerimage[i16] = player == 255 ? bg : this.colors[player % 6]; } } frame.Dispose(); } }
/// <summary> /// Called when a body index frame arrived from the sensor. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DepthFrameArrivedEventArgs"/> instance containing the event data.</param> private void OnReaderBodyIndexFrame_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { // Notify flowrate occurrence m_performanceAnalyzer.NotifyFlowRateOccurrence( Constants.KINECT_PERF_FLOWRATE_BODYINDEX_FRAME); using (var frame = e.FrameReference.AcquireFrame()) { if (frame == null) { return; } this.AquiredBodyFrames = this.AquiredBodyFrames + 1; // Publich event to whole application m_Messenger.Publish( new MessageBodyIndexFrameArrived(e)); } }
void bodyIndexFrameReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { UpdateBodyIndexFrame(e); DrawBodyIndexFrame(); }
void bodyIndexFrameReader_FrameArrived( BodyIndexFrameReader sender, BodyIndexFrameArrivedEventArgs args ) { UpdateBodyIndexFrame( args ); DrawBodyIndexFrame(); }
/// <summary> /// Handles the 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_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { if (frameCount >= min_ && frameCount < max_) { bool bodyIndexFrameProcessed = false; using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { // the fastest way to process the body index data is to directly access // the underlying buffer using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bodyIndexFrame.LockImageBuffer()) { // verify data and write the color data to the display bitmap if (((this.bodyIndexFrameDescription.Width * this.bodyIndexFrameDescription.Height) == bodyIndexBuffer.Size) && (this.bodyIndexFrameDescription.Width == this.bodyIndexBitmap.PixelWidth) && (this.bodyIndexFrameDescription.Height == this.bodyIndexBitmap.PixelHeight)) { this.ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); bodyIndexFrameProcessed = true; } } } } if (bodyIndexFrameProcessed) { this.RenderBodyIndexPixels(); if (this.bodyIndexBitmap != null) { // create a png bitmap encoder which knows how to save a .png file BitmapEncoder encoder = new PngBitmapEncoder(); // create frame from the writable bitmap and add to encoder encoder.Frames.Add(BitmapFrame.Create(this.bodyIndexBitmap)); // string time = System.DateTime.UtcNow.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat); // string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); // string mycustompath = @"G:\01\bodyindex_data\"; string path = Path.Combine(path_ + @"/bodyIndex" + frameCount.ToString() + ".png"); // write the new file to disk try { // FileStream is IDisposable using (FileStream fs = new FileStream(path, FileMode.Create)) { encoder.Save(fs); } // this.StatusText = string.Format(CultureInfo.CurrentCulture, Properties.Resources.SavedScreenshotStatusTextFormat, path); } catch (IOException) { // this.StatusText = string.Format(CultureInfo.CurrentCulture, Properties.Resources.FailedScreenshotStatusTextFormat, path); } } Console.WriteLine("I m here " + frameCount.ToString()); frameCount++; } } else { frameCount++; return; } }
private void Reader_BodyIndexFrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { if (_needBodyIndex) { //lowers fps to improve performance if (_frameCount % 2 == 0) { // ColorFrame is IDisposable using (BodyIndexFrame frame = e.FrameReference.AcquireFrame()) { if (frame != null) { FrameDescription frameDescription = this.GetFrameDescriptionForMode(BackgroundMode.BodyIndex); using (KinectBuffer buffer = frame.LockImageBuffer()) { // verify data and write the new color frame data to the display bitmap if (this._source == null || (frameDescription.Width != this._source.PixelWidth) || (frameDescription.Height != this._source.PixelHeight)) { this._source = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); } this._source.Lock(); this.ProcessBodyIndexFrameData(buffer.UnderlyingBuffer, buffer.Size); this._source.WritePixels(new Int32Rect(0, 0, this._source.PixelWidth, this._source.PixelHeight), this.bodyIndexPixels, this._source.PixelWidth * (int)BytesPerPixel, 0); _gaussianSource = this._source; this.Update(); this._source.Unlock(); } } } } _frameCount++; } }
internal MessageBodyIndexFrameArrived(BodyIndexFrameArrivedEventArgs bodyIndexFrameArgs) { this.BodyIndexFrameArgs = bodyIndexFrameArgs; }
/// <summary> /// Handles the 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 BodyIndexReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { if (this.processingBodyIndexFrame) { return; } this.processingBodyIndexFrame = true; bool bodyIndexFrameProcessed = false; using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { // the fastest way to process the body index data is to directly access // the underlying buffer using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bodyIndexFrame.LockImageBuffer()) { // verify data and write the color data to the display bitmap //&&(this.bodyIndexFrameDescription.Width == this.bodyIndexBitmap.PixelWidth) && (this.bodyIndexFrameDescription.Height == this.bodyIndexBitmap.PixelHeight)) //maybe try / this.bodyIndexFrameDescription.BytesPerPixel if ((this.bodyIndexFrameDescription.Width * this.bodyIndexFrameDescription.Height) ==(bodyIndexBuffer.Size / this.bodyIndexFrameDescription.BytesPerPixel)) { this.ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); bodyIndexFrameProcessed = true; } } } } if (bodyIndexFrameProcessed) { this.bodyIndexFrameCallback(this.bodyIndexPixels); // this.RenderBodyIndexPixels(); } this.processingBodyIndexFrame = false; }
//bodyindex #region void bodyIndexFrameReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { UpdateBodyIndexFrame(e); DrawBodyIndexFrame(); }
void bodyIndexFrameReader_FrameArrived( BodyIndexFrameReader sender, BodyIndexFrameArrivedEventArgs args) { UpdateBodyIndexFrame(args); DrawBodyIndexFrame(); }
private void BodyIndexReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { var bodyIndexPacket = new BodyIndexFramePacket(e.Bitmap, e.CameraIntrinsics, _sensor.GetCoordinateMapper().DepthToColor); SendFrameData(bodyIndexPacket); }
/// <summary> /// Handles the 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_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e) { bool bodyIndexFrameProcessed = false; using (BodyIndexFrame bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame != null) { // the fastest way to process the body index data is to directly access // the underlying buffer using (Microsoft.Kinect.KinectBuffer bodyIndexBuffer = bodyIndexFrame.LockImageBuffer()) { // verify data and write the color data to the display bitmap if (((this.bodyIndexFrameDescription.Width * this.bodyIndexFrameDescription.Height) == bodyIndexBuffer.Size) && (this.bodyIndexFrameDescription.Width == this.bodyIndexBitmap.PixelWidth) && (this.bodyIndexFrameDescription.Height == this.bodyIndexBitmap.PixelHeight)) { // checks each pixel to see if it is part of the player or not this.ProcessBodyIndexFrameData(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); // check if the frame is the same as before or different checkFrame(bodyIndexBuffer.UnderlyingBuffer, bodyIndexBuffer.Size); if (found && !fired) { fired = true; frameNum++; Console.WriteLine("Shot " + frameNum); // fire gun Process proc = new System.Diagnostics.Process(); proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; proc.StartInfo.FileName = "C:/Python27/python.exe"; proc.StartInfo.Arguments = "activateSentry.py"; proc.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); while (!proc.StandardOutput.EndOfStream) { Console.WriteLine(proc.StandardOutput.ReadLine()); } Console.WriteLine("Fired" + DateTime.Now); // take photo of victum takePhoto(); Console.WriteLine("Photo Taken " + DateTime.Now); // tweet current photo Process proc2 = new System.Diagnostics.Process(); proc2.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; proc2.StartInfo.FileName = "C:/Python27/python.exe"; proc2.StartInfo.Arguments = "tweetphoto.py"; proc2.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); proc2.StartInfo.UseShellExecute = false; proc2.StartInfo.RedirectStandardOutput = true; proc2.Start(); while (!proc2.StandardOutput.EndOfStream) { Console.WriteLine(proc2.StandardOutput.ReadLine()); } } bodyIndexFrameProcessed = true; } } } } //bodyIndexFrameProcessed = false; if (bodyIndexFrameProcessed) { // this displays the new body but for some reason this constantly executes this.RenderBodyIndexPixels(); //Console.WriteLine("body count: " + BodyFrameSource::BodyCount); } }
void bodyIndexFrameReader_FrameArrived( BodyIndexFrameReader sender, BodyIndexFrameArrivedEventArgs args ) { // ボディインデックスデータを取得する using ( var bodyIndexFrame = args.FrameReference.AcquireFrame() ) { if ( bodyIndexFrame == null ) { return; } bodyIndexFrame.CopyFrameDataToArray( bodyIndexBuffer ); } // ボディインデックスデータをBGRAデータに変換する for ( int i = 0; i < bodyIndexBuffer.Length; i++ ) { var index = bodyIndexBuffer[i]; var colorIndex = i * 4; if ( index != 255 ) { // BodyIndexとビーム方向のTrackingIdのインデックスが // 一致している人の色を変える(青) if ( index == AudioTrackingIndex ) { bodyIndexColorBuffer[colorIndex + 0] = 255; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 255; bodyIndexColorBuffer[colorIndex + 3] = 255; } } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } } // ビットマップにする var stream = bodyIndexColorBitmap.PixelBuffer.AsStream(); stream.Write( bodyIndexColorBuffer, 0, bodyIndexColorBuffer.Length ); bodyIndexColorBitmap.Invalidate(); }
private void DepthFrameReady(object sender, BodyIndexFrameArrivedEventArgs e) { BodyIndexFrame frame = e.FrameReference.AcquireFrame(); int bg = this.backcolor; if (frame != null) { this.FInvalidate = true; this.frameindex = (int)frame.RelativeTime.Ticks; lock (m_lock) { frame.CopyFrameDataToArray(this.rawdepth); for (int i16 = 0; i16 < 512 * 424; i16++) { byte player = rawdepth[i16]; this.playerimage[i16] = player == 255 ? bg : this.colors[player % 9]; } } frame.Dispose(); } }
private void UpdateBodyIndexFrame(BodyIndexFrameArrivedEventArgs e) { using (var bodyIndexFrame = e.FrameReference.AcquireFrame()) { if (bodyIndexFrame == null) { return; } // ボディインデックスデータを取得する bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer); //bodyIndexFrame.Dispose(); } }
private void UpdateBodyIndexFrame( BodyIndexFrameArrivedEventArgs args ) { // ボディインデックスフレームを取得する using ( var bodyIndexFrame = args.FrameReference.AcquireFrame() ) { if ( bodyIndexFrame == null ) { return; } // ボディインデックスデータを取得する bodyIndexFrame.CopyFrameDataToArray( bodyIndexBuffer ); } }
/// <summary> /// Enqueue body index frame events /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void BodyIndex_EnqueueEventArgs(Object sender, BodyIndexFrameArrivedEventArgs e) { bodyIndexFrameQueue.Enqueue(e); }
void bodyIndexFrameReader_FrameArrived( object sender, BodyIndexFrameArrivedEventArgs e ) { // ボディインデックスデータを取得する using ( var bodyIndexFrame = e.FrameReference.AcquireFrame() ) { if ( bodyIndexFrame == null ) { return; } bodyIndexFrame.CopyFrameDataToArray( bodyIndexBuffer ); } // ボディインデックスデータをBGRAデータに変換する for ( int i = 0; i < bodyIndexBuffer.Length; i++ ) { var index = bodyIndexBuffer[i]; var colorIndex = i * 4; if ( index != 255 ) { // BodyIndexとビーム方向のTrackingIdのインデックスが // 一致している人の色を変える(青) if ( index == AudioTrackingIndex ) { bodyIndexColorBuffer[colorIndex + 0] = 255; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 0; bodyIndexColorBuffer[colorIndex + 3] = 255; } else { bodyIndexColorBuffer[colorIndex + 0] = 0; bodyIndexColorBuffer[colorIndex + 1] = 0; bodyIndexColorBuffer[colorIndex + 2] = 255; bodyIndexColorBuffer[colorIndex + 3] = 255; } } else { bodyIndexColorBuffer[colorIndex + 0] = 255; bodyIndexColorBuffer[colorIndex + 1] = 255; bodyIndexColorBuffer[colorIndex + 2] = 255; bodyIndexColorBuffer[colorIndex + 3] = 255; } } // ビットマップにする bodyIndexColorImage.WritePixels( bodyIndexColorRect, bodyIndexColorBuffer, bodyIndexColorStride, 0 ); }