예제 #1
0
        public void OnCameraLoaded(ICameraCaptureDevice captureDevice)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (this.State == ViewModelState.Loading)
                {
                    try
                    {
                        this.PreviewBrush         = new VideoBrush();
                        this.PreviewBrush.Stretch = Stretch.Uniform;
                        this.PreviewBrush.SetSource(captureDevice);
                        this.ViewfinderRotation = this.cameraEngine.ViewfinderRotation;

                        ApplyCameraSettings();

                        this.ReviewImageBitmap = new WriteableBitmap(
                            (int)captureDevice.PreviewResolution.Width,
                            (int)captureDevice.PreviewResolution.Height);

                        this.State = ViewModelState.Loaded;
                        CameraLoaded();
                    }
                    catch (ObjectDisposedException)
                    {
                        // It's possible that an unload operation was queued up and executed
                        // after this event was raised since it was dispatched over to the UI
                        // thread, so it is possible for the captureDevice to be disposed.
                    }
                }
            });
        }
예제 #2
0
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {
            if (isProcessing)
            {
                return;
            }

            cameraDevice.PreviewFrameAvailable -= previewFrameHandler;

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;

            if (pixels == null)
            {
                pixels = new byte[len];
            }
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width  = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();

            ta.height = height;
            ta.width  = width;
            ta.pixels = pixels;


            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {
                bw.RunWorkerAsync(ta);
            });
        }
예제 #3
0
        private void PhotoCaptureDevice_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (_active && !_processing && _device != null)
            {
                _processing = true;
                _device.PreviewFrameAvailable -= PhotoCaptureDevice_PreviewFrameAvailable;

                var width  = (uint)_device.PreviewResolution.Width;
                var height = (uint)_device.PreviewResolution.Height;

                byte[] buffer = new byte[width * height];

                sender.GetPreviewBufferY(buffer);

                var frame = new Frame()
                {
                    Buffer     = buffer,
                    Pitch      = width,
                    Format     = FrameFormat.Gray8,
                    Dimensions = new Windows.Foundation.Size(width, height)
                };

                Dispatcher.BeginInvoke(async() =>
                {
                    if (_active)
                    {
                        var tuple = await ProcessFrameAsync(frame);

                        _processing = false;

                        if (_active && _device != null)
                        {
                            if (tuple != null && ResultTextBlock.Text != tuple.Item1.Text)
                            {
                                _resultTuple = tuple;

                                ResultTextBlock.Text = _resultTuple.Item1.Text;
                                ResultImage.Source   = _resultTuple.Item2;

                                if (OpticalReaderTask.Instance.RequireConfirmation)
                                {
                                    ResultGrid.Visibility = System.Windows.Visibility.Visible;
                                }
                                else
                                {
                                    NavigationService.GoBack();
                                }
                            }

                            _device.PreviewFrameAvailable += PhotoCaptureDevice_PreviewFrameAvailable;
                        }
                    }
                    else
                    {
                        _processing = false;
                    }
                });
            }
        }
예제 #4
0
 private void PreviewFrame(ICameraCaptureDevice device, object obj)
 {
     if (_runningScan != null)
     {
         return;
     }
     _runningScan = new Task <Result>(AnalysePreview);
     _runningScan.Start();
 }
        void camera_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (updateRunning) return;

            updateRunning = true;
            camera.GetPreviewBufferArgb(previewtmp.Pixels);
            Dispatcher.BeginInvoke(() => {
                previewtmp.Pixels.CopyTo(preview.Pixels, 0);
                preview.Invalidate(); 
                updateRunning = false; });
        }
 public void LoadCamera(ICameraCaptureDevice camera)
 {
     if (VideoBrush == null && camera != null)
     {
         RunOnUIThread(() =>
         {
             VideoBrush         = new VideoBrush();
             VideoBrush.Stretch = Stretch.Uniform;
             VideoBrush.SetSource(camera);
             Rectangle.Fill = VideoBrush;
         });
     }
 }
 public void LoadCamera(ICameraCaptureDevice camera)
 {
     if (VideoBrush == null && camera != null)
     {
         RunOnUIThread(() =>
         {
             VideoBrush = new VideoBrush();
             VideoBrush.Stretch = Stretch.Uniform;
             VideoBrush.SetSource(camera);
             Rectangle.Fill = VideoBrush;
         });
     }
 }
예제 #8
0
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {
            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

            System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());



            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;

            if (pixels == null)
            {
                pixels = new byte[len];
            }
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width  = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();

            ta.height = height;
            ta.width  = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();

            bw1.WorkerReportsProgress      = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);
        }
예제 #9
0
        //void factory_Opened(object sender, EventArgs e)
        //{

        //imageSeqeuenceNumber = 0;
        //phoneService.BeginStartSession(0, (int)resolution.Width, (int)resolution.Height,
        //    a =>
        //    {
        //        phoneService.EndStartSession(a);
        //        cam.PreviewFrameAvailable += cam_PreviewFrameAvailable;
        //    }, null);
        //}

        void cam_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (Environment.TickCount - lastSendImageTick < sendImageInterval)
            {
                return;
            }

            int[] pixels = new int[(int)Math.Ceiling(resolution.Width * resolution.Height)];
            sender.GetPreviewBufferArgb(pixels);

            List <byte> buffer = new List <byte>(pixels.Length * 4);

            foreach (int v in pixels)
            {
                buffer.AddRange(BitConverter.GetBytes(v));
            }

            if (phoneService != null)
            {
                phoneService.BeginSendImage(DateTime.UtcNow.GetUnixTimestamp() - App.TimeDifference, buffer.ToArray(), SendImageCompleted, null);
            }
            sendImageInterval += 100;
            //Dispatcher.BeginInvoke(() => { txtDebug.Text = "sendImageInterval=" + sendImageInterval; });
        }
        async void camera_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (rendering) return;

            try
            {
                rendering = true;
                //camera.GetPreviewBufferArgb(buffer);
                camera.GetPreviewBufferYCbCr( buffer);

                if (false)
                {
                    await renderer1.RenderAsync();
                    await renderer2.RenderAsync();
                    await renderer3.RenderAsync();
                    await renderer4.RenderAsync();
                }
                else
                {
                    await Task.WhenAll(new Task[]
                             {
                                 renderer1.RenderAsync().AsTask(),
                                 renderer2.RenderAsync().AsTask(),
                                 renderer3.RenderAsync().AsTask(),
                                 renderer4.RenderAsync().AsTask()
                             });
                }

                Dispatcher.BeginInvoke( () =>
                    {
                        
                        b1.Invalidate();
                        b2.Invalidate();
                        b3.Invalidate();
                        b4.Invalidate();
                        rendering = false;
                    });




            }
            catch(Exception e)
            {
                rendering = false;
            }


        }
 private void Capture_PreviewFrameAvailable(ICameraCaptureDevice camera, object e)
 {
     FrameAvailable = true;
 }
예제 #12
0
 private void PreviewFrame(ICameraCaptureDevice device, object obj)
 {
     if (_runningScan != null)
         return;
     _runningScan = new Task<Result>(AnalysePreview);
     _runningScan.Start();
 }
예제 #13
0
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {
            if (closeScanner)
            {
                closeScanner = false;
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    string resultString  = "{\"type\":" + JsonHelper.Serialize("Cancel") + "}";
                    PluginResult pResult = new PluginResult(PluginResult.Status.OK, resultString);
                    pResult.KeepCallback = true;
                    MWBarcodeScanner.mwbScanner.DispatchCommandResult(pResult, MWBarcodeScanner.kallbackID);
                    if (this.NavigationService.CanGoBack)
                    {
                        this.NavigationService.GoBack();
                    }
                    return;
                });
            }

            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

            // System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;

            if (pixels == null)
            {
                pixels = new byte[len];
            }
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width  = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();

            ta.height = height;
            ta.width  = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();

            bw1.WorkerReportsProgress      = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);
        }
 private void Capture_PreviewFrameAvailable(ICameraCaptureDevice camera, object e)
 {
     FrameAvailable = true;
 }
        public void OnCameraLoaded(ICameraCaptureDevice captureDevice)
        {
            Dispatcher.BeginInvoke(() =>
            {
                if (this.State == ViewModelState.Loading)
                {
                    try
                    {
                        this.PreviewBrush = new VideoBrush();
                        this.PreviewBrush.Stretch = Stretch.Uniform;
                        this.PreviewBrush.SetSource(captureDevice);
                        this.ViewfinderRotation = this.cameraEngine.ViewfinderRotation;

                        ApplyCameraSettings();

                        this.ReviewImageBitmap = new WriteableBitmap(
                            (int)captureDevice.PreviewResolution.Width,
                            (int)captureDevice.PreviewResolution.Height);

                        this.State = ViewModelState.Loaded;
                        CameraLoaded();
                    }
                    catch (ObjectDisposedException)
                    {
                        // It's possible that an unload operation was queued up and executed 
                        // after this event was raised since it was dispatched over to the UI
                        // thread, so it is possible for the captureDevice to be disposed.
                    }
                }
            });
        }
예제 #16
0
        private void OnPreviewFrame(ICameraCaptureDevice sender, object args)
        {
            lock (_processing)
            {
                if (!_timer.IsRunning)
                {
                    _timer.Start();
                    Debug.WriteLine("Timer started!");
                }

                if (_waitForWb)
                {
                    if (_timer.ElapsedMilliseconds < WHITE_BALANCE_DELAY)
                    {
                        return;
                    }
                    _waitForWb = false;
                    Debug.WriteLine("Timer restarted after {0}ms.", _timer.ElapsedMilliseconds);
                    _timer.Restart();
                    return;
                }

                if (_settings.Torch && !_torched)
                {
                    Task t = ToggleTorch();
                    _torched = true;
                }

                var elapsedTime     = _timer.ElapsedMilliseconds;
                var currentInterval = _settings.Interval * _framesCaptured - (PREVIEW_FRAME_RATE_MS >> 1);

                if (elapsedTime >= currentInterval + _settings.Delay)
                {
                    if (_framesCaptured == 0)
                    {
                        Debug.WriteLine("Locking AWB & AE & AF");
                        sender.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters,
                                           AutoFocusParameters.Focus | AutoFocusParameters.Exposure | AutoFocusParameters.WhiteBalance
                                           );
                    }

                    _shutterSound.Play();

                    sender.GetPreviewBufferYCbCr(_frameBuffer);

                    ThreadPool.QueueUserWorkItem(new WaitCallback(FrameProcessor), new FrameProcessorData(_frameBuffer, elapsedTime, sender.PreviewResolution));

                    _framesCaptured++;
                    Debug.WriteLine("Frame #{0} captured at {1}ms.", _framesCaptured, elapsedTime);
                }
                else
                {
                    Debug.WriteLine("{0}ms.", elapsedTime);
                }

                if (_framesCaptured == _settings.Frames)
                {
                    Debug.WriteLine("All frames captured.");
                    sender.PreviewFrameAvailable -= OnPreviewFrame;
                    return;
                }
            }
        }
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {

            if (isProcessing)
            {
                return;
            }

            cameraDevice.PreviewFrameAvailable -= previewFrameHandler;

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;
            if (pixels == null)
                pixels = new byte[len];
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();
            ta.height = height;
            ta.width = width;
            ta.pixels = pixels;


            Deployment.Current.Dispatcher.BeginInvoke(delegate()
            {

                bw.RunWorkerAsync(ta);
            });

        }
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {

            if (closeScanner) {
                closeScanner = false;
                Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                   
                    string resultString = "{\"type\":" + JsonHelper.Serialize("Cancel") + "}";
                    PluginResult pResult = new PluginResult(PluginResult.Status.OK, resultString);
                    pResult.KeepCallback = true;
                    MWBarcodeScanner.mwbScanner.DispatchCommandResult(pResult, MWBarcodeScanner.kallbackID);
                    if (this.NavigationService.CanGoBack) { 
                        this.NavigationService.GoBack();
                    }
                   return;
               });
            }

            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

           // System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;
            if (pixels == null)
                pixels = new byte[len];
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();
            ta.height = height;
            ta.width = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();
            bw1.WorkerReportsProgress = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);

        }
예제 #19
0
        void cam_PreviewFrameAvailable(ICameraCaptureDevice device, object sender)
        {

            if (activeThreads >= param_maxThreads || resultDisplayed)
            {
                return;
            }


            if (isClosing)
            {
                return;
            }

            activeThreads++;

            System.Diagnostics.Debug.WriteLine("ActiveThreads: " + activeThreads.ToString());

           

            

            isProcessing = true;

            int len = (int)device.PreviewResolution.Width * (int)device.PreviewResolution.Height;
            if (pixels == null)
                pixels = new byte[len];
            device.GetPreviewBufferY(pixels);
            // Byte[] result = new Byte[10000];
            int width = (int)device.PreviewResolution.Width;
            int height = (int)device.PreviewResolution.Height;

            ThreadArguments ta = new ThreadArguments();
            ta.height = height;
            ta.width = width;
            ta.pixels = pixels;


            BackgroundWorker bw1 = new BackgroundWorker();
            bw1.WorkerReportsProgress = false;
            bw1.WorkerSupportsCancellation = false;
            bw1.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw1.RunWorkerAsync(ta);

        }
        private void PhotoCaptureDevice_PreviewFrameAvailable(ICameraCaptureDevice sender, object args)
        {
            if (_active && !_processing && _device != null)
            {
                _processing = true;
                _device.PreviewFrameAvailable -= PhotoCaptureDevice_PreviewFrameAvailable;

                var width = (uint)_device.PreviewResolution.Width;
                var height = (uint)_device.PreviewResolution.Height;

                byte[] buffer = new byte[width * height];

                sender.GetPreviewBufferY(buffer);

                var frame = new Frame()
                {
                    Buffer = buffer,
                    Pitch = width,
                    Format = FrameFormat.Gray8,
                    Dimensions = new Windows.Foundation.Size(width, height)
                };

                Dispatcher.BeginInvoke(async () =>
                {
                    if (_active)
                    {
                        var tuple = await ProcessFrameAsync(frame);

                        _processing = false;

                        if (_active && _device != null)
                        {
                            if (tuple != null && ResultTextBlock.Text != tuple.Item1.Text)
                            {
                                _resultTuple = tuple;

                                ResultTextBlock.Text = _resultTuple.Item1.Text;
                                ResultImage.Source = _resultTuple.Item2;

                                if (OpticalReaderTask.Instance.RequireConfirmation)
                                {
                                    ResultGrid.Visibility = System.Windows.Visibility.Visible;
                                }
                                else
                                {
                                    NavigationService.GoBack();
                                }
                            }

                            _device.PreviewFrameAvailable += PhotoCaptureDevice_PreviewFrameAvailable;
                        }
                    }
                    else
                    {
                        _processing = false;
                    }
                });
            }
        }