예제 #1
0
        async void PreviewFrameAvailable(IImageSize imageSize)
        {
            if (!_Ready || _Rendering || _Done)
            {
                return;
            }
            _Rendering = true;

            await _Render.RenderAsync();

            Utilities.Dispatch(() =>
            {
                _Image.Invalidate();
            });

            if (_Controller.FocusControl.Supported)
            {
                if ((_Controller.FocusControl.FocusState != MediaCaptureFocusState.Searching) && (_Controller.FocusControl.FocusState != MediaCaptureFocusState.Focused))
                {
                    _Controller.FocusControl.FocusAsync();
                }
            }

            if (!_Controller.FocusControl.Supported || _Controller.FocusControl.FocusState == MediaCaptureFocusState.Focused)
            {
                //  extract codes
                if ((_CodesFound != null) || (_DataFound != null))
                {
                    if (_Controller.FocusControl.FocusState == MediaCaptureFocusState.Focused)
                    {
                        if (_Width == 0)
                        {
                            _Width = _Image.PixelWidth;
                        }
                        if (_Height == 0)
                        {
                            _Height = _Image.PixelHeight;
                        }
                        AddRemoveData(_Image.PixelBuffer.ToArray());
                        //if (_Threads < _MaxThreads)
                        //{
                        //    _Threads++;
                        //    var data = _Image.PixelBuffer.ToArray();
                        //    int width = _Image.PixelWidth, height = _Image.PixelHeight;
                        //    Task.Run(async () => FindCodes(data, width, height));
                        //}
                    }
                }
            }

            _Rendering = false;
        }
예제 #2
0
        private async void OnPreviewFrameAvailable(IImageSize imageSize)
        {
            if (!_isRendering)
            {
                _isRendering = true;
                await _writeableBitmapRenderer.RenderAsync();

                await
                CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.High,
                    () =>
                {
                    int bufferSize = _writeableBitmap.PixelWidth *_writeableBitmap.PixelHeight * 4;
                    if (_buffer == null || _buffer.Length != bufferSize)
                    {
                        _buffer = new byte[bufferSize];
                    }
                    IBuffer pixelBuffer = _writeableBitmap.PixelBuffer;
                    pixelBuffer.CopyTo(_buffer);

                    GCHandle handle = GCHandle.Alloc(_buffer, GCHandleType.Pinned);
                    using (
                        Mat m = new Mat(_writeableBitmap.PixelHeight, _writeableBitmap.PixelWidth,
                                        DepthType.Cv8U, 4,
                                        handle.AddrOfPinnedObject(), _writeableBitmap.PixelWidth * 4))
                        using (Mat gray = new Mat())
                            using (Mat canny = new Mat())
                            {
                                CvInvoke.CvtColor(m, gray, ColorConversion.Bgr2Gray);
                                CvInvoke.Canny(gray, canny, 40, 60);

                                CvInvoke.CvtColor(canny, m, ColorConversion.Gray2Bgra);
                            }
                    handle.Free();

                    using (Stream s = pixelBuffer.AsStream())
                    {
                        s.Write(_buffer, 0, _buffer.Length);
                    }

                    _writeableBitmap.Invalidate();
                });

                _isRendering = false;
            }
        }
예제 #3
0
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            if (!_initialized || _isRendering)
            {
                return;
            }

            _isRendering = true;

            await Task.Run(() => { _writeableBitmap.Invalidate(); });

            await _writeableBitmapRenderer.RenderAsync();

            await Task.Run(() => { Deocode(_writeableBitmap.PixelBuffer.ToArray(), BitmapFormat.Unknown); });

            _isRendering = false;
        }
예제 #4
0
        /// <summary>
        /// Render a frame with the selected filter
        /// </summary>
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            // Prevent multiple rendering attempts at once
            if (Initialized && !_isRendering)
            {
                _isRendering = true;


                // User changed the filter, let's update it before rendering



                // Render the image with the filter
                await _writeableBitmapRenderer.RenderAsync();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                            () =>
                {
                    TestWritableBitmap = _writeableBitmap;
                    Status             = "Trying to do something .. ";

                    //System.Drawing.Bitmap temp = (System.Drawing.Bitmap)_writeableBitmap;

                    //try
                    //{
                    //    frameCounter++;

                    //    if(frameCounter>10)
                    //    {
                    //        cards = recognizer.Recognize(temp);
                    //        frameCounter = 0;
                    //    }
                    //}
                    //catch
                    //{ }

                    _writeableBitmap.Invalidate();
                    Status = "Done Something";
                });

                _isRendering = false;
            }
        }
예제 #5
0
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            if (!_initialized || _isRendering)
            {
                return;
            }

            _isRendering = true;

            await Dispatcher.RunAsync(
                CoreDispatcherPriority.High,
                () =>
            {
                _writeableBitmap.Invalidate();
            });

            await _writeableBitmapRenderer.RenderAsync();

            Dispatcher.RunAsync(
                CoreDispatcherPriority.High,
                () =>
            {
                Deocode(_writeableBitmap.PixelBuffer.ToArray(), BitmapFormat.Unknown);
            });

            //FPS calculation
            var now   = DateTime.Now;
            var delta = now - _lastFrame;

            _lastFrame = now;

            var fps = 1000.0 / delta.TotalMilliseconds;

            await Dispatcher.RunAsync(
                CoreDispatcherPriority.High,
                () =>
            {
                FpsCounter.Text = String.Format("FPS: {0:0.0}", fps);
            });

            _isRendering = false;
        }
        /// <summary>
        /// Render a frame with the selected filter
        /// </summary>
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            // Prevent multiple rendering attempts at once
            if (Initialized && !_isRendering)
            {
                _isRendering = true;

                // User changed the filter, let's update it before rendering
                if (_changeFilterRequest)
                {
                    if (_filterList[_index].Type != null)
                    {
                        // Use reflection to create a new filter class
                        var filter = (IFilter)Activator.CreateInstance(_filterList[_index].Type, _filterList[_index].Parameters);

                        _effect.Filters = new[] { filter };
                    }
                    else
                    {
                        _effect.Filters = new IFilter[0];
                    }

                    _changeFilterRequest = false;
                }

                // Render the image with the filter
                await _writeableBitmapRenderer.RenderAsync();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                            () =>
                {
                    Status = _filterList[_index].Name;

                    _writeableBitmap.Invalidate();
                });

                _isRendering = false;
            }
        }
예제 #7
0
        }//initialize preview resources

        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            try
            {
                //render bitmap
                var renderTask = RenderAsync();
            }
            catch (OutOfMemoryException)
            {
                var dlg = new MessageDialog(Localize("memoryError"));
                await dlg.ShowAsync();

                Frame.Navigate(typeof(MainPage));
            }
            catch (Exception ex)
            {
                if (ex.HResult != -2005270523)
                {
                    Frame.Navigate(typeof(MainPage));
                }
            }
        }//render available bitmap
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            if (_sw.Elapsed > focus_period)
            {
                try
                {
                    focus_period = focus_period + TimeSpan.FromSeconds(5);
                    await vdc.FocusControl.FocusAsync();
                }
                catch { }
            }


            if (_sw.Elapsed > _timeout)
            {
                OnError(new TimeoutException("Could not find any barcode"));
            }
            else
            {
                _renderTask = Render();
            }
        }
예제 #9
0
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            if (!_initialized || _isRendering) 
                return;

            _isRendering = true;

            await Dispatcher.RunAsync(
                CoreDispatcherPriority.High,
                () =>
                {
                    _writeableBitmap.Invalidate();
                });

            await _writeableBitmapRenderer.RenderAsync();

            Dispatcher.RunAsync(
                CoreDispatcherPriority.High,
                () =>
                {
                    Deocode(_writeableBitmap.PixelBuffer.ToArray(), BitmapFormat.Unknown);
                });

            //FPS calculation
            var now = DateTime.Now;
            var delta = now - _lastFrame;
            _lastFrame = now;

            var fps = 1000.0/delta.TotalMilliseconds;

            await Dispatcher.RunAsync(
               CoreDispatcherPriority.High,
               () =>
               {
                   FpsCounter.Text = String.Format("FPS: {0:0.0}", fps);
               });

            _isRendering = false;
        }
 private void OnPreviewFrameAvailable(IImageSize args)
 {
     _renderTask = Render();
 }
예제 #11
0
 protected Image MakeImage(Guid id, string type, IImageSize imageSize)
 {
     return(MakeImage(id, type, imageSize.Width, imageSize.Height));
 }
예제 #12
0
        async void PreviewFrameAvailable(IImageSize imageSize)
        {
            if (!_Ready || _Rendering || _Done) return;
            _Rendering = true;

            await _Render.RenderAsync();

            Utilities.Dispatch(() =>
            {
                _Image.Invalidate();
            });

            if (_Controller.FocusControl.Supported)
            {
                if ((_Controller.FocusControl.FocusState != MediaCaptureFocusState.Searching) && (_Controller.FocusControl.FocusState != MediaCaptureFocusState.Focused)) _Controller.FocusControl.FocusAsync();
            }

            if (!_Controller.FocusControl.Supported || _Controller.FocusControl.FocusState == MediaCaptureFocusState.Focused)
            {
                //  extract codes
                if ((_CodesFound != null) || (_DataFound != null))
                {
                    if (_Controller.FocusControl.FocusState == MediaCaptureFocusState.Focused)
                    {
                        if (_Width == 0) _Width = _Image.PixelWidth;
                        if (_Height == 0) _Height = _Image.PixelHeight;
                        AddRemoveData(_Image.PixelBuffer.ToArray());
                        //if (_Threads < _MaxThreads)
                        //{
                        //    _Threads++;
                        //    var data = _Image.PixelBuffer.ToArray();
                        //    int width = _Image.PixelWidth, height = _Image.PixelHeight;
                        //    Task.Run(async () => FindCodes(data, width, height));
                        //}
                    }
                }
            }

            _Rendering = false;
        }
 private void OnPreviewFrameAvailable(IImageSize args)
 {
     _renderTask = Render();
 }
예제 #14
0
 public ImageData(BlockBase blockBase, byte blockTypeNumber, IImageSize imageSize)
     : base(blockBase)
 {
     BlockTypeNumber = blockTypeNumber;
     _imageSize      = imageSize;
 }
예제 #15
0
 public static void PopulateImageSize(this IImageSize image, Size size)
 {
     image.Width  = size.Width.ToString();
     image.Height = size.Height.ToString();
 }
예제 #16
0
 public ImageStripTable(BlockBase blockBase, IImageSize imageSize) : base(blockBase)
 {
     _imageSize = imageSize;
 }
예제 #17
0
 public static models.Image MakeImage(IRoadieSettings configuration, IHttpContext httpContext, Guid id, string type, IImageSize imageSize)
 {
     return(MakeImage(configuration, httpContext, id, type, imageSize.Width, imageSize.Height));
 }
예제 #18
0
 void OnPreviewFrameAvailable(IImageSize imageSize)
 {
     Utilities.Dispatch(() => PreviewFrameAvailable(imageSize));
 }
예제 #19
0
 public void SetImageSize(IImageSize imageSize)
 {
     _imageSize = imageSize;
 }
        /// <summary>
        /// Render a frame with the selected filter
        /// </summary>
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            // Prevent multiple rendering attempts at once
            if (Initialized && !_isRendering)
            {
                _isRendering = true;

                // User changed the filter, let's update it before rendering
                if (_changeFilterRequest)
                {
                    if (_filterList[_index].Type != null)
                    {
                        // Use reflection to create a new filter class
                        var filter = (IFilter)Activator.CreateInstance(_filterList[_index].Type, _filterList[_index].Parameters);

                        _effect.Filters = new[] { filter };
                    }
                    else
                    {
                        _effect.Filters = new IFilter[0];
                    }

                    _changeFilterRequest = false;
                }

                // Render the image with the filter
                await _writeableBitmapRenderer.RenderAsync();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                    () =>
                        {
                            Status = _filterList[_index].Name;

                            _writeableBitmap.Invalidate();
                        });

                _isRendering = false;
            }
        }
        /// <summary>
        /// Render a frame with the selected filter
        /// </summary>
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            // Prevent multiple rendering attempts at once
            if (Initialized && !isRendering)
            {
                isRendering = true;

                // Render the image with the filter
                await renderer.RenderAsync();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                    () =>
                    {
                        outputBitmap.Invalidate();
                    });

                isRendering = false;
            }
        }
예제 #22
0
 private void OnPreviewFrameAvailable(IImageSize args)
 {
     if (_sw.Elapsed > _timeout)
     {
         OnError(new TimeoutException("Could not find any barcode"));
     }
     else
     {
         _renderTask = Render();
     }
 }
예제 #23
0
 public static void PopulateImageSize(this IImageSize image, double width, double height)
 {
     image.Width  = width.ToString();
     image.Height = height.ToString();
 }
예제 #24
0
 void OnPreviewFrameAvailable(IImageSize imageSize)
 {
     Utilities.Dispatch(() => PreviewFrameAvailable(imageSize));
 }
예제 #25
0
      private async void OnPreviewFrameAvailable(IImageSize imageSize)
      {
         if (!_isRendering)
         {
            _isRendering = true;
            await _writeableBitmapRenderer.RenderAsync();
            await
               Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                  CoreDispatcherPriority.High,
                  () =>
                  {
                     int bufferSize = _writeableBitmap.PixelWidth * _writeableBitmap.PixelHeight * 4;
                     if (_buffer == null || _buffer.Length != bufferSize)
                        _buffer = new byte[bufferSize];
                     IBuffer pixelBuffer = _writeableBitmap.PixelBuffer;
                     pixelBuffer.CopyTo(_buffer);

                     GCHandle handle = GCHandle.Alloc(_buffer, GCHandleType.Pinned);
                     using (
                        Mat m = new Mat(_writeableBitmap.PixelHeight, _writeableBitmap.PixelWidth,
                           DepthType.Cv8U, 4,
                           handle.AddrOfPinnedObject(), _writeableBitmap.PixelWidth * 4))
                     using (Mat gray = new Mat())
                     using (Mat canny = new Mat())
                     {
                        CvInvoke.CvtColor(m, gray, ColorConversion.Bgr2Gray);
                        CvInvoke.Canny(gray, canny, 40, 60);
                        CvInvoke.CvtColor(canny, m, ColorConversion.Gray2Bgra);
                     }
                     handle.Free();
                     
                     using (Stream s = pixelBuffer.AsStream())
                     {
                        s.Write(_buffer, 0, _buffer.Length);
                     }
                    
                     _writeableBitmap.Invalidate();
                  });
            _isRendering = false; 
         }

      }
예제 #26
0
        /// <summary>
        /// Render a frame with the selected filter
        /// </summary>
        private async void OnPreviewFrameAvailable(IImageSize args)
        {
            // Prevent multiple rendering attempts at once
            if (Initialized && !_isRendering)
            {
                _isRendering = true;

                
                    // User changed the filter, let's update it before rendering

                

                // Render the image with the filter
                await _writeableBitmapRenderer.RenderAsync();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                    () =>
                        {
                            

                            TestWritableBitmap = _writeableBitmap;
                            Status = "Trying to do something .. ";

                            //System.Drawing.Bitmap temp = (System.Drawing.Bitmap)_writeableBitmap;

                            //try
                            //{
                            //    frameCounter++;

                            //    if(frameCounter>10)
                            //    {
                            //        cards = recognizer.Recognize(temp);
                            //        frameCounter = 0;
                            //    }
                            //}
                            //catch
                            //{ }

                            _writeableBitmap.Invalidate();
                            Status = "Done Something";
                        });

                _isRendering = false;

                
            }
        }