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);
            }
        }
Ejemplo n.º 2
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
        }
Ejemplo n.º 3
0
        /// 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();
            }
        }
Ejemplo n.º 4
0
 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);
                }
            }
        }
Ejemplo n.º 6
0
 /// <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);
         }
     }
 }
Ejemplo n.º 7
0
 //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();
 }
Ejemplo n.º 8
0
 static void reader_BodyIndexFrameArrived(object sender, BodyIndexFrameArrivedEventArgs e)
 {
     using (var bodyIndexFrame = e.FrameReference.AcquireFrame())
     {
         if (bodyIndexFrame != null)
         {
             BodyIndexFrameReady(bodyIndexFrame);
         }
     }
 }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        // ボディインデックスフレームの更新
        private void UpdateBodyIndexFrame(BodyIndexFrameArrivedEventArgs e)
        {
            using (var bodyIndexFrame = e.FrameReference.AcquireFrame()) {
                if (bodyIndexFrame == null)
                {
                    return;
                }

                // ボディインデックスデータを取得する
                bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer);
            }
        }
Ejemplo n.º 11
0
 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);
         }
     }
 }
Ejemplo n.º 12
0
 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);
     }
 }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
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));
                }
            }
        }
        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));
                }

            }
        }
Ejemplo n.º 16
0
        //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();
            }
        }
Ejemplo n.º 18
0
        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();
        }
Ejemplo n.º 19
0
    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();
            }
        }
Ejemplo n.º 21
0
 /// <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);
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
        /// <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();
            }
        }
Ejemplo n.º 23
0
        /*
         * 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();
            }
        }
Ejemplo n.º 25
0
        /// <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));
            }
        }
Ejemplo n.º 26
0
 void bodyIndexFrameReader_FrameArrived(object sender,
                                        BodyIndexFrameArrivedEventArgs e)
 {
     UpdateBodyIndexFrame(e);
     DrawBodyIndexFrame();
 }
Ejemplo n.º 27
0
 void bodyIndexFrameReader_FrameArrived( 
     BodyIndexFrameReader sender, BodyIndexFrameArrivedEventArgs args )
 {
     UpdateBodyIndexFrame( args );
     DrawBodyIndexFrame();
 }
Ejemplo n.º 28
0
        /// <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;
            }
        }
Ejemplo n.º 29
0
        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;
 }
Ejemplo n.º 31
0
        /// <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;
        }
Ejemplo n.º 32
0
 private void Runtime_PlayerFrameReady(object sender, BodyIndexFrameArrivedEventArgs e)
 {
     if (this.BodyFrameReady != null)
     {
         this.BodyFrameReady(sender, e);
     }
 }
Ejemplo n.º 33
0
        //bodyindex
        #region
        void bodyIndexFrameReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e)
        {

            UpdateBodyIndexFrame(e);
            DrawBodyIndexFrame();

        }
Ejemplo n.º 34
0
 void bodyIndexFrameReader_FrameArrived(
     BodyIndexFrameReader sender, BodyIndexFrameArrivedEventArgs args)
 {
     UpdateBodyIndexFrame(args);
     DrawBodyIndexFrame();
 }
Ejemplo n.º 35
0
        private void BodyIndexReader_FrameArrived(object sender, BodyIndexFrameArrivedEventArgs e)
        {
            var bodyIndexPacket = new BodyIndexFramePacket(e.Bitmap, e.CameraIntrinsics, _sensor.GetCoordinateMapper().DepthToColor);

            SendFrameData(bodyIndexPacket);
        }
Ejemplo n.º 36
0
        /// <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);
            }
        }
Ejemplo n.º 37
0
        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();
        }
Ejemplo n.º 38
0
        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();
            }
        }
Ejemplo n.º 39
0
        private void UpdateBodyIndexFrame(BodyIndexFrameArrivedEventArgs e)
        {
            using (var bodyIndexFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyIndexFrame == null)
                {
                    return;
                }

                // ボディインデックスデータを取得する
                bodyIndexFrame.CopyFrameDataToArray(bodyIndexBuffer);

                //bodyIndexFrame.Dispose();
            }
        }
Ejemplo n.º 40
0
        private void UpdateBodyIndexFrame( BodyIndexFrameArrivedEventArgs args )
        {
            // ボディインデックスフレームを取得する
            using ( var bodyIndexFrame = args.FrameReference.AcquireFrame() ) {
                if ( bodyIndexFrame == null ) {
                    return;
                }

                // ボディインデックスデータを取得する
                bodyIndexFrame.CopyFrameDataToArray( bodyIndexBuffer );
            }
        }
 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();
     }
 }
Ejemplo n.º 42
0
 /// <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);
 }
Ejemplo n.º 43
0
        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 );
        }