Exemplo n.º 1
0
 void kinectSensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
 {
     using (ColorImageFrame frame = e.OpenColorImageFrame())
     {
         if (frame != null)
         {
             // 这里用了C4F的ToBitmapSource
             ColorImageElement.Source = frame.ToBitmapSource();
         }
     }
 }
Exemplo n.º 2
0
        /**
         * Metoda handler pentru evenimentul creat de captarea imaginilor
         * prin camera web a senzorului.
         **/
        void ColorImageReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            bool receiveData = false;

            using (ColorImageFrame colorImageFrame = e.OpenColorImageFrame())
            {
                if (colorImageFrame != null)
                {
                    if (pixelData == null)
                    {
                        pixelData = new byte[colorImageFrame.PixelDataLength];
                    }
                    colorImageFrame.CopyPixelDataTo(pixelData);
                    receiveData = true;
                }
                else
                {
                    //nu s-au primit date
                }
                if (receiveData)
                {
                    image1.Source = colorImageFrame.ToBitmapSource();
                    //daca s-a apasat butonul "Captura" se incepe umplerea bufferului
                    if (startedCapture)
                    {
                        if (index == MAX_BUFFERED)
                        {
                            startedCapture  = false;
                            button1.Content = "Captura finalizata";
                            createMovie("D:\\teste\\original.avi", bufferedFrames);
                            button2.IsEnabled = true;
                        }
                        else
                        {
                            index++;
                            bufferedFrames.Add(BitmapFromSource(colorImageFrame.ToBitmapSource()));
                        }
                    }
                }
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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);
                    ////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);

                    ColorImageElement.Source = frame.ToBitmapSource();
                }
            }
        }
Exemplo n.º 5
0
        // Called when a new video frame is ready from the Kinect and the option to display it is turned on.
        public void NuiRuntime_VideoFrameReady(object sender, AllFramesReadyEventArgs e)
        {
            if (ShowCamera)
            {
                using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
                {
                    if (colorFrame == null)
                    {
                        return;
                    }

                    PART_KinectVideo.Source = colorFrame.ToBitmapSource();
                }
            }
            else
            {
                PART_KinectVideo.Source = null;
            }
        }
        private void Pulse()
        {
            using (ColorImageFrame imageFrame = _kinectSensor.ColorStream.OpenNextFrame(200))
            {
                if (imageFrame == null)
                {
                    return;
                }

                using (Image <Bgr, byte> image = imageFrame.ToOpenCVImage <Bgr, byte>())
                    using (MemStorage storage = new MemStorage()) //create storage for motion components
                    {
                        if (_forgroundDetector == null)
                        {
                            _forgroundDetector = new BGStatModel <Bgr>(image
                                                                       , Emgu.CV.CvEnum.BG_STAT_TYPE.GAUSSIAN_BG_MODEL);
                        }

                        _forgroundDetector.Update(image);

                        //update the motion history
                        _motionHistory.Update(_forgroundDetector.ForgroundMask);

                        //get a copy of the motion mask and enhance its color
                        double[] minValues, maxValues;
                        System.Drawing.Point[] minLoc, maxLoc;
                        _motionHistory.Mask.MinMax(out minValues, out maxValues
                                                   , out minLoc, out maxLoc);
                        Image <Gray, Byte> motionMask = _motionHistory.Mask
                                                        .Mul(255.0 / maxValues[0]);

                        //create the motion image
                        Image <Bgr, Byte> motionImage = new Image <Bgr, byte>(motionMask.Size);
                        motionImage[0] = motionMask;

                        //Threshold to define a motion area
                        //reduce the value to detect smaller motion
                        double minArea = 100;

                        storage.Clear(); //clear the storage
                        Seq <MCvConnectedComp> motionComponents = _motionHistory.GetMotionComponents(storage);
                        bool isMotionDetected = false;
                        //iterate through each of the motion component
                        for (int c = 0; c < motionComponents.Count(); c++)
                        {
                            MCvConnectedComp comp = motionComponents[c];
                            //reject the components that have small area;
                            if (comp.area < minArea)
                            {
                                continue;
                            }

                            OnDetection();
                            isMotionDetected = true;
                            break;
                        }
                        if (isMotionDetected == false)
                        {
                            OnDetectionStopped();
                            this.Dispatcher.Invoke(new Action(() => rgbImage.Source = null));
                            StopRecording();
                            return;
                        }

                        this.Dispatcher.Invoke(
                            new Action(() => rgbImage.Source = imageFrame.ToBitmapSource())
                            );
                        Record(imageFrame);
                    }
            }
        }