Example #1
0
        private void DecodeFrame(FastJavaByteArray fastArray)
        {
            var cameraParameters = _cameraController.Camera.GetParameters();
            var width            = cameraParameters.PreviewSize.Width;
            var height           = cameraParameters.PreviewSize.Height;

            var barcodeReader = _scannerHost.ScanningOptions.BuildBarcodeReader();

            var rotate    = false;
            var newWidth  = width;
            var newHeight = height;

            // use last value for performance gain
            var cDegrees = _cameraController.LastCameraDisplayOrientationDegree;

            //if (cDegrees == 90 || cDegrees == 270)
            //{
            //    rotate = true;
            //    newWidth = height;
            //    newHeight = width;
            //}

            ZXing.Result result = null;
            var          start  = PerformanceCounter.Start();

            //LuminanceSource fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, width, height, 0, 0, width, height); // _area.Left, _area.Top, _area.Width, _area.Height);
            // cut square in the middle
            LuminanceSource fast = new FastJavaByteArrayYUVLuminanceSource(
                fastArray,
                width,
                height,
                (width - Math.Min(width, height)) / 2,
                (height - Math.Min(width, height)) / 2,
                Math.Min(width, height),
                Math.Min(width, height)
                );

            if (rotate)
            {
                fast = fast.rotateCounterClockwise();
            }

            result = barcodeReader.Decode(fast);

            fastArray.Dispose();
            fastArray = null;

            PerformanceCounter.Stop(start,
                                    "Decode Time: {0} ms (width: " + width + ", height: " + height + ", degrees: " + cDegrees + ", rotate: " +
                                    rotate + ")");

            if (result != null)
            {
                Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found: " + result.Text);

                _wasScanned = true;
                BarcodeFound?.Invoke(this, result);
                return;
            }
        }
Example #2
0
        private void DecodeFrame(FastJavaByteArray fastArray)
        {
            var cameraParameters = _cameraController.Camera.GetParameters();
            var width            = cameraParameters.PreviewSize.Width;
            var height           = cameraParameters.PreviewSize.Height;

            InitBarcodeReaderIfNeeded();

            var rotate    = false;
            var newWidth  = width;
            var newHeight = height;

            // use last value for performance gain
            var cDegrees = _cameraController.LastCameraDisplayOrientationDegree;

            if (cDegrees == 90 || cDegrees == 270)
            {
                rotate    = true;
                newWidth  = height;
                newHeight = width;
            }

            ZXing.Result result = null;
            var          start  = PerformanceCounter.Start();

            LuminanceSource luminanceSource;

            var fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, width, height, 0, 0, width, height); // _area.Left, _area.Top, _area.Width, _area.Height);

            if (rotate)
            {
                fast.CopyMatrix(ref _matrix);
                RotateCounterClockwise(_matrix, ref _rotatedMatrix, width, height);                                        // _area.Width, _area.Height);
                luminanceSource = new PlanarYUVLuminanceSource(_rotatedMatrix, height, width, 0, 0, height, width, false); // _area.Height, _area.Width, 0, 0, _area.Height, _area.Width, false);
            }
            else
            {
                luminanceSource = fast;
            }

            result = _barcodeReader.Decode(luminanceSource);

            fastArray.Dispose();
            fastArray = null;

            PerformanceCounter.Stop(start,
                                    "Decode Time: {0} ms (width: " + width + ", height: " + height + ", degrees: " + cDegrees + ", rotate: " +
                                    rotate + ")");

            if (result != null)
            {
                Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found: " + result.Text);

                _wasScanned = true;
                BarcodeFound?.Invoke(this, result);
                return;
            }
        }
        private void DecodeFrame(byte[] bytes)
        {
            var cameraParameters = _cameraController.Camera.GetParameters();
            var width            = cameraParameters.PreviewSize.Width;
            var height           = cameraParameters.PreviewSize.Height;

            InitBarcodeReaderIfNeeded();

            var rotate    = false;
            var newWidth  = width;
            var newHeight = height;

            // use last value for performance gain
            var cDegrees = _cameraController.LastCameraDisplayOrientationDegree;

            if (cDegrees == 90 || cDegrees == 270)
            {
                rotate    = true;
                newWidth  = height;
                newHeight = width;
            }

            var start = PerformanceCounter.Start();

            if (rotate)
            {
                bytes = RotateCounterClockwise(bytes, width, height);
            }

            var result = _barcodeReader.Decode(bytes, newWidth, newHeight, RGBLuminanceSource.BitmapFormat.Unknown);

            PerformanceCounter.Stop(start,
                                    "Decode Time: {0} ms (width: " + width + ", height: " + height + ", degrees: " + cDegrees + ", rotate: " +
                                    rotate + ")");

            if ((result == null) || string.IsNullOrEmpty(result.Text))
            {
                return;
            }

            Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found: " + result.Text);

            _wasScanned = true;
            BarcodeFound?.Invoke(this, result);
        }
        private void DecodeFrame(FastJavaByteArray fastArray)
        {
            var cameraParameters = _cameraController.Camera.GetParameters();
            var width            = cameraParameters.PreviewSize.Width;
            var height           = cameraParameters.PreviewSize.Height;

            var barcodeReader = _scannerHost.ScanningOptions.BuildBarcodeReader();

            var rotate    = false;
            var newWidth  = width;
            var newHeight = height;

            // use last value for performance gain
            var cDegrees = _cameraController.LastCameraDisplayOrientationDegree;

            if (cDegrees == 90 || cDegrees == 270)
            {
                rotate    = true;
                newWidth  = height;
                newHeight = width;
            }

            ZXing.Result result = null;
            var          start  = PerformanceCounter.Start();

            /// <summary>
            ///START - Scanning Improvement, VK Apacheta Corp 11/14/2018
            ///Added a new frame to get the center part of the captured image.
            ///To create a FastJavaByteArray from the cropped captured frame and use it to decode the barcode.
            ///To decrease the processing time drastically for higher resolution cameras.
            /// </summary>
            var frame_width  = width * 3 / 5;
            var frame_height = height * 3 / 5;
            var frame_left   = width * 1 / 5;
            var frame_top    = height * 1 / 5;

            LuminanceSource fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, width, height,
                                                                           //framingRectPreview?.Width() ?? width,
                                                                           // framingRectPreview?.Height() ?? height,
                                                                           frame_left,
                                                                           frame_top,
                                                                           frame_width,
                                                                           frame_height);  // _area.Left, _area.Top, _area.Width, _area.Height);

            /// <summary>
            ///END - Scanning Improvement, VK Apacheta Corp 11/14/2018
            /// </summary>
            if (rotate)
            {
                fast = fast.rotateCounterClockwise();
            }

            result = barcodeReader.Decode(fast);

            fastArray.Dispose();
            fastArray = null;

            PerformanceCounter.Stop(start,
                                    $"width: {width}, height: {height}, frame_top :{frame_top}, frame_left: {frame_left}, frame_width: {frame_width}, frame_height: {frame_height}, degrees: {cDegrees}, rotate: {rotate}; " + "Decode Time: {0} ms");

            if (result != null)
            {
                Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found");

                _wasScanned = true;
                BarcodeFound?.Invoke(this, result);
                return;
            }
        }