void KinectSensorColorFrameReady(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 #2
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)
        {
            //drop the frame if you're not done with the last one
            if (!this.processingFrame)
            {
                this.processingFrame = true;
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                {
                    if (colorFrame != null)
                    {
                        // Copy the pixel data from the image to a temporary array
                        colorFrame.CopyPixelDataTo(this.colorPixels);

                        IntPtr filteredPixels = this.colorFilter.FilterFrame(this.colorPixels, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight);

                        this.colorBitmap.WritePixels(
                            new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                            filteredPixels,
                            this.colorPixels.Length,
                            this.colorBitmap.PixelWidth * sizeof(int));

                    }
                }
                this.processingFrame = false;
            }
        }
        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();
            }
        }
Example #4
0
        void SensorColorFrameReady(object sender, kinect.ColorImageFrameReadyEventArgs e)
        {
            using (kinect.ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {
                    // Copy the pixel data from the image to a temporary array
                    colorFrame.CopyPixelDataTo(this.colorFramePixels);

                    for (int i = 3; i < this.colorFramePixels.Length - 4; i += 4)
                    {
                        this.colorFramePixels[i] = 255;  // set the alpha to max
                    }

                    // Write the pixel data into our bitmap
                    this.colorBitmapVideo.WritePixels(
                        new Int32Rect(0, 0, this.colorBitmapVideo.PixelWidth, this.colorBitmapVideo.PixelHeight),
                        this.colorFramePixels,
                        this.colorBitmapVideo.PixelWidth * sizeof(int),
                        0);
                }
            }

            // draw a sighting frame for precise alignment:
            // Horisontally the frame spans 16.56 degrees on every side and 12.75 degrees either up or down (at 74" the size it covers is 44"W by 33.5"H, i.e. 33.12 degrees by 25.5 degrees)
            // see http://writeablebitmapex.codeplex.com/
            //int sightFrameColor = 255;  // Pbgra32
            Color sightFrameColor = Colors.Red;

            colorBitmapVideo.DrawLine((int)colorBitmapVideo.Width / 2, 0, (int)colorBitmapVideo.Width / 2, (int)colorBitmapVideo.Height, sightFrameColor);
            colorBitmapVideo.DrawLine(0, (int)colorBitmapVideo.Height / 2, (int)colorBitmapVideo.Width, (int)colorBitmapVideo.Height / 2, sightFrameColor);
            colorBitmapVideo.DrawRectangle((int)colorBitmapVideo.Width / 4, (int)colorBitmapVideo.Height / 4,
                                           (int)colorBitmapVideo.Width * 3 / 4, (int)colorBitmapVideo.Height * 3 / 4, sightFrameColor);
        }
Example #5
0
        public void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {
                    if (0 == (framesNum + 1) % BUFFERSIZE) //if buffer is full - empty buffer to file\s
                    {
                        for (int i = framesNum - BUFFERSIZE + 1; i < framesNum + 1; i++)
                        {
                            //  CreateThumbnail(@"images\color"+i+".bmp", ConvertWriteableBitmapToBitmapImage(colorBitmap[i%BUFFERSIZE]));
                            //AddBmpToAvi(@"images\video.avi", BitmapFromWriteableBitmap(colorBitmap[i % BUFFERSIZE]));
                        }

                    }

                    // Copy the pixel data from the image to a temporary array
                    colorFrame.CopyPixelDataTo(this.colorPixels);

                    // Write the pixel data into our bitmap

                    this.colorBitmap[framesNum % BUFFERSIZE].WritePixels(
                            new Int32Rect(0, 0, this.colorBitmap[framesNum % BUFFERSIZE].PixelWidth, this.colorBitmap[framesNum % BUFFERSIZE].PixelHeight),
                            this.colorPixels,
                            this.colorBitmap[framesNum % BUFFERSIZE].PixelWidth * sizeof(int),
                            0);
                    framesNum++;
                }
            }
        }
        /// <summary>
        /// Sets the data of ColorVideo.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="colorImageFrame"></param>
        public void KinectColorFrameReady(object sender, ColorImageFrameReadyEventArgs colorImageFrame)
        {
            //Get raw image
            ColorVideoFrame = colorImageFrame.OpenColorImageFrame();

            if (ColorVideoFrame != null)
            {
                //Create array for pixel data and copy it from the image frame
                PixelData = new Byte[ColorVideoFrame.PixelDataLength];
                ColorVideoFrame.CopyPixelDataTo(PixelData);

                //Convert RGBA to BGRA, Kinect and XNA uses different color-formats.
                BgraPixelData = new Byte[ColorVideoFrame.PixelDataLength];
                for (int i = 0; i < PixelData.Length; i += 4)
                {
                    BgraPixelData[i] = PixelData[i + 2];
                    BgraPixelData[i + 1] = PixelData[i + 1];
                    BgraPixelData[i + 2] = PixelData[i];
                    BgraPixelData[i + 3] = (Byte)255; //The video comes with 0 alpha so it is transparent
                }

                // Create a texture and assign the realigned pixels
                ColorVideo = new Texture2D(Graphics.GraphicsDevice, ColorVideoFrame.Width, ColorVideoFrame.Height);
                ColorVideo.SetData(BgraPixelData);
                ColorVideoFrame.Dispose();
            }
        }
Example #7
0
        void miKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame framesColor = e.OpenColorImageFrame())
            {
                if (framesColor == null) return;

                if (datosColor == null)
                    datosColor = new byte[framesColor.PixelDataLength];

                framesColor.CopyPixelDataTo(datosColor);

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

                this.colorImagenBitmap.WritePixels(
                    new Int32Rect(0, 0, framesColor.Width, framesColor.Height),
                    datosColor,
                    framesColor.Width * framesColor.BytesPerPixel, 
                    0  
                    );

                canvasEsqueleto.Background = new ImageBrush(colorImagenBitmap);
            }
        }
Example #8
0
 void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     if (this.ColorFrameReady != null)
     {
         this.ColorFrameReady(this, e);
     }
 }
        private void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if (Enabled)
            {
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                {
                    // can happen that we have to drop frames
                    if (null == colorFrame)
                    {
                        return;
                    }

                    height = colorFrame.Height;
                    width = colorFrame.Width;
                    bytesPerPixel = colorFrame.BytesPerPixel;

                    // TODO: does this remove the need to allocate the same space over and over again?
                    if (null == imageBuffer || imageBuffer.Length != colorFrame.PixelDataLength)
                    {
                        this.imageBuffer = new byte[colorFrame.PixelDataLength];
                    }

                    colorFrame.CopyPixelDataTo(this.imageBuffer);
                }
            }
        }
        /// <summary>
        /// Color frame main class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
            {
                // Check if the incoming frame is not null
                if (imageFrame != null)
                {
                    // Get the pixel data in byte array
                    this.pixelData = new byte[imageFrame.PixelDataLength];

                    // Copy the pixel data
                    imageFrame.CopyPixelDataTo(this.pixelData);

                    // assign the bitmap image source into image control
                    BitmapSource bitmapS = BitmapSource.Create(
                     imageFrame.Width,
                     imageFrame.Height,
                     96,
                     96,
                     PixelFormats.Bgr32,
                     null,
                     pixelData,
                     imageFrame.Width *4 );

                   // this.caller.setImg(bitmapS); //we send data to the caller class

                }
            }
        }
Example #11
0
        void miKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame framesImagen = e.OpenColorImageFrame()) {
                
                if (framesImagen == null) 
                    return;
                
                byte[] datosColor = new byte[framesImagen.PixelDataLength];
                
                framesImagen.CopyPixelDataTo(datosColor);

                if (grabarFoto)
                {
                    bitmapImagen = BitmapSource.Create(
                        framesImagen.Width, framesImagen.Height, 96, 96, PixelFormats.Bgr32, null,
                        datosColor, framesImagen.Width * framesImagen.BytesPerPixel);
                    grabarFoto = false;
                }
                
                colorStream.Source = BitmapSource.Create(
                    framesImagen.Width, framesImagen.Height, 
                    96, 
                    96, 
                    PixelFormats.Bgr32, 
                    null, 
                    datosColor, 
                    framesImagen.Width * framesImagen.BytesPerPixel
                    );
            }
        }
Example #12
0
        public void kinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            try
            {
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                {
                    if (colorFrame != null)
                    {
                        // RGBカメラのフレームデータを取得する
                        byte[] colorPixel = new byte[colorFrame.PixelDataLength];
                        colorFrame.CopyPixelDataTo(colorPixel);

                        // ピクセルデータをビットマップに変換する

                        mainWindow.imageRgb.Source = BitmapSource.Create(colorFrame.Width,
                            colorFrame.Height, 96, 96, PixelFormats.Bgr32, null,
                            colorPixel, colorFrame.Width * colorFrame.BytesPerPixel);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 /// <summary>
 /// RGBカメラのフレーム更新イベント
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void kinect_ColorFrameReady( object sender, ColorImageFrameReadyEventArgs e )
 {
     using ( var colorFrame = e.OpenColorImageFrame() ) {
         if ( colorFrame != null ) {
             imageRgbCamera.Source = colorFrame.ToBitmapSource();
         }
     }
 }
Example #14
0
 protected void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (var frame = e.OpenColorImageFrame()) {
         if (frame != null) {
             this.ProcessFrame(frame);
         }
     }
 }
Example #15
0
        public void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            if (bitmap == null) {
            bitmap = ((WSRKinect)WSRConfig.GetInstance().GetWSRMicro()).NewColorBitmap();
              }

              CheckQRCode();
        }
        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            var colorImageFrame = e.OpenColorImageFrame();
            if (colorImageFrame != null)
            {


                var faceDetection = new FaceDetectionRecognition();
                var pixelData = new byte[colorImageFrame.PixelDataLength];
                colorImageFrame.CopyPixelDataTo(pixelData);

                pictureBox3.Image = FaceDetectionRecognition.BytesToBitmap(pixelData, colorImageFrame.Height, colorImageFrame.Width);
                pictureBox3.Refresh();
                var detectedFace = faceDetection.GetDetectedFace(pixelData, colorImageFrame.Height, colorImageFrame.Width);



                if (detectedFace != null)
                {
                    pictureBox4.Image = detectedFace.Bitmap;
                    pictureBox4.Refresh();

                    if (_remainingShots > 0)
                    {
                        faceDetection.SaveNewDetectedFace(_tempName, detectedFace);
                        _remainingShots--;
                    }
                    else
                    {
                        var user = faceDetection.RecognizeFace(detectedFace);


                        if (user != null)
                        {
                            Console.WriteLine("I recognize you with a mouth!, your are: {0}", user.NickName);
                            pictureBox2.Image = user.Face.GetBitmap();
                            pictureBox2.Refresh();
                        }
                        else
                        {
                            Console.Clear();
                            Console.WriteLine("You are a new user, would you like to be added to the database? Y/N");
                            var key = Console.ReadKey();

                            if (key.KeyChar == 'Y' || key.KeyChar == 'y')
                            {
                                Console.WriteLine("Please provide a nick name for you: ");
                                var name = Console.ReadLine();

                                faceDetection.SaveNewDetectedFace(name, detectedFace);
                                _tempName = name;
                                _remainingShots = 39;
                            }
                        }
                    }
                }
            }
        }
 void kinect_ColorFrameReady( object sender, ColorImageFrameReadyEventArgs e )
 {
     // Disposableなのでusingでくくる
     using ( ColorImageFrame colorFrame = e.OpenColorImageFrame() ) {
         if ( colorFrame != null ) {
             imageRgbCamera.Source = colorFrame.ToBitmapSource();
         }
     }
 }
Example #18
0
        void miKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame framesImagen = e.OpenColorImageFrame()) {
                
                if (framesImagen == null) 
                    return;
                
                byte[] datosColor = new byte[framesImagen.PixelDataLength];
                
                framesImagen.CopyPixelDataTo(datosColor);

                if (grabarFoto)
                {
                    bitmapImagen = BitmapSource.Create(
                        framesImagen.Width, framesImagen.Height, 96, 96, PixelFormats.Bgr32, null,
                        datosColor, framesImagen.Width * framesImagen.BytesPerPixel);
                    grabarFoto = false;
                }

                if (WriteableBitmap.IsChecked == true)
                {
                    if (bitmapEficiente == null)
                    {
                        bitmapEficiente = new WriteableBitmap(
                            framesImagen.Width, framesImagen.Height,
                            96,
                            96,
                            PixelFormats.Bgr32,
                            null
                            );
                    }
                    bitmapEficiente.WritePixels(
                        new Int32Rect(0, 0, framesImagen.Width, framesImagen.Height),
                        datosColor,
                        framesImagen.Width * framesImagen.BytesPerPixel,
                        0
                        );

                    colorStream.Source = bitmapEficiente;
                }
                else
                {
                    colorStream.Source = BitmapSource.Create(
                        framesImagen.Width, framesImagen.Height,
                        96,
                        96,
                        PixelFormats.Bgr32,
                        null,
                        datosColor,
                        framesImagen.Width * framesImagen.BytesPerPixel
                        );
                }
            }
        }
Example #19
0
 void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     ColorImageFrame colorFrame = e.OpenColorImageFrame();
     if (colorFrame != null)
     {
         byte[] pixelData = new byte[colorFrame.PixelDataLength];
         colorFrame.CopyPixelDataTo(pixelData);
         BitmapSource source = BitmapSource.Create(640,480,96,96,PixelFormats.Bgr32, null, pixelData, 640*4);
         imgKinect.Source = source;
     }
 }
Example #20
0
 void myKinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (ColorImageFrame es = e.OpenColorImageFrame())
     {
         if (!(es == null))
         {
             byte[] bits = new byte[es.PixelDataLength];
             es.CopyPixelDataTo(bits);
             image1.Source = BitmapSource.Create(es.Width, es.Height, 96, 96, PixelFormats.Bgr32, null, bits, es.Width * es.BytesPerPixel);
         }
     }
 }
        private void ColorImageReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
            {
                if (imageFrame != null)
                {
                    // We need to detect if the format has changed.
                    bool haveNewFormat = this.lastImageFormat != imageFrame.Format;

                    if (haveNewFormat)
                    {
                        this.pixelData = new byte[imageFrame.PixelDataLength];
                    }

                    imageFrame.CopyPixelDataTo(this.pixelData);

                    // A WriteableBitmap is a WPF construct that enables resetting the Bits of the image.
                    // This is more efficient than creating a new Bitmap every frame.
                    if (haveNewFormat)
                    {
                        //kinectColorImage.Visibility = Visibility.Visible;
                        this.outputImage = new WriteableBitmap(
                            imageFrame.Width,
                            imageFrame.Height,
                            96,  // DpiX
                            96,  // DpiY
                            PixelFormats.Bgr32,
                            null);

                        this.kinectColorImage.Source = this.outputImage;
                    }

                    this.outputImage.WritePixels(
                        new Int32Rect(0, 0, imageFrame.Width, imageFrame.Height),
                        this.pixelData,
                        imageFrame.Width * Bgr32BytesPerPixel,
                        0);

                    this.lastImageFormat = imageFrame.Format;

                    var stream = new MemoryStream();
                    var encoder = new JpegBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(outputImage));
                    encoder.Save(stream);
                    byte[] buffer = stream.GetBuffer();
                    //gui.colorImage.Image = new System.Drawing.Bitmap(new MemoryStream(buffer));

                    stream.Close();

                    UpdateFrameRate();
                }
            }
        }
Example #22
0
 void Sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (var frame = e.OpenColorImageFrame())
     {
         if (frame != null)
         {
             if (_mode == Mode.Color)
             {
                 camera.Source = frame.ToBitmap();
             }
         }
     }
 }
Example #23
0
        void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            
            using (ColorImageFrame colorImageFrame = e.OpenColorImageFrame())
            {
                if (colorImageFrame == null)
                {
                    return;
                }

                this.Camera.Source = ImageFrameExtensions.ToBitmapSource(colorImageFrame);
            }
        }
Example #24
0
 /// <summary>
 /// 处理每一帧
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void _nui_ColorFrameReady(object sender, Microsoft.Kinect.ColorImageFrameReadyEventArgs e)
 {
     using (ColorImageFrame frame = e.OpenColorImageFrame())
     {
         if (frame == null)
         {
             return;
         }
         byte[] pixels = new byte[frame.PixelDataLength];
         frame.CopyPixelDataTo(pixels);
         // 通知对象进行处理
         _subject.Notify(pixels, frame.Width, frame.Height);
     }
 }
Example #25
0
        void Sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (var image = e.OpenColorImageFrame()) {
                if (image != null) {
                    if (this.data == null) {
                        this.data = new byte[image.PixelDataLength];
                    }
                    image.CopyPixelDataTo(this.data);

                    this.writeableBitmap.WritePixels(new Int32Rect(0, 0, image.Width, image.Height), data, image.Width * image.BytesPerPixel, 0);
                    this.OnNewDataAvailable();
                }
            }
        }
Example #26
0
        private void KinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using(ColorImageFrame cif = e.OpenColorImageFrame())
            {
                if(cif == null)
                {
                    return;
                }

                BitmapSource bs = cif.ToBitmapSource();
                Bitmap bmp = GetBitmapFromBitmapSource(bs);
                Image<Bgr, byte> currentFrame = new Image<Bgr, byte>(bmp);
                imageBox1.Image = currentFrame;
            }
        }
Example #27
0
 private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
     {
         if (colorFrame != null)
         {
             colorFrame.CopyPixelDataTo(myArray);
             myBitmap.WritePixels(
                 new Int32Rect(0, 0, myBitmap.PixelWidth, myBitmap.PixelHeight),
                 myArray,
                 myBitmap.PixelWidth * sizeof(int),
                 0);
         }
     }
 }
 /// <summary>
 /// RGBカメラの更新通知
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void kinect_ColorFrameReady( object sender, ColorImageFrameReadyEventArgs e )
 {
     try {
     // RGBカメラのフレームデータを取得する
     using ( ColorImageFrame colorFrame = e.OpenColorImageFrame() ) {
       if ( colorFrame != null ) {
     colorManager.Update( colorFrame );
     imageRgb.Source = colorManager.Bitmap;
       }
     }
       }
       catch ( Exception ex ) {
     MessageBox.Show( ex.Message );
       }
 }
        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);

                KinectVideo.Source = BitmapSource.Create(colorFrame.Width, colorFrame.Height, 96, 96,
                    PixelFormats.Bgr32, null, colorData, colorFrame.Width * colorFrame.BytesPerPixel);

                

            }
        }
Example #30
0
        /// <summary>
        /// The event called when a new color frame is recieved from a Kinect.
        /// </summary>
        /// <param name="sender">The Kinect that is calling this method.</param>
        /// <param name="e">The event arguements (such as the color image).</param>
        void mainForm_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            // Create a color frame to hold the color frame that was recieved.
            KinectSensor sensor = (KinectSensor)sender;
            // Create an image index.
            int imageIndex = 0;

            // Try to get the index associated with the Kinect's unique ID.
            if (KinectIDs.TryGetValue(sensor.UniqueKinectId, out imageIndex))
            {
                // Get the color frame from the device.
                ColorImageFrame frame = e.OpenColorImageFrame();
                // Set the picture box image at the specified index with the color image frame.
                setImage(imageIndex, frame);
            }
        }
Example #31
0
        void kinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame frameImagen = e.OpenColorImageFrame()) //openColorImageFrame comienza a recibir flujo de datos de la camara y con la estructura using se va eliminando para recibir mas flujo de datos
            {
                if (frameImagen == null) // si no recibe ningun flujo de datos muestra un valor nulo
                {
                    return;
                }
                byte[] datosColor = new byte[frameImagen.PixelDataLength];//el metodo pixelDataLength indica el tamaño del buffer de datos, eso lo convertimos en un array de tipo byte
                frameImagen.CopyPixelDataTo(datosColor);// hacemos peticion a frameImagen para copear datos del frame al buffer del arreglo, teniendo asi el tamaño de la imagen en el arreglo datos color
                mostrarVideo.Source = BitmapSource.Create(frameImagen.Width, frameImagen.Height,
                    96, 96, PixelFormats.Bgr32, null, datosColor,
                    frameImagen.Width * frameImagen.BytesPerPixel);//ancho imagen, alto , dpi (pts por pulgada) horizontales,dpi verticales, formato de pixeles ,valor nulo, arreglo de bytes (contenido de imagen),strike ancho por largo

            }
        }
Example #32
-1
        void myKinect_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame == null) return;

                bmap = OpenCV2WPFConverter.ColorImageFrameToBitmap(colorFrame);

                imgBgr = new Image<Bgr, Byte>(bmap);
                imgHsv = new Image<Hsv, Byte>(bmap);

                if (imgBgr == null || imgHsv == null) return;
                processedBgr = imgBgr.InRange(new Bgr(B_min, G_min, R_min), new Bgr(B_max, G_max, R_max));

                processedHsv = imgHsv.InRange(new Hsv(H_min, S_min, V_min), new Hsv(H_max, S_max, V_max));
                //0,130,0 ~ 120, 256, 120 for green color.
                processedBgr = processedBgr.SmoothGaussian(7);
                processedHsv = processedHsv.SmoothGaussian(7);

                CircleF[] circlesBgr = processedBgr.HoughCircles(cannyThreshold, circleAccumulatorThreshold
                    , 2, processedBgr.Height / 8 , 8, 40)[0];

                CircleF[] circlesHsv = processedBgr.HoughCircles(cannyThreshold, circleAccumulatorThreshold
                    , 2, processedHsv.Height / 8, 8, 40)[0];

                HsvCircleCount = 0;
                RgbCircleCount = 0;

                // Draw Circles for RBG video stream
                foreach (CircleF circle in circlesBgr)
                {

                    RgbCircleCount += 1;
                    imgBgr.Draw(circle, new Bgr(System.Drawing.Color.Bisque), 3);

                }

                // Draw Circles for HSV video stream
                foreach (CircleF circle in circlesHsv)
                {

                    HsvCircleCount += 1;
                    imgBgr.Draw(circle, new Bgr(System.Drawing.Color.Bisque), 3);

                }

                kinectVideo.Source = OpenCV2WPFConverter.ToBitmapSource(imgBgr);
                HsvVideo.Source = OpenCV2WPFConverter.ToBitmapSource(processedHsv);
                RgbVideo.Source = OpenCV2WPFConverter.ToBitmapSource(processedBgr);
                //control the distance of different circles!
                this.HsvCircleUI.Content = HsvCircleCount.ToString();
                this.RgbCircleUI.Content = RgbCircleCount.ToString();

            }
        }