Example #1
0
        void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            bool receivedData = false;

            using (ColorImageFrame CFrame = e.OpenColorImageFrame())
            {
                if (CFrame == null)
                {
                    // The image processing took too long. More than 2 frames behind.
                }
                else
                {
                    pixelData = new byte[CFrame.PixelDataLength];
                    CFrame.CopyPixelDataTo(pixelData);
                    receivedData = true;
                }
            }

            if (receivedData)
            {
                IntPtr ctpr = Marshal.UnsafeAddrOfPinnedArrayElement(pixelData, 0);
                Bitmap bm   = new Bitmap(640, 480, 640 * 4, System.Drawing.Imaging.PixelFormat.Format32bppRgb, ctpr);

                pictureBox1.Image = bm;
            }
        }
Example #2
0
        void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if ((DateTime.Now - _lastFrameTimeStamp).TotalMilliseconds >= MaxInterval)
            {
                _lastFrameTimeStamp = DateTime.Now;

                using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
                {
                    Bitmap bmap = ImageToBitmap(imageFrame);
                    if (bmap != null)
                    {
                        lock (_skeletons)
                        {
                            foreach (Skeleton skel in _skeletons)
                            {
                                DrawBonesAndJoints(skel, Graphics.FromImage(bmap));
                            }
                        }
                        // notify client
                        NewFrame(this, new NewFrameEventArgs(bmap));
                        // release the image
                        bmap.Dispose();
                    }
                }
            }
        }
Example #3
0
        void kinectRuntime_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if (replay != null && !replay.IsFinished)
            {
                return;
            }

            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                if (recorder != null && ((recorder.Options & KinectRecordOptions.Color) != 0))
                {
                    recorder.Record(frame);
                    Debug.WriteLine("Color Recorded");
                }

                //  if (displayDepth)
                //    return;

                colorManager.Update(frame);
            }
        }
Example #4
0
        /// <summary>
        /// Event handler for Kinect sensor's ColorFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())

            {
                if (colorFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    colorFrame.CopyPixelDataTo(this.colorPixels);
                    // Write the pixel data into our bitmap
                    this.colorBitmap.WritePixels(
                        new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                        this.colorPixels,
                        this.colorBitmap.PixelWidth * colorFrame.BytesPerPixel,
                        0);
                    // Console.WriteLine(this.colorPixels[0]); // test to access infrared stream data
                    // stream colorPixels data to local socket buffer to be read by Python application
                    // fail on dropped connection
                    try
                    {
                        sock.Send(this.colorPixels, 0, 100, SocketFlags.None);
                    }
                    catch (SocketException ex)
                    {
                        Console.WriteLine("Socket dropped...");
                    }
                }
            }
        }
Example #5
0
 private void Runtime_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     if (this.ColorFrameReady != null)
     {
         this.ColorFrameReady(sender, e);
     }
 }
Example #6
0
        /// <summary>
        /// RGB カメラフレーム更新イベントハンドラ
        /// </summary>
        /// <param name="sender">Kinect センサー</param>
        /// <param name="e">イベント</param>
        private void _kinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if (!_drawEnable)
            {
                return;
            }

            KinectSensor kinect = sender as KinectSensor;

            if (kinect == null)
            {
                return;
            }

            // RGB カメラのフレームデータを取得する
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame == null)
                {
                    return;
                }

                EventHandler <ColorUpdateEventArgs> eventHandler = ColorUpdate;
                if (eventHandler != null)
                {
                    ColorUpdateEventArgs args = new ColorUpdateEventArgs();
                    args.Kinect     = kinect;
                    args.ColorFrame = colorFrame;
                    eventHandler(this, args);
                }
            }
        }
Example #7
0
        void runtime_VideoFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            bool receivedData = false;

            using (ColorImageFrame CFrame = e.OpenColorImageFrame())
            {
                if (CFrame == null)
                {
                    // process duurt te lang
                }
                else
                {
                    pixelData = new byte[CFrame.PixelDataLength];
                    CFrame.CopyPixelDataTo(pixelData);
                    receivedData = true;
                }
            }


            if (receivedData)
            {
                BitmapSource source = BitmapSource.Create(640, 480, 96, 96,
                                                          PixelFormats.Bgr32, null, pixelData, 640 * 4);

                /*BitmapSource source = BitmapSource.Create(640, 480, 96, 96,
                 *      PixelFormats.Bgr32, null, pixelData, 640 * 4);
                 */

                video.Source  = source; //Nu speel ik mijn bitmap door.
                video2.Source = source; //
            }
        }
Example #8
0
        void runtime_VideoFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            bool receivedData = false;

            using (ColorImageFrame CFrame = e.OpenColorImageFrame())
            {
                if (CFrame == null)
                {
                    // The image processing took too long. More than 2 frames behind.
                }
                else
                {
                    pixelData = new byte[CFrame.PixelDataLength];
                    CFrame.CopyPixelDataTo(pixelData);
                    receivedData = true;
                }
            }

            if (receivedData)
            {
                BitmapSource source = BitmapSource.Create(640, 480, 96, 96,
                                                          PixelFormats.Bgr32, null, pixelData, 640 * 4);

                videoImage.Source = source;
            }
        }
Example #9
0
        void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame frame = e.OpenColorImageFrame())
            {
                if (frame != null)
                {
                    byte[] pixelData = new byte[frame.PixelDataLength];
                    frame.CopyPixelDataTo(pixelData);
                    //for (int i = 0; i < pixelData.Length; i += frame.BytesPerPixel)
                    //{
                    //Only red
                    //pixelData[i] = 0x00;
                    //pixelData[i + 1] = 0x00;

                    //Inverted color
                    //pixelData[i] = (byte)~pixelData[i];
                    //pixelData[i + 1] = (byte)~pixelData[i + 1];
                    //pixelData[i + 2] = (byte)~pixelData[i + 2];

                    //Apocalyptic zombie
                    //pixelData[i] = pixelData[i + 1];
                    //pixelData[i + 1] = pixelData[i];
                    //pixelData[i + 2] = (byte)~pixelData[i + 2];

                    //Gray csale
                    //byte gray = Math.Max(pixelData[i], pixelData[i + 1]);
                    //gray = Math.Max(gray, pixelData[i + 2]);
                    //pixelData[i] = gray;
                    //pixelData[i + 1] = gray;
                    //pixelData[i + 2] = gray;

                    //Grain black and white movie
                    //byte gray = Math.Max(pixelData[i], pixelData[i + 1]);
                    //gray = Math.Max(gray, pixelData[i + 2]);
                    //pixelData[i] = gray;
                    //pixelData[i + 1] = gray;
                    //pixelData[i + 2] = gray;

                    //Washed out color
                    //double gray = (pixelData[i] * 0.11) + (pixelData[i + 1] * 0.59) + (pixelData[i + 2] * 0.3);
                    //double desaturation = 0.75;
                    //pixelData[i] = (byte)(pixelData[i] + desaturation * (gray - pixelData[i]));
                    //pixelData[i + 1] = (byte)(pixelData[i + 1] + desaturation * (gray - pixelData[i + 1]));
                    //pixelData[i + 2] = (byte)(pixelData[i + 2] + desaturation * (gray - pixelData[i + 2]));

                    //High saturation
                    //if (pixelData[i] < 0x33 || pixelData[i] > 0xE5) { pixelData[i] = 0x00; }
                    //else { pixelData[i] = 0xFF; }
                    //if (pixelData[i + 1] < 0x33 || pixelData[i + 1] > 0xE5) { pixelData[i + 1] = 0x00; }
                    //else { pixelData[i + 1] = 0xFF; }
                    //if (pixelData[i + 2] < 0x33 || pixelData[i + 2] > 0xE5) { pixelData[i + 2] = 0x00; }
                    //else { pixelData[i + 2] = 0xFF; }
                    //}
                    //ColorImageElement.Source = BitmapImage.Create(frame.Width, frame.Height, 96, 96,
                    //    PixelFormats.Bgr32, null, pixelData, frame.Width * frame.BytesPerPixel);

                    this.colorImageBitmap.WritePixels(this.colorImageBitmapRect, pixelData, this.colorImageStride, 0);
                }
            }
        }
        /// <summary>
        /// Handler for the Kinect sensor's ColorFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="colorImageFrameReadyEventArgs">event arguments</param>
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs colorImageFrameReadyEventArgs)
        {
            // Even though we un-register all our event handlers when the sensor
            // changes, there may still be an event for the old sensor in the queue
            // due to the way the KinectSensor delivers events.  So check again here.
            if (this.sensor != sender)
            {
                return;
            }

            using (var colorFrame = colorImageFrameReadyEventArgs.OpenColorImageFrame())
            {
                if (null != colorFrame)
                {
                    try
                    {
                        // Hand data to each handler to be processed
                        foreach (var handler in this.streamHandlers)
                        {
                            handler.ProcessColor(colorFrame.GetRawPixelData(), colorFrame);
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        // ColorFrame functions may throw when the sensor gets
                        // into a bad state.  Ignore the frame in that case.
                    }
                }
            }
        }
Example #11
0
 /// <summary>
 /// colorFrameReady() is an event handler that executes each time a new color frame is ready for retrieval from the Kinect
 /// </summary>
 /// <param name="sender"> object sending the event </param>
 /// <param name="e"> event arguments </param>
 void colorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     Console.WriteLine("Color Frame Ready for Processing");
     if (color_retrieved == false) // if we have not yet retrieved a color frame for processing
     {
         using (ColorImageFrame color_frame = e.OpenColorImageFrame())
         {
             if (color_frame != null)                                                                                                                     // check for an invalid frame
             {
                 sensor.Stop();                                                                                                                           // temporarily disable the Kinect sensor
                 color_data = new byte[sensor.ColorStream.FramePixelDataLength];                                                                          // allocate space to hold the color data
                 color_frame.CopyPixelDataTo(color_data);                                                                                                 // copy the color data to the array
                 color_bitmap = new WriteableBitmap(sensor.ColorStream.FrameHeight, sensor.ColorStream.FrameWidth, 96.0, 96.0, PixelFormats.Bgr32, null); // create a bitmap to hold the color data
                 try
                 {
                     // color_bitmap.WritePixels(new Int32Rect(0, 0, color_bitmap.PixelWidth, color_bitmap.PixelHeight), color_data, color_bitmap.PixelWidth * sizeof(int), 0); // write the color data to the bitmap
                 }
                 catch (IOException)
                 {
                     Console.WriteLine("ERROR: IOException");
                 }
                 // color_image.Source = color_bitmap;
                 saveImage(color_bitmap); // save the image
             }
             sensor.Start();              // restart the sensor
         }
         color_retrieved = true;          // indicates that a color frame has been retrieved and there is no need to retrieve another
         Console.WriteLine("Finished Processing Color Frame");
     }
 }
Example #12
0
        //ColorFrameReadyイベントのハンドラ(画像情報を取得して描画)
        private void ColorImageReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            try
            {
                using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
                {
                    if (imageFrame != null)
                    {
                        //画像情報の幅・高さ取得※途中で変わらない想定!
                        int frmWidth  = imageFrame.Width;
                        int frmHeight = imageFrame.Height;

                        //画像情報をバッファにコピー
                        imageFrame.CopyPixelDataTo(pixelBuffer);

                        //ビットマップに描画
                        Int32Rect src = new Int32Rect(0, 0, frmWidth, frmHeight);
                        bmpBuffer.WritePixels(src, pixelBuffer, frmWidth * 4, 0);
                    }
                }
            }
            catch
            {
                Console.WriteLine("エラーが発生しました。");
            }
        }
Example #13
0
        private void KinectOnColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if (!IsRunning)
            {
                return;
            }

            #region ColorFrameProcessing

            // Save the imageFrame data to a BitmapSource then fire the
            // ColorImageReady event.
            // Since the BitmapSource is a dependency object it is aware
            // of it's thread affinity and so Freeze() must be called
            // in order to allow the data to be read by the UI thread.
            // The creation of the BitmapSource is taken care of by the
            // extention method ToBitmapSource.
            using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
            {
                if (imageFrame != null)
                {
                    BitmapSource image = imageFrame.ToBitmapSource();
                    image.Freeze();

                    OnColorImageReady(image);
                }
            }
            #endregion
        }
Example #14
0
        void Sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
            {
                if (imageFrame != null)
                {
                    colorMap = new Texture2D(Game.GraphicsDevice, imageFrame.Width, imageFrame.Height);

                    byte[] data = new byte[imageFrame.PixelDataLength];
                    imageFrame.CopyPixelDataTo(data);

                    // Copy to Texture2D
                    //Flip the R with the B
                    for (int b = 0; b < data.Length; b += 4)
                    {
                        byte tmp = data[b];
                        data[b]     = data[b + 2];
                        data[b + 2] = tmp;
                    }

                    colorMap.SetData <byte>(data);
                }
                else
                {
                    // imageFrame is null because the request did not arrive in time          }
                }
            }
        }
        public void colorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                byte[] pixels = new byte[frame.PixelDataLength];
                frame.CopyPixelDataTo(pixels);

                Marshal.FreeHGlobal(colorPtr);
                colorPtr = Marshal.AllocHGlobal(pixels.Length);
                Marshal.Copy(pixels, 0, colorPtr, pixels.Length);

                int stride = frame.Width * 4;

                colorImage = new Bitmap(
                    frame.Width,
                    frame.Height,
                    stride,
                    PixelFormat.Format32bppRgb,
                    colorPtr);

                afterColorReady();
            }
        }
Example #16
0
        void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (var image = e.OpenColorImageFrame())
            {
                if (image == null)
                {
                    return;
                }

                if (colorBytes == null ||
                    colorBytes.Length != image.PixelDataLength)
                {
                    colorBytes = new byte[image.PixelDataLength];
                }

                image.CopyPixelDataTo(colorBytes);


                int length = colorBytes.Length;
                for (int i = 0; i < length; i += 4)
                {
                    colorBytes[i + 3] = 255;
                }

                BitmapSource source = BitmapSource.Create(image.Width,
                                                          image.Height,
                                                          96,
                                                          96,
                                                          PixelFormats.Bgra32,
                                                          null,
                                                          colorBytes,
                                                          image.Width * image.BytesPerPixel);
                videoImage.Source = source;
            }
        }
Example #17
0
        private void ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            ColorImageFrame frame = e.OpenColorImageFrame();

            if (frame != null)
            {
                if (frame.Format != this.oldformat)
                {
                    int bpp = frame.Format == ColorImageFormat.RgbResolution640x480Fps30 ? 4 : 2;
                    this.colorimage = new byte[640 * 480 * bpp];

                    this.oldformat = frame.Format;
                    this.DisposeTextures();
                }

                this.FInvalidate = true;
                this.frameindex  = frame.FrameNumber;

                lock (m_lock)
                {
                    frame.CopyPixelDataTo(this.colorimage);
                }

                frame.Dispose();
            }
        }
        /**
         * Desenhar o esqueleto do usuário.
         */
        void etecnect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame visualizacao = e.OpenColorImageFrame())
            {
                if (visualizacao == null)
                {
                    return;
                }

                if (info_cores_sensor_kinect == null)
                {
                    info_cores_sensor_kinect = new byte[visualizacao.PixelDataLength];
                }

                visualizacao.CopyPixelDataTo(info_cores_sensor_kinect);

                if (bmp_rgb_cores == null)
                {
                    this.bmp_rgb_cores = new WriteableBitmap(
                        visualizacao.Width,
                        visualizacao.Height,
                        96,
                        96,
                        PixelFormats.Bgr32,
                        null);
                }

                this.bmp_rgb_cores.WritePixels(new Int32Rect(0, 0, visualizacao.Width, visualizacao.Height), info_cores_sensor_kinect, visualizacao.Width * visualizacao.BytesPerPixel, 0);
                esqueletobugado.Background = new ImageBrush(bmp_rgb_cores);
            }
        }
Example #19
0
 void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     if (ImageFrameReady != null)
     {
         ImageFrameReady(this, e);
     }
 }
Example #20
0
        /* Function to print the scream */
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame == null)
                {
                    return;
                }
                if (colorData == null)
                {
                    colorData = new byte[colorFrame.PixelDataLength];
                }
                colorFrame.CopyPixelDataTo(colorData);

                Marshal.FreeHGlobal(colorPtr);
                colorPtr = Marshal.AllocHGlobal(colorData.Length);
                Marshal.Copy(colorData, 0, colorPtr, colorData.Length);

                kinectVideoBitmap = new Bitmap(colorFrame.Width,
                                               colorFrame.Height,
                                               colorFrame.Width * colorFrame.BytesPerPixel,
                                               PixelFormat.Format32bppRgb,
                                               colorPtr);

                pbKinectVideo.Image = kinectVideoBitmap;
            }
        }
Example #21
0
        /// <summary>
        /// Actualiza los datos recibidos de la camara sobre nuestro kinectRGBVideo
        /// </summary>
        void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorImageFrame = e.OpenColorImageFrame())
            {
                if (colorImageFrame != null)
                {
                    byte[] pixelsFromFrame = new byte[colorImageFrame.PixelDataLength];

                    colorImageFrame.CopyPixelDataTo(pixelsFromFrame);

                    Color[] color = new Color[colorImageFrame.Height * colorImageFrame.Width];
                    kinectRGBVideo = new Texture2D(graphics.GraphicsDevice, colorImageFrame.Width, colorImageFrame.Height);

                    // Recorre los pixels y asigna el byte adecuado a cada punto
                    // El indice se incrementa de 4 en 4 porque hay 3 colores: red, green, blue
                    // El bytemap pixelsFromFrame se compone de un array unidimensional
                    int index = 0;
                    for (int y = 0; y < colorImageFrame.Height; y++)
                    {
                        for (int x = 0; x < colorImageFrame.Width; x++, index += 4)
                        {
                            color[y * colorImageFrame.Width + x] = new Color(pixelsFromFrame[index + 2], pixelsFromFrame[index + 1], pixelsFromFrame[index + 0]);
                        }
                    }

                    // Actualizamos los datos de los pixels del ColorImageFrame a nuestra Texture2D
                    kinectRGBVideo.SetData(color);
                }
            }
        }
        private void Kinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame frame = e.OpenColorImageFrame())
            {
                if (frame != null)
                {
                    frame.CopyPixelDataTo(this._ColorImagePixelData);

                    FrameworkElement element = ImageTreatmentSelector.SelectedItem as FrameworkElement;

                    if (element != null)
                    {
                        string tagValue = (string)element.Tag;

                        switch (tagValue)
                        {
                        case "1":
                            ColorImageElement.Source = BitmapImage.Create(frame.Width, frame.Height, 96, 96, PixelFormats.Bgr32, null, this._ColorImagePixelData, frame.Width * frame.BytesPerPixel);
                            break;

                        case "2":
                            this.ColorImageElement.Source = this._ColorImageBitmap;
                            this._ColorImageBitmap.WritePixels(this._ColorImageBitmapRect, this._ColorImagePixelData, this._ColorImageStride, 0);
                            break;

                        case "3":
                            this.ColorImageElement.Source = this._ColorImageBitmap;
                            ShadePixelDataRed(this._ColorImagePixelData, frame);
                            this._ColorImageBitmap.WritePixels(this._ColorImageBitmapRect, this._ColorImagePixelData, this._ColorImageStride, 0);
                            break;
                        }
                    }
                }
            }
        }
Example #23
0
        //Gets color frame from kinect
        private void Ksensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            ColorImageFrame colorFrame = e.OpenColorImageFrame();
            BitmapSource    bmap       = ImageToBitmap(colorFrame);

            Colorstream.Source = bmap;

            //Each function executed every other time
            if (i == 1)
            {
                Imageprocessing.Proc(bmap, Canvas3, Outputstream);
                XB = Imageprocessing.XBlue;
                YB = Imageprocessing.YBlue;
                XR = Imageprocessing.XRed;
                YR = Imageprocessing.YRed;

                //Sets output screen
                Imageprocessing.OutputScreen(Outputstream, ObjectFrame);
                i = 0;
            }
            else
            {
                i = 1;
            }
        }
Example #24
0
 private void KSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (var Frame = e.OpenColorImageFrame())
     {
         pbstream.Image = CreateBitmapFromSensor(Frame);
     }
 }
Example #25
0
        private void CopyColorFrame(ColorImageFrameReadyEventArgs e)
        {
            using (var colorFrame = e.OpenColorImageFrame()) {
                if (colorFrame == null)
                {
                    return;
                }

                // Make a copy of the color frame for displaying.
                var haveNewFormat = _currentColorImageFormat != colorFrame.Format;
                if (haveNewFormat)
                {
                    _currentColorImageFormat  = colorFrame.Format;
                    _colorImageData           = new byte[colorFrame.PixelDataLength];
                    _colorImageWritableBitmap = new WriteableBitmap(colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null);

                    _colorImage.Source = _colorImageWritableBitmap;
                }

                colorFrame.CopyPixelDataTo(_colorImageData);
                _colorImageWritableBitmap.WritePixels(
                    new Int32Rect(0, 0, colorFrame.Width, colorFrame.Height),
                    _colorImageData,
                    colorFrame.Width * colorFrame.BytesPerPixel,
                    0);
            }
        }
Example #26
0
        }//voz

        void myKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame == null)
                {
                    return;
                }
                byte[] colorData = new byte[colorFrame.PixelDataLength];
                colorFrame.CopyPixelDataTo(colorData);
                //camara que siempre se muestra
                kinectVideo.Source = BitmapSource.Create(
                    colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel
                    );
                if (foto)//si se activa el comando de voz correspondiente se realiza una captura
                {
                    kinectVideo1.Source = BitmapSource.Create(
                        colorFrame.Width, colorFrame.Height,
                        96, 96,
                        PixelFormats.Bgr32,
                        null,
                        colorData,
                        colorFrame.Width * colorFrame.BytesPerPixel
                        );
                    foto = false;
                }
            }
        }
Example #27
0
 private void kinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (ColorImageFrame frame = e.OpenColorImageFrame())
     {
         if (frame != null)
         {
             KinectBase.ColorFrameEventArgs colorE = new KinectBase.ColorFrameEventArgs();
             colorE.kinectID = this.kinectID;
             if (frame.Format == ColorImageFormat.InfraredResolution640x480Fps30)
             {
                 colorE.pixelFormat = PixelFormats.Gray16;
                 colorE.isIR        = true;
             }
             else
             {
                 colorE.pixelFormat = PixelFormats.Bgr32;
                 colorE.isIR        = false;
             }
             colorE.width         = frame.Width;
             colorE.height        = frame.Height;
             colorE.bytesPerPixel = frame.BytesPerPixel;
             colorE.timeStamp     = new TimeSpan(frame.Timestamp * 10000); //Convert from milliseconds to ticks and set the time span
             //colorE.image = new byte[frame.PixelDataLength];
             colorE.image = colorImagePool.GetObject();                    //Get an array from the image pool
             if (colorE.image.Length != frame.PixelDataLength)             //If the image array is the wrong size, create a new one (it will get cycled into the pool on its own later)
             {
                 colorE.image = new byte[frame.PixelDataLength];
             }
             frame.CopyPixelDataTo(colorE.image);
             OnColorFrameReceived(colorE);
         }
     }
 }
Example #28
0
        void kinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            try
            {
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                {
                    if (colorFrame != null)
                    {
                        byte[] colorPixel = new byte[colorFrame.PixelDataLength];
                        colorFrame.CopyPixelDataTo(colorPixel);
                        imageRgb.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
                                                              PixelFormats.Bgr32, null, colorPixel, colorFrame.Width * colorFrame.BytesPerPixel);
                    }
                    FramesPerSecondElement.Text = string.Format("{0:0} fps", (this._TotalFrames++ / DateTime.Now.Subtract(this._StartFrameTime).TotalSeconds));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Vector4 accelerometer = kinect.AccelerometerGetCurrentReading();

            textAccelerometerX.Text = accelerometer.X.ToString();
            textAccelerometerY.Text = accelerometer.Y.ToString();
            textAccelerometerZ.Text = accelerometer.Z.ToString();

            textAngle.Text = GetAccelerometerAngle().ToString();

            textTiltAngle.Text = kinect.ElevationAngle.ToString();
        }
Example #29
0
        /// <summary>
        /// Event handler for Kinect sensor's ColorFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    colorFrame.CopyPixelDataTo(this.colorPixels);

                    Boolean Error = true;

                    // Write the pixel data into our bitmap
                    while (Error == true)
                    {
                        try
                        {
                            Error = false;
                            this.colorBitmap.WritePixels(
                                new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                                this.colorPixels,
                                this.colorBitmap.PixelWidth * sizeof(int),
                                0);
                        }
                        catch (System.Runtime.InteropServices.COMException)
                        {
                            Error = true;
                        }
                    }
                }
            }
        }
Example #30
0
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    colorFrame.CopyPixelDataTo(this.colorPixels);

                    KinectData kd = new KinectData(ColorWidth, ColorHeight);

                    kd.SetColorData(ImageToBitmap(colorFrame));

                    if (ObjectDetection)
                    {
                        List <DetectedObject> objs = ObjectDetector.FindObjects(kd.ColorImage, kd.Width, kd.Height);
                        kd.SetDetectedObjects(objs);
                    }

                    //sender matrix
                    if (Frame != null)
                    {
                        Frame(kd, e);
                    }
                }
            }
        }
 private void MyColorImageFrameReadyEventHandler(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (ColorImageFrame colorImageFrame = e.OpenFrame() as ColorImageFrame)
     {
         if (colorImageFrame != null)
         {
             rgbFrameRate.UpdateAvgFps();
         }
     }
 }
    private void MyColorImageFrameReadyEventHandler(object sender, ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame colorImageFrame = e.OpenFrame() as ColorImageFrame)
        {
            if (colorImageFrame != null)
            {
                if (newFrameId == colorImageFrame.FrameKey.FrameNumberKey)
                    return;

                ColorImage colorImage = colorImageFrame.ColorImage;
                newRgbImage = colorImage.Image;
                newFrameId = colorImageFrame.FrameKey.FrameNumberKey;

                if (SdkManager.IsDebugRun)
                {
                    Debug.Log ("Raw image frame: " + newFrameId);
                }
            }
        }
    }
    private void MyColorImageFrameReadyEventHandler(object sender, ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame colorImageFrame = e.OpenFrame() as ColorImageFrame)
        {
            if (colorImageFrame != null)
            {
                imageWarnings = colorImageFrame.Warnings;

                // some of the warnings are on the stream and not on the image itself.
                var colorImageStream = colorImageFrame.Stream as Xtr3D.Net.BaseTypes.ImageStreamBase<FrameKey, ColorImage>;
                imageSteamWarnings = colorImageStream.Warnings;
                StringBuilder sb = new StringBuilder();
                int warningsCount = CheckImageWarnings(sb);

                if (SdkManager.IsDebugRun)
                {
                    Debug.Log(String.Format("Warnings frame: {0}, contains {1} Warnings:\n{2}", colorImageFrame.FrameKey.FrameNumberKey, warningsCount, sb.ToString()));
                }
            }
        }
    }
        private void MyColorImageFrameReadyEventHandler(object sender, ColorImageFrameReadyEventArgs e)
        {
            // Opening the received frame
            using (var colorImageFrame = e.OpenFrame() as ColorImageFrame)
            {
                if (colorImageFrame != null) // Making sure it's really ColorImageFrame
                {
                    Console.WriteLine("Raw image frame: " + colorImageFrame.FrameKey.FrameNumberKey);
                    m_colorImageDrawer.DrawColorImage(colorImageFrame.ColorImage.Image); // Reading the ColorImage data
                    ColorImageDisplay.Source = m_colorImageDrawer.ImageSource;

                    var colorImageStream = colorImageFrame.Stream as ImageStreamBase<FrameKey, ColorImage>;
                    UpdateImageAndVideoWarnings(colorImageFrame.Warnings, colorImageStream.Warnings); // Reading both Image and ImageStream warnings
                }
            }
        }