Exemplo n.º 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;
            }
        }
        void DecodeFrame(FastJavaByteArray fastArray)
        {
            var resolution = cameraController.CameraResolution;
            var width      = resolution.Width;
            var height     = resolution.Height;

            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();

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

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

            var 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)
            {
                // Convert LuminanceSource to grey-scale Bitmap array
                var grayscale_image = fast.Matrix;

                var imageBytes = new byte[fast.Width, fast.Height];
                for (var y = 0; y < fast.Height; y++)
                {
                    for (var x = 0; x < fast.Width; x++)
                    {
                        var value = grayscale_image[y * fast.Width + x];
                        imageBytes[x, y] = value;
                    }
                }

                Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found");

                wasScanned = true;
                BarcodeFound?.Invoke(new ScanResult(result, imageBytes));
                return;
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
0
        void DecodeFrame(FastJavaByteArray fastArray)
        {
            var resolution = cameraController.CameraResolution;
            var width      = resolution.Width;
            var height     = resolution.Height;

            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();

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

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

            var 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");

                wasScanned = true;
                BarcodeFound?.Invoke(result);
                return;
            }
        }
        void DecodeFrame(FastJavaByteArray fastArray)
        {
            var rotate = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait;
            var start  = PerformanceCounter.Start();

            //only calculate the variables needed for decoding if the camera is rotated or the CustomScanAreaView (if used) is changed
            if (lastDecodedCameraDisplayRotationDegree != cameraController.CurrentCameraDisplayRotationDegree || needRecalculateDecodingVariables)
            {
                if (surfaceView != null && surfaceView.UsingCustomScanArea)
                {
                    SetDecodeVariablesForCustomScanArea();
                }
                else
                {
                    SetDecodeVariablesForWholeScreen();
                }

                lastDecodedCameraDisplayRotationDegree = cameraController.CurrentCameraDisplayRotationDegree;
                needRecalculateDecodingVariables       = false;
            }

            var             barcodeReader = scannerHost.ScanningOptions.BuildBarcodeReader();
            LuminanceSource fast;

            if (rotate)
            {
                //for decoding it is expected that the FastJavaByteArrayYUVLuminanceSource will be in landscape orientation
                //if we are in portrait mode the array must be rotated
                //also since we are in portrait mode and all dimensions are calculated from the perspective of the user they must be
                //given to the constructor flipped
                fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, heightCamera, widthCamera,
                                                               offsetScanAreaTopPixelsScaled,
                                                               offsetScanAreaLeftPixelsScaled,
                                                               heightScanAreaScaled,
                                                               widthScanAreaScaled).rotateCounterClockwise();
            }
            else
            {
                //while in landscape mode the FastJavaByteArrayYUVLuminanceSource paramater names match up with the names of the calculated values
                fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, widthCamera, heightCamera,
                                                               offsetScanAreaLeftPixelsScaled,
                                                               offsetScanAreaTopPixelsScaled,
                                                               widthScanAreaScaled,
                                                               heightScanAreaScaled);
            }


            var result = barcodeReader.Decode(fast);

            fastArray.Dispose();
            fastArray = null;

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

            if (result != null)
            {
                Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found");
                wasScanned = true;
                BarcodeFound?.Invoke(result);
                return;
            }
        }
Exemplo n.º 6
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();

            /// <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;
            }
        }