コード例 #1
0
ファイル: PtGreyCamera.cs プロジェクト: wpiyong/fancy
            override protected void OnImageEvent(ManagedImage image)
            {
                Dispatcher dispatcher = Dispatcher.CurrentDispatcher;

                dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
                Dispatcher.Run();
                _camera.OnImageGrabbed(image);
                //Console.WriteLine("capture image: {0}, exposure time: {1}", image.FrameID, image.ChunkData.ExposureTime);
                image.Release();
            }
コード例 #2
0
ファイル: PtGreyCamera.cs プロジェクト: wpiyong/n3
            override protected void OnImageEvent(ManagedImage image)
            {
                //Debug.WriteLine("OnImageEvent");

                try
                {
                    if (!image.IsIncomplete)
                    {
                        // Convert image
                        using (var temp = image.Convert(PixelFormatEnums.BGR8))
                        {
                            if (_imageQueue.Count <= 10)
                            {
                                _imageQueue.Enqueue(
                                    new PtGreyCameraImage
                                {
                                    FrameId   = image.FrameID,
                                    TimeStamp = image.TimeStamp,
                                    Image     = new System.Drawing.Bitmap(temp.bitmap)
                                }
                                    );
                            }
                            else
                            {
                                Debug.WriteLine("Dropped frame");
                            }
                        }
                    }
                    image.Release();
                }
                catch (SpinnakerException ex)
                {
                    Debug.WriteLine("Error: {0}", ex.Message);
                }
                catch (Exception ex1)
                {
                    Debug.WriteLine("Error: {0}", ex1.Message);
                }
                finally
                {
                    // Must manually release the image to prevent buffers on the camera stream from filling up
                    //image.Release();
                }
            }
コード例 #3
0
        override protected void OnImageEvent(ManagedImage image)
        {
            //Debug.WriteLine("OnImageEvent");
            try
            {
                Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
                dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
                Dispatcher.Run();

                if (!image.IsIncomplete)
                {
                    // test get image from file
                    //string currentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    //var tempFileNamePath = Path.Combine(currentDirectory, "laser_spot.bmp");
                    //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(tempFileNamePath);

                    //var bitmapData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
                    //            System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);
                    //var img = BitmapSource.Create(bitmapData.Width, bitmapData.Height, bmp.HorizontalResolution, bmp.VerticalResolution,
                    //            PixelFormats.Bgr24, null, bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
                    //bmp.UnlockBits(bitmapData);

                    // Convert image
                    image.ConvertToBitmapSource(PixelFormatEnums.BGR8, managedImageConverted);
                    BitmapSource img = managedImageConverted.bitmapsource.Clone();
                    img.Freeze();
                    RaiseImageChangedEvent(new ImageEventArgs(img));
                    //img.Dispatcher.InvokeShutdown();
                    if (_measuring && _imageQueue.Count <= 100)
                    {
                        imgCounter++;
                        lock (_locker)
                        {
                            var temp = image.Convert(PixelFormatEnums.BGR8);
                            _imageQueue.Enqueue(new PtGreyCameraImage
                            {
                                FrameId   = (ulong)imgCounter,
                                TimeStamp = (ulong)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds,
                                Image     = new System.Drawing.Bitmap(temp.bitmap)
                                            // for testing
                                            //Image = new System.Drawing.Bitmap(bmp)
                            }
                                                );
                        }
                        RaiseImageEnqueuedEvent(new ImageEnqueuedEventArgs(imgCounter));
                        _wh.Set();
                        Debug.WriteLine("enqueue frame: {0}", imgCounter);
                    }
                    else
                    {
                        //Debug.WriteLine("Dropped frame");
                    }
                }
                image.Release();
            }
            catch (SpinnakerException ex)
            {
                Debug.WriteLine("Error: {0}", ex.Message);
            }
            catch (Exception ex1)
            {
                Debug.WriteLine("Error: {0}", ex1.Message);
            }
            finally
            {
                GC.Collect();
            }
        }