// This method is called whenever objects are updated and it's the right place to react to the tracking results.
 public void OnSessionUpdated(BarcodeTracking barcodeTracking, BarcodeTrackingSession session, IFrameData frameData)
 {
     DispatchQueue.MainQueue.DispatchAsync(() =>
     {
         if (!this.barcodeTracking.Enabled)
         {
             return;
         }
         foreach (var identifier in session.RemovedTrackedBarcodes)
         {
             this.overlays.Remove(identifier);
         }
         var filteredTrackedCodes = session.TrackedBarcodes.Values.Where(code => code != null && code.Barcode != null && !string.IsNullOrEmpty(code.Barcode.Data));
         foreach (var trackedCode in filteredTrackedCodes)
         {
             var success = this.overlays.TryGetValue(trackedCode.Identifier, out UIView overlay);
             if (!success)
             {
                 return;
             }
             overlay.Hidden = this.ShouldHideOverlay(trackedCode, this.captureView.Frame.Width);
         }
     });
     // Dispose the frame when you have finished processing it. If the frame is not properly disposed,
     // different issues could arise, e.g. a frozen, non-responsive, or "severely stuttering" video feed.
     frameData.Dispose();
 }
Exemplo n.º 2
0
        private DataCaptureManager()
        {
            // The barcode tracking process is configured through barcode tracking settings
            // which are then applied to the barcode tracking instance that manages barcode recognition and tracking.
            BarcodeTrackingSettings barcodeTrackingSettings = BarcodeTrackingSettings.Create();

            // The settings instance initially has all types of barcodes (symbologies) disabled.
            // For the purpose of this sample we enable a generous set of symbologies.
            // In your own app ensure that you only enable the symbologies that your app requires
            // as every additional enabled symbology has an impact on processing times.
            HashSet <Symbology> symbologies = new HashSet <Symbology>
            {
                Symbology.Ean13Upca,
                Symbology.Ean8,
                Symbology.Upce,
                Symbology.Code39,
                Symbology.Code128
            };

            barcodeTrackingSettings.EnableSymbologies(symbologies);

            CameraSettings cameraSettings = BarcodeTracking.RecommendedCameraSettings;

            cameraSettings.PreferredResolution = VideoResolution.FullHd;
            this.Camera?.ApplySettingsAsync(cameraSettings);

            // Create data capture context using your license key and set the camera as the frame source.
            this.DataCaptureContext = DataCaptureContext.ForLicenseKey(SCANDIT_LICENSE_KEY);
            this.DataCaptureContext.SetFrameSourceAsync(this.Camera);

            // Create new barcode tracking mode with the settings from above.
            this.BarcodeTracking = BarcodeTracking.Create(this.DataCaptureContext, barcodeTrackingSettings);
        }
        private void InitializeAndStartBarcodeScanning()
        {
            // Create data capture context using your license key.
            this.dataCaptureContext = DataCaptureContext.ForLicenseKey(SCANDIT_LICENSE_KEY);

            // Use the default camera and set it as the frame source of the context.
            // The camera is off by default and must be turned on to start
            // streaming frames to the data capture context for recognition.
            // See ResumeFrameSource and OnPause methods.
            this.camera = Camera.GetDefaultCamera();

            if (this.camera != null)
            {
                // Use the recommended camera settings for the BarcodeTracking mode.
                CameraSettings cameraSettings = BarcodeTracking.RecommendedCameraSettings;
                // Adjust camera settings - set Full HD resolution.
                cameraSettings.PreferredResolution = VideoResolution.FullHd;
                this.camera.ApplySettingsAsync(cameraSettings);
                this.dataCaptureContext.SetFrameSourceAsync(this.camera);
            }

            // The barcode tracking process is configured through barcode tracking settings
            // which are then applied to the barcode tracking instance that manages barcode tracking.
            BarcodeTrackingSettings barcodeTrackingSettings = BarcodeTrackingSettings.Create();

            // The settings instance initially has all types of barcodes (symbologies) disabled.
            // For the purpose of this sample we enable a very generous set of symbologies.
            // In your own app ensure that you only enable the symbologies that your app requires
            // as every additional enabled symbology has an impact on processing times.
            HashSet <Symbology> symbologies = new HashSet <Symbology>();

            symbologies.Add(Symbology.Ean13Upca);
            symbologies.Add(Symbology.Ean8);
            symbologies.Add(Symbology.Upce);
            symbologies.Add(Symbology.Code39);
            symbologies.Add(Symbology.Code128);

            barcodeTrackingSettings.EnableSymbologies(symbologies);

            // Create barcode tracking and attach to context.
            this.barcodeTracking = BarcodeTracking.Create(this.dataCaptureContext, barcodeTrackingSettings);

            // Register self as a listener to get informed of tracked barcodes.
            this.barcodeTracking.AddListener(this);

            // To visualize the on-going barcode tracking process on screen, setup a data capture view
            // that renders the camera preview. The view must be connected to the data capture context.
            this.dataCaptureView = DataCaptureView.Create(this, this.dataCaptureContext);

            // Create barcode tracking overlay to the data capture view to render the tracked barcodes on
            // top of the video preview. This is optional, but recommended for better visual feedback.
            BarcodeTrackingBasicOverlay.Create(this.barcodeTracking, this.dataCaptureView);

            // Add the DataCaptureView to the container.
            FrameLayout container = this.FindViewById <FrameLayout>(Resource.Id.data_capture_view_container);

            container.AddView(this.dataCaptureView);
        }
        private void SetupRecognition()
        {
            // Create data capture context using your license key.
            this.context = DataCaptureContextExtensions.LicensedContext;

            // Use the camera and set it as the frame source of the context. The camera is off by
            // default and must be turned on to start streaming frames to the data capture context for recognition.
            // See viewWillAppear and viewDidDisappear above.
            this.context.SetFrameSourceAsync(this.camera);

            // Use the recommended camera settings for the BarcodeTracking mode as default settings.
            // The preferred resolution is automatically chosen, which currently defaults to HD on all devices.
            // Setting the preferred resolution to full HD helps to get a better decode range.
            var cameraSettings = BarcodeTracking.RecommendedCameraSettings;

            cameraSettings.PreferredResolution = VideoResolution.Uhd4k;
            this.camera?.ApplySettingsAsync(cameraSettings);

            // The barcode tracking process is configured through barcode tracking settings
            // and are then applied to the barcode tracking instance that manages barcode tracking.
            var settings = BarcodeTrackingSettings.Create(BarcodeTrackingScenario.A);

            // The settings instance initially has all types of barcodes (symbologies) disabled. For the purpose of this
            // sample we enable a very generous set of symbologies. In your own app ensure that you only enable the
            // symbologies that your app requires as every additional enabled symbology has an impact on processing times.
            settings.EnableSymbologies(new HashSet <Symbology>
            {
                Symbology.Ean13Upca,
                Symbology.Ean8,
                Symbology.Upce,
                Symbology.Code39,
                Symbology.Code128
            });

            // Create new barcode tracking mode with the settings from above.
            this.barcodeTracking = BarcodeTracking.Create(this.context, settings);

            this.barcodeTracking.AddListener(this);

            // To visualize the on-going barcode tracking process on screen, setup a data capture view that renders the
            // camera preview. The view must be connected to the data capture context.
            this.captureView = DataCaptureView.Create(this.context, this.View.Bounds);
            this.captureView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(this.captureView);
            this.View.SendSubviewToBack(this.captureView);

            // Add a barcode tracking overlay to the data capture view to render the tracked barcodes on top of the video
            // preview. This is optional, but recommended for better visual feedback. The overlay is automatically added
            // to the view.
            this.basicOverlay          = BarcodeTrackingBasicOverlay.Create(this.barcodeTracking, this.captureView);
            this.basicOverlay.Listener = this;

            // Add another barcode tracking overlay to the data capture view to render other views. The overlay is
            // automatically added to the view.
            this.advancedOverlay          = BarcodeTrackingAdvancedOverlay.Create(this.barcodeTracking, this.captureView);
            this.advancedOverlay.Listener = this;
        }
        protected void InitializeAndStartBarcodeScanning()
        {
            // Create data capture context using your license key.
            this.dataCaptureContext = DataCaptureContext.ForLicenseKey(SCANDIT_LICENSE_KEY);

            // Use the default camera and set it as the frame source of the context.
            // The camera is off by default and must be turned on to start streaming frames to the data
            // capture context for recognition.
            // See resumeFrameSource and pauseFrameSource below.
            this.camera = Camera.GetDefaultCamera();
            if (this.camera != null)
            {
                // Use the settings recommended by barcode capture.
                this.dataCaptureContext.SetFrameSourceAsync(this.camera);
            }

            // Use the recommended camera settings for the BarcodeTracking mode as default settings.
            // The preferred resolution is automatically chosen, which currently defaults to HD on all devices.
            CameraSettings cameraSettings = BarcodeTracking.RecommendedCameraSettings;

            // Setting the preferred resolution to full HD helps to get a better decode range.
            cameraSettings.PreferredResolution = VideoResolution.FullHd;
            camera?.ApplySettingsAsync(cameraSettings);
            BarcodeTrackingSettings barcodeTrackingSettings = BarcodeTrackingSettings.Create();

            // The settings instance initially has all types of barcodes (symbologies) disabled.
            // For the purpose of this sample we enable a very generous set of symbologies.
            // In your own app ensure that you only enable the symbologies that your app requires as
            // every additional enabled symbology has an impact on processing times.
            HashSet <Symbology> symbologies = new HashSet <Symbology>()
            {
                Symbology.Ean13Upca,
                Symbology.Ean8,
                Symbology.Upce,
                Symbology.Code39,
                Symbology.Code128
            };

            barcodeTrackingSettings.EnableSymbologies(symbologies);

            // Create new barcode tracking mode with the settings from above.
            this.barcodeTracking = BarcodeTracking.Create(this.dataCaptureContext, barcodeTrackingSettings);

            // Register self as a listener to get informed whenever a new barcode got recognized.
            this.barcodeTracking.AddListener(this);

            // To visualize the on-going barcode tracking process on screen, setup a data capture view
            // that renders the camera preview. The view must be connected to the data capture context.
            var dataCaptureView = DataCaptureView.Create(this.dataCaptureContext, this.View.Bounds);

            dataCaptureView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight |
                                               UIViewAutoresizing.FlexibleWidth;
            this.View.AddSubview(dataCaptureView);
            this.View.SendSubviewToBack(dataCaptureView);
            BarcodeTrackingBasicOverlay.Create(this.barcodeTracking, dataCaptureView);
        }
 public void OnSessionUpdated(BarcodeTracking barcodeTracking, BarcodeTrackingSession session, IFrameData frameData)
 {
     lock (scanResults)
     {
         foreach (var trackedBarcode in
                  session.AddedTrackedBarcodes.Where(trb => IsValidBarcode(trb.Barcode)))
         {
             scanResults.Add(new ScanResult(trackedBarcode.Barcode));
         }
     }
 }
        public void OnSessionUpdated(BarcodeTracking barcodeTracking, BarcodeTrackingSession session, IFrameData frameData)
        {
            var products = session.TrackedBarcodes.Values
                           .Select(trackedBarcode => trackedBarcode.Barcode)
                           .Where(barcode => barcode.Data != null)
                           .Select(barcode => Model.Product.Create(barcode.Data, barcode.Symbology.HumanReadableName()));

            if (this.Element?.BindingContext is MainViewModel viewModel)
            {
                viewModel.ScannedProducts = products.ToList();
            }
        }
 public void OnSessionUpdated(BarcodeTracking barcodeCapture, BarcodeTrackingSession session, IFrameData frameData)
 {
     lock (this.scanResults)
     {
         foreach (var trackedBarcode in session.AddedTrackedBarcodes)
         {
             this.scanResults.Add(new ScanResult
             {
                 Data      = trackedBarcode.Barcode.Data,
                 Symbology = SymbologyDescription.Create(trackedBarcode.Barcode.Symbology).ReadableName
             });
         }
     }
 }
        public void OnSessionUpdated(BarcodeTracking barcodeTracking, BarcodeTrackingSession session, IFrameData frameData)
        {
            DispatchQueue.MainQueue.DispatchAsync(() =>
            {
                this.scanResults = session.TrackedBarcodes?.Values.Select(v => new ScanResult
                {
                    Data      = v.Barcode.Data,
                    Symbology = v.Barcode.Symbology.ReadableName()
                }).ToHashSet();
            });

            // Dispose the frame when you have finished processing it. If the frame is not properly disposed,
            // different issues could arise, e.g. a frozen, non-responsive, or "severely stuttering" video feed.
            frameData.Dispose();
        }
Exemplo n.º 10
0
        public void OnSessionUpdated(BarcodeTracking barcodeTracking, BarcodeTrackingSession session, IFrameData frameData)
        {
            // This method is called whenever objects are updated and it's the right place to react to the tracking results.
            var products = session.TrackedBarcodes.Values
                           .Select(trackedBarcode => trackedBarcode.Barcode)
                           .Where(barcode => barcode.Data != null)
                           .Select(barcode => Model.Product.Create(barcode.Data, barcode.Symbology.HumanReadableName()));

            if (this.Element?.BindingContext is MainViewModel viewModel)
            {
                viewModel.ScannedProducts = products.ToList();
            }

            frameData.Dispose();
        }
        public void OnSessionUpdated(
            BarcodeTracking barcodeTracking,
            BarcodeTrackingSession session,
            IFrameData data)
        {
            if (this.IsFrozen() || this.listener == null)
            {
                return;
            }

            foreach (int identifier in session.RemovedTrackedBarcodes)
            {
                this.RemoveBubbleViewForIdentifierOnMainThread(identifier);
            }

            foreach (TrackedBarcode trackedBarcode in session.TrackedBarcodes.Values)
            {
                if (!string.IsNullOrEmpty(trackedBarcode.Barcode.Data))
                {
                    // We show or hide the bubble depending on its size compared to the device screen.
                    this.SetBubbleVisibilityOnMainThread(trackedBarcode, this.listener.ShouldShowBubble(trackedBarcode));
                }
            }
        }
 public void OnObservationStopped(BarcodeTracking barcodeTracking)
 {
 }
        private void Initialize()
        {
            // Create data capture context using your license key.
            dataCaptureContext = DataCaptureContext.ForLicenseKey(SCANDIT_LICENSE_KEY);

            // Use the recommended camera settings for the BarcodeTracking mode.
            var cameraSettings = BarcodeTracking.RecommendedCameraSettings;

            // Adjust camera settings - set Full HD resolution.
            cameraSettings.PreferredResolution = VideoResolution.FullHd;
            // Use the default camera and set it as the frame source of the context.
            // The camera is off by default and must be turned on to start streaming frames to the data
            // capture context for recognition.
            // See resumeFrameSource and pauseFrameSource below.
            camera = Camera.GetDefaultCamera(cameraSettings);

            if (camera == null)
            {
                throw new NullReferenceException(
                          "Sample depends on a camera, which failed to initialize.");
            }

            dataCaptureContext.SetFrameSourceAsync(camera);

            // The barcode tracking process is configured through barcode tracking settings
            // which are then applied to the barcode tracking instance that manages barcode tracking.
            var barcodeTrackingSettings = BarcodeTrackingSettings.Create();

            // The settings instance initially has all types of barcodes (symbologies) disabled.
            // For the purpose of this sample we enable a very generous set of symbologies.
            // In your own app ensure that you only enable the symbologies that your app requires
            // as every additional enabled symbology has an impact on processing times.
            var symbologies = new HashSet <Symbology>
            {
                Symbology.Ean13Upca,
                Symbology.Ean8,
                Symbology.Upce,
                Symbology.Code39,
                Symbology.Code128
            };

            barcodeTrackingSettings.EnableSymbologies(symbologies);

            // Create barcode tracking and attach to context.
            barcodeTracking = BarcodeTracking.Create(dataCaptureContext, barcodeTrackingSettings);

            // Register self as a listener to get informed of tracked barcodes.
            barcodeTracking.AddListener(this);

            // To visualize the on-going barcode tracking process on screen, setup a data capture view
            // that renders the camera preview. The view must be connected to the data capture context.
            var dataCaptureView = DataCaptureView.Create(this, dataCaptureContext);

            // Add a barcode tracking overlay to the data capture view to render the tracked barcodes on
            // top of the video preview. This is optional, but recommended for better visual feedback.
            var overlay =
                BarcodeTrackingBasicOverlay.Create(barcodeTracking, dataCaptureView);

            // Configure how barcodes are highlighted - apply default brush or create your own.
            // final Brush defaultBrush = new Brush(Color.BLUE, Color.RED, 5f);
            defaultBrush  = overlay.Brush;
            overlay.Brush = defaultBrush;

            var rejectedFillColor   = ContextCompat.GetColor(this, Resource.Color.barcode_rejected);
            var rejectedBorderColor = ContextCompat.GetColor(this, Resource.Color.barcode_rejected_border);

            rejectedBrush    = new Brush(rejectedFillColor, rejectedBorderColor, 1f);
            overlay.Listener = this;

            // Add the DataCaptureView to the container.
            var container = FindViewById <FrameLayout>(Resource.Id.data_capture_view_container);

            container.AddView(dataCaptureView);
        }
 public void OnObservationStarted(BarcodeTracking barcodeTracking)
 {
     // NOP
 }
        protected override void OnElementChanged(ElementChangedEventArgs <DataCaptureView> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources
                e.OldElement.PauseScanningRequested  -= OnPauseScanningRequested;
                e.OldElement.ResumeScanningRequested -= OnResumeScanningRequested;

                this.dataCaptureContext?.Dispose();
            }

            if (e.NewElement != null)
            {
                // Instantiate the native control and assign it to the Control property with
                // the SetNativeControl method
                if (this.Control == null)
                {
                    e.NewElement.PauseScanningRequested  += OnPauseScanningRequested;
                    e.NewElement.ResumeScanningRequested += OnResumeScanningRequested;

                    this.dataCaptureContext = DataCaptureContext.ForLicenseKey(e.NewElement.LicenseKey);
                    // Set the camera as the frame source of the context. The camera is off by
                    // default and must be turned on to start streaming frames to the data capture context for recognition.
                    this.dataCaptureContext.SetFrameSourceAsync(this.camera);

                    // The barcode tracking process is configured through barcode tracking settings
                    // and are then applied to the barcode tracking instance that manages barcode tracking.
                    var settings = BarcodeTrackingSettings.Create();

                    // The settings instance initially has all types of barcodes (symbologies) disabled. For the purpose of this
                    // sample we enable a very generous set of symbologies. In your own app ensure that you only enable the
                    // symbologies that your app requires as every additional enabled symbology has an impact on processing times.
                    var symbologiesToEnable = new List <Symbology> {
                        Symbology.Ean8,
                        Symbology.Ean13Upca,
                        Symbology.Code128,
                        Symbology.DataMatrix
                    };
                    settings.EnableSymbologies(symbologiesToEnable);

                    // Create new barcode tracking mode with the settings from above.
                    this.barcodeTracking = BarcodeTracking.Create(this.dataCaptureContext, settings);

                    // Register this as a listener to get informed of tracked barcodes.
                    this.barcodeTracking.AddListener(this);

                    // To visualize the on-going barcode tracking process on screen, setup a data capture view that renders the
                    // camera preview. The view must be connected to the data capture context.
                    this.captureView = NativeDataCaptureView.Create(this.Context, this.dataCaptureContext);

                    // Once the native DataCaptureView is created it needs to be set as the native control.
                    this.SetNativeControl(this.captureView);

                    // Add a barcode tracking overlay to the data capture view to render the tracked barcodes on top of the video
                    // preview. This is optional, but recommended for better visual feedback.
                    this.overlay          = BarcodeTrackingBasicOverlay.Create(this.barcodeTracking, this.captureView);
                    this.overlay.Listener = this;

                    this.camera.SwitchToDesiredStateAsync(FrameSourceState.On);
                    this.barcodeTracking.Enabled = true;
                }
            }
        }