From c6098183c4cffb7ace031247187eb994124a98c2 Mon Sep 17 00:00:00 2001 From: vkalyanapu <39805602+vkalyanapu@users.noreply.github.com> Date: Wed, 14 Nov 2018 16:47:21 -0500 Subject: [PATCH 1/4] Update CameraAnalyzer.cs Improvement for scanning --- .../CameraAccess/CameraAnalyzer.cs | 201 +++++++++++++++++- 1 file changed, 193 insertions(+), 8 deletions(-) diff --git a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs index 1a7ea7c8a..1659d10a5 100644 --- a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs +++ b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs @@ -1,19 +1,39 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using Android.Views; using ApxLabs.FastAndroidCamera; +using Android.Graphics; +using Android.Content; +using Android.Util; namespace ZXing.Mobile.CameraAccess { public class CameraAnalyzer { + /// + ///START - Scanning Improvement, VK 10/2018 + /// + private const int MIN_FRAME_WIDTH = 240; + private const int MIN_FRAME_HEIGHT = 240; + private const int MAX_FRAME_WIDTH = 640; // = 5/8 * 1920 + private const int MAX_FRAME_HEIGHT = 480; // = 5/8 * 1080 + /// + /// END - Scanning Improvement, VK 10/2018 + /// + /// + private readonly CameraController _cameraController; private readonly CameraEventsListener _cameraEventListener; + private int _screenHeight = -1; + private int _screenWidth = -1; private Task _processingTask; private DateTime _lastPreviewAnalysis = DateTime.UtcNow; private bool _wasScanned; IScannerSessionHost _scannerHost; + private Rect framingRectInPreview; + private Rect framingRect; + private IWindowManager manager; public CameraAnalyzer(SurfaceView surfaceView, IScannerSessionHost scannerHost) { @@ -21,6 +41,14 @@ public CameraAnalyzer(SurfaceView surfaceView, IScannerSessionHost scannerHost) _cameraEventListener = new CameraEventsListener(); _cameraController = new CameraController(surfaceView, _cameraEventListener, scannerHost); Torch = new Torch(_cameraController, surfaceView.Context); + try + { + manager = (surfaceView.Context as ZxingActivity)?.WindowManager; + } + catch(Exception ex) + { + Log.Debug(MobileBarcodeScanner.TAG, "Error occured while getting window manager : " + ex.ToString()); + } } public event EventHandler BarcodeFound; @@ -57,6 +85,14 @@ public void AutoFocus() _cameraController.AutoFocus(); } + /// + ///Scanning Improvement, VK 10/2018 + /// + //public void LowLightMode(bool on) + //{ + // _cameraController.LowLightMode(on); + //} + public void AutoFocus(int x, int y) { _cameraController.AutoFocus(x, y); @@ -67,6 +103,14 @@ public void RefreshCamera() _cameraController.RefreshCamera(); } + private bool Valid_ScreenResolution + { + get + { + return _screenHeight > 0 && _screenWidth > 0; + } + } + private bool CanAnalyzeFrame { get @@ -103,14 +147,15 @@ private void HandleOnPreviewFrameReady(object sender, FastJavaByteArray fastArra { try { - DecodeFrame(fastArray); + Log.Debug(MobileBarcodeScanner.TAG, "Preview Analyzing."); + DecodeFrame(fastArray); } catch (Exception ex) { Console.WriteLine(ex); } }).ContinueWith(task => { if (task.IsFaulted) - Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "DecodeFrame exception occurs"); + Log.Debug(MobileBarcodeScanner.TAG, "DecodeFrame exception occurs"); }, TaskContinuationOptions.OnlyOnFaulted); } @@ -139,7 +184,25 @@ private void DecodeFrame(FastJavaByteArray fastArray) 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); + /// + ///START - Scanning Improvement, VK 10/2018 + /// + 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); + + /// + ///END - Scanning Improvement, VK 10/2018 + /// if (rotate) fast = fast.rotateCounterClockwise(); @@ -149,17 +212,139 @@ private void DecodeFrame(FastJavaByteArray fastArray) fastArray = null; PerformanceCounter.Stop(start, - "Decode Time: {0} ms (width: " + width + ", height: " + height + ", degrees: " + cDegrees + ", rotate: " + - rotate + ")"); + $"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) { - Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found"); + Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found"); _wasScanned = true; BarcodeFound?.Invoke(this, result); return; } } + + + /// + ///Scanning Improvement, VK 10/2018 + /// + private Rect GetFramingRectInPreview() + { + if (framingRectInPreview == null) + { + //if (!Valid_ScreenResolution) + // GetScreenResolution(); + var cameraParameters = _cameraController?.Camera?.GetParameters(); + var width = cameraParameters.PreviewSize.Width; + var height = cameraParameters.PreviewSize.Height; + if (cameraParameters == null)//|| !Valid_ScreenResolution) + { + // Called early, before init even finished + return null; + } + + var framingRect = GetFramingRect(width, height); + if (framingRect == null) + { + return null; + } + + var rect = new Rect(framingRect); + //var cameraParameters = _cameraController?.Camera?.GetParameters(); + //var width = cameraParameters.PreviewSize.Width; + //var height = cameraParameters.PreviewSize.Height; + + + //rect.Left = rect.Left * width / _screenWidth; + //rect.Right = rect.Right * width / _screenHeight; + //rect.Top = rect.Top * height / _screenWidth; + //rect.Bottom = rect.Bottom * height / _screenHeight; + framingRectInPreview = rect; + Log.Debug(MobileBarcodeScanner.TAG, $"preview resolution: w={width}; h={height}; _screenWidth ={_screenWidth}; _screenHeight={_screenHeight}; framingRect={framingRect?.ToString()}"); + } + + Log.Debug(MobileBarcodeScanner.TAG, $"Calculated preview framing rect: {framingRectInPreview?.FlattenToString()}"); + return framingRectInPreview; + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + public Rect GetFramingRect(int _width, int _height) + { + if (framingRect == null) + { + if (_cameraController == null) + { + return null; + } + + if (!(_width > 0 && _height > 0))//Valid_ScreenResolution) + { + // Called early, before init even finished + return null; + } + + int width = findDesiredDimensionInRange(_width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH); + int height = findDesiredDimensionInRange(_height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); + + int leftOffset = (_width - width) / 2; + int topOffset = (_height - height) / 2; + framingRect = new Rect(leftOffset, topOffset, width, height); + Log.Debug(MobileBarcodeScanner.TAG, $"Calculated framing rect: {framingRect?.FlattenToString()}; screenWidth: {_screenWidth}; screenHeight: {_screenHeight}"); + } + + return framingRect; + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private void GetScreenResolution() + { + var screenResolution = new DisplayMetrics(); + try + { + if(manager == null) + { + Log.Debug(MobileBarcodeScanner.TAG, $"Window manager is null."); + } + + Display display = manager?.DefaultDisplay; + if (display == null) + { + Log.Debug(MobileBarcodeScanner.TAG, $"Default display is null."); + } + else + { + + display?.GetMetrics(screenResolution); + _screenWidth = screenResolution.WidthPixels; + _screenHeight = screenResolution.HeightPixels; + } + Log.Debug(MobileBarcodeScanner.TAG, $"Screen Display Rect- Width = {_screenWidth}; Height = {_screenHeight} "); + } + catch (Exception ex) + { + Log.Debug(MobileBarcodeScanner.TAG, "Error occured while getting screen resolution : " + ex.ToString()); + } + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) + { + int dim = 5 * resolution / 8; // Target 5/8 of each dimension + if (dim < hardMin) + { + return hardMin; + } + if (dim > hardMax) + { + return hardMax; + } + return dim; + } } -} \ No newline at end of file +} From a250ef225f26df075b277a1cf134e3f5f49b8750 Mon Sep 17 00:00:00 2001 From: vkalyanapu <39805602+vkalyanapu@users.noreply.github.com> Date: Wed, 14 Nov 2018 16:48:44 -0500 Subject: [PATCH 2/4] Update CameraController.cs Scanner improvement for auto focus. Setting the auto focus to rectangle --- .../CameraAccess/CameraController.cs | 251 +++++++++++++++++- 1 file changed, 239 insertions(+), 12 deletions(-) diff --git a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs index 61f7b8e3b..7b4c6bbea 100644 --- a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs +++ b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Android.Content; @@ -9,11 +9,15 @@ using Android.Views; using ApxLabs.FastAndroidCamera; using Camera = Android.Hardware.Camera; +using Android.Util; namespace ZXing.Mobile.CameraAccess { public class CameraController { + private const float MAX_EXPOSURE_COMPENSATION = 1.5f; + private const float MIN_EXPOSURE_COMPENSATION = 0.0f; + private const int AREA_PER_1000 = 300; private readonly Context _context; private readonly ISurfaceHolder _holder; private readonly SurfaceView _surfaceView; @@ -75,9 +79,10 @@ public void SetupCamera() var previewSize = previewParameters.PreviewSize; var bitsPerPixel = ImageFormat.GetBitsPerPixel(previewParameters.PreviewFormat); - int bufferSize = (previewSize.Width * previewSize.Height * bitsPerPixel) / 8; - const int NUM_PREVIEW_BUFFERS = 5; + + Log.Debug(MobileBarcodeScanner.TAG, $"bitsPerPixed={bitsPerPixel}; bufferSize={bufferSize}"); + const int NUM_PREVIEW_BUFFERS = 5; for (uint i = 0; i < NUM_PREVIEW_BUFFERS; ++i) { using (var buffer = new FastJavaByteArray(bufferSize)) @@ -92,7 +97,7 @@ public void SetupCamera() } catch (Exception ex) { - Android.Util.Log.Debug(MobileBarcodeScanner.TAG, ex.ToString()); + Log.Debug(MobileBarcodeScanner.TAG, ex.ToString()); return; } finally @@ -112,6 +117,20 @@ public void AutoFocus() AutoFocus(0, 0, false); } + + /// + ///Scanning Improvement, VK 10/2018 + /// + public void LowLightMode(bool on) + { + var parameters = Camera?.GetParameters(); + if (parameters != null) + { + SetBestExposure(parameters, on); + Camera.SetParameters(parameters); + } + } + public void AutoFocus(int x, int y) { // The bounds for focus areas are actually -1000 to 1000 @@ -150,7 +169,7 @@ public void ShutdownCamera() } catch (Exception e) { - Android.Util.Log.Error(MobileBarcodeScanner.TAG, e.ToString()); + Log.Error(MobileBarcodeScanner.TAG, e.ToString()); } PerformanceCounter.Stop(perf, "Shutdown camera took {0}ms"); @@ -182,7 +201,7 @@ private void OpenCamera() Camera.GetCameraInfo(i, camInfo); if (camInfo.Facing == whichCamera) { - Android.Util.Log.Debug(MobileBarcodeScanner.TAG, + Log.Debug(MobileBarcodeScanner.TAG, "Found " + whichCamera + " Camera, opening..."); Camera = Camera.Open(i); _cameraId = i; @@ -193,7 +212,7 @@ private void OpenCamera() if (!found) { - Android.Util.Log.Debug(MobileBarcodeScanner.TAG, + Log.Debug(MobileBarcodeScanner.TAG, "Finding " + whichCamera + " camera failed, opening camera 0..."); Camera = Camera.Open(0); _cameraId = 0; @@ -232,29 +251,65 @@ private void ApplyCameraSettings() var supportedFocusModes = parameters.SupportedFocusModes; if (_scannerHost.ScanningOptions.DisableAutofocus) parameters.FocusMode = Camera.Parameters.FocusModeFixed; + else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeAuto)) + parameters.FocusMode = Camera.Parameters.FocusModeAuto; else if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich && supportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture)) parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture; else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousVideo)) parameters.FocusMode = Camera.Parameters.FocusModeContinuousVideo; - else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeAuto)) - parameters.FocusMode = Camera.Parameters.FocusModeAuto; else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeFixed)) parameters.FocusMode = Camera.Parameters.FocusModeFixed; + + Log.Debug(MobileBarcodeScanner.TAG, + $"FocusMode ={parameters.FocusMode}"); var selectedFps = parameters.SupportedPreviewFpsRange.FirstOrDefault(); if (selectedFps != null) { + Log.Debug(MobileBarcodeScanner.TAG, + $"Old Selected fps Min:{selectedFps[0]}, Max {selectedFps[1]}"); // This will make sure we select a range with the lowest minimum FPS // and maximum FPS which still has the lowest minimum // This should help maximize performance / support for hardware + //foreach (var fpsRange in parameters.SupportedPreviewFpsRange) + //{ + // if (fpsRange[0] < selectedFps[0] && fpsRange[1] >= selectedFps[1]) + // selectedFps = fpsRange; + //} + + /// + ///Scanning Improvement, VK 10/2018 + /// foreach (var fpsRange in parameters.SupportedPreviewFpsRange) { - if (fpsRange[0] <= selectedFps[0] && fpsRange[1] > selectedFps[1]) + if (fpsRange[1] > selectedFps[1] || fpsRange[1] == selectedFps[1] && fpsRange[0] < selectedFps[0]) selectedFps = fpsRange; } + + Log.Debug(MobileBarcodeScanner.TAG, + $" Setting Selected fps to Min:{selectedFps[0]}, Max {selectedFps[1]}"); + + /// + ///Scanning Improvement, VK 10/2018 + /// parameters.SetPreviewFpsRange(selectedFps[0], selectedFps[1]); } + + if (_scannerHost.ScanningOptions.LowLightMode == true) + SetBestExposure(parameters, parameters.FlashMode != Camera.Parameters.FlashModeOn); + + /* + * Improvements based on zxing android library + * - Setting default auto focus areas instead of single focus point + * - Setting Barcode scene mode if available for the device + * - Set metering to improve lighting/ exposure in the focused area (i.e., rectangular focus area in the center) + * - **** Imp ==> In UI project a layout should be created to mask other areas except the center rectangular area. + * To inform the user that app/ camera only scans the center rectangular area of the device. + */ + SetDefaultFocusArea(parameters); + SetBarcodeSceneMode(parameters); + SetMetering(parameters); CameraResolution resolution = null; var supportedPreviewSizes = parameters.SupportedPreviewSizes; @@ -302,7 +357,7 @@ private void ApplyCameraSettings() // Hopefully a resolution was selected at some point if (resolution != null) { - Android.Util.Log.Debug(MobileBarcodeScanner.TAG, + Log.Debug(MobileBarcodeScanner.TAG, "Selected Resolution: " + resolution.Width + "x" + resolution.Height); parameters.SetPreviewSize(resolution.Width, resolution.Height); } @@ -312,6 +367,177 @@ private void ApplyCameraSettings() SetCameraDisplayOrientation(); } + /// + ///Scanning Improvement, VK 10/2018 + /// + private void SetBestExposure(Camera.Parameters parameters, bool lowLight) + { + int minExposure = parameters.MinExposureCompensation; + int maxExposure = parameters.MaxExposureCompensation; + float step = parameters.ExposureCompensationStep; + if ((minExposure != 0 || maxExposure != 0) && step > 0.0f) + { + // Set low when light is on + float targetCompensation = MAX_EXPOSURE_COMPENSATION; + int compensationSteps = (int)(targetCompensation / step); + float actualCompensation = step * compensationSteps; + // Clamp value: + compensationSteps = lowLight ? Math.Max(Math.Min(compensationSteps, maxExposure), minExposure) : (int)MIN_EXPOSURE_COMPENSATION; + if (parameters.ExposureCompensation == compensationSteps) + { + Log.Debug(MobileBarcodeScanner.TAG, "Exposure compensation already set to " + compensationSteps + " / " + actualCompensation); + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Setting exposure compensation to " + compensationSteps + " / " + actualCompensation); + parameters.ExposureCompensation = compensationSteps; + } + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Camera does not support exposure compensation"); + } + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private void SetDefaultFocusArea(Camera.Parameters parameters) + { + if (parameters?.MaxNumFocusAreas > 0) + { + List middleArea = BuildMiddleArea(AREA_PER_1000); + Log.Debug(MobileBarcodeScanner.TAG, "Setting focus area to : " + middleArea.Select(f => f.Rect.FlattenToString()).Aggregate((first, next) => first + "; " + next)); + parameters.FocusAreas = middleArea; + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Device does not support focus areas"); + } + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private void SetMetering(Camera.Parameters parameters) + { + if (parameters?.MaxNumMeteringAreas > 0) + { + List middleArea = BuildMiddleArea(AREA_PER_1000); + Log.Debug(MobileBarcodeScanner.TAG, "Setting metering areas: " + middleArea.Select(f => f.Rect.FlattenToString()).Aggregate((first, next) => first + "; " + next)); + parameters.MeteringAreas = middleArea; + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Device does not support metering areas"); + } + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private List BuildMiddleArea(int areaPer1000) + { + return new List() + { + new Camera.Area(new Rect(-areaPer1000, -areaPer1000, areaPer1000, areaPer1000), 1) + }; + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private void SetVideoStabilization(Camera.Parameters parameters) + { + if (parameters.IsVideoStabilizationSupported) + { + if (parameters.VideoStabilization) + { + Log.Debug(MobileBarcodeScanner.TAG, "Video stabilization already enabled"); + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Enabling video stabilization..."); + parameters.VideoStabilization = true; + } + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "This device does not support video stabilization"); + } + } + + /// + ///Scanning Improvement, VK 10/2018 + /// + private void SetBarcodeSceneMode(Camera.Parameters parameters) + { + if (parameters.SceneMode == Camera.Parameters.SceneModeBarcode) + { + Log.Debug(MobileBarcodeScanner.TAG, "Barcode scene mode already set"); + return; + } + var supportedSceneModes = parameters.SupportedSceneModes; + if (supportedSceneModes?.Contains(Camera.Parameters.SceneModeBarcode) == true) + { + Log.Debug(MobileBarcodeScanner.TAG, $"Previous SceneMode={parameters.SceneMode}"); + parameters.SceneMode = Camera.Parameters.SceneModeBarcode; + Log.Debug(MobileBarcodeScanner.TAG, "Barcode scene mode is set"); + } + + } + + private void SetZoom(Camera.Parameters parameters, double targetZoomRatio) + { + if (parameters.IsZoomSupported) + { + var zoom = IndexOfClosestZoom(parameters, targetZoomRatio); + if (zoom == null) + { + return; + } + if (parameters.Zoom == zoom) + { + Log.Debug(MobileBarcodeScanner.TAG, "Zoom is already set to " + zoom); + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Setting zoom to " + zoom); + parameters.Zoom = (int)zoom; + } + } + else + { + Log.Debug(MobileBarcodeScanner.TAG, "Zoom is not supported"); + } + } + + private int? IndexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio) + { + var ratios = parameters.ZoomRatios.ToList(); + Log.Debug(MobileBarcodeScanner.TAG, "Zoom ratios: " + ratios); + int maxZoom = parameters.MaxZoom; + if (ratios == null || ratios.Count == 0 || ratios.Count != maxZoom + 1) + { + Log.Debug(MobileBarcodeScanner.TAG, "Invalid zoom ratios!"); + return null; + } + double target100 = 100.0 * targetZoomRatio; + double smallestDiff = Double.PositiveInfinity; + int closestIndex = 0; + for (int i = 0; i < ratios.Count; i++) + { + double diff = Math.Abs(ratios[i]?.LongValue() ?? 0 - target100); + if (diff < smallestDiff) + { + smallestDiff = diff; + closestIndex = i; + } + } + Log.Debug(MobileBarcodeScanner.TAG, "Chose zoom ratio of " + ((ratios[closestIndex]?.LongValue() ?? 0) / 100.0)); + return closestIndex; + } + private void AutoFocus(int x, int y, bool useCoordinates) { if (Camera == null) return; @@ -360,6 +586,7 @@ private void AutoFocus(int x, int y, bool useCoordinates) { new Camera.Area(new Rect(x, y, x + 20, y + 20), 1000) }; + Android.Util.Log.Debug(MobileBarcodeScanner.TAG, $"AutoFocus Area =(x={x}, y={y}, right = {x + 20}, bottom ={y + 20})"); Camera.SetParameters(cameraParams); } @@ -432,4 +659,4 @@ private int GetCameraDisplayOrientation() return correctedDegrees; } } -} \ No newline at end of file +} From 1ae0e8256df95e60bf92b9cffdec8516a1365564 Mon Sep 17 00:00:00 2001 From: vkalyanapu <39805602+vkalyanapu@users.noreply.github.com> Date: Wed, 14 Nov 2018 18:01:03 -0500 Subject: [PATCH 3/4] Update CameraAnalyzer.cs Updated credits for the file --- .../CameraAccess/CameraAnalyzer.cs | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs index 1659d10a5..9b315fcb8 100644 --- a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs +++ b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraAnalyzer.cs @@ -1,3 +1,23 @@ +/* +* Copyright 2018 ZXing/Redth - https://github.com/Redth/ZXing.Net.Mobile +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Edited by VK, Apacheta Corp 11/14/2018. +* http://www.apacheta.com/ +* +*/ + using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -12,14 +32,14 @@ namespace ZXing.Mobile.CameraAccess public class CameraAnalyzer { /// - ///START - Scanning Improvement, VK 10/2018 + ///START - Scanning Improvement, VK 11/14/2018 /// private const int MIN_FRAME_WIDTH = 240; private const int MIN_FRAME_HEIGHT = 240; private const int MAX_FRAME_WIDTH = 640; // = 5/8 * 1920 private const int MAX_FRAME_HEIGHT = 480; // = 5/8 * 1080 /// - /// END - Scanning Improvement, VK 10/2018 + /// END - Scanning Improvement, VK 11/14/2018 /// /// @@ -87,6 +107,7 @@ public void AutoFocus() /// ///Scanning Improvement, VK 10/2018 + ///Removed this method for now. /// //public void LowLightMode(bool on) //{ @@ -185,7 +206,10 @@ private void DecodeFrame(FastJavaByteArray fastArray) var start = PerformanceCounter.Start(); /// - ///START - Scanning Improvement, VK 10/2018 + ///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. /// var frame_width = width * 3 / 5; var frame_height = height * 3 / 5; @@ -201,7 +225,7 @@ private void DecodeFrame(FastJavaByteArray fastArray) frame_height); // _area.Left, _area.Top, _area.Width, _area.Height); /// - ///END - Scanning Improvement, VK 10/2018 + ///END - Scanning Improvement, VK Apacheta Corp 11/14/2018 /// if (rotate) fast = fast.rotateCounterClockwise(); From 5dd202ea6f6069efc0fb4d507b3ba9238fca6533 Mon Sep 17 00:00:00 2001 From: vkalyanapu <39805602+vkalyanapu@users.noreply.github.com> Date: Wed, 14 Nov 2018 18:02:15 -0500 Subject: [PATCH 4/4] Update CameraController.cs Update credits --- .../CameraAccess/CameraController.cs | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs index 7b4c6bbea..cb8ce7409 100644 --- a/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs +++ b/Source/ZXing.Net.Mobile.Android/CameraAccess/CameraController.cs @@ -1,3 +1,23 @@ +/* +* Copyright 2018 ZXing/Redth - https://github.com/Redth/ZXing.Net.Mobile +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Edited by VK, Apacheta Corp 11/14/2018. +* http://www.apacheta.com/ +* +*/ + using System; using System.Collections.Generic; using System.Linq; @@ -291,7 +311,9 @@ private void ApplyCameraSettings() $" Setting Selected fps to Min:{selectedFps[0]}, Max {selectedFps[1]}"); /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, Apacheta corporation 11/14/2018 + ///Changed the fps to use low and high. instead of low value and low value ie., selectedFps[0]. + ///Old code :: parameters.SetPreviewFpsRange(selectedFps[0], selectedFps[0]); /// parameters.SetPreviewFpsRange(selectedFps[0], selectedFps[1]); } @@ -300,6 +322,7 @@ private void ApplyCameraSettings() SetBestExposure(parameters, parameters.FlashMode != Camera.Parameters.FlashModeOn); /* + * Edited by VK - Apacheta corporation 11/14/2018 * Improvements based on zxing android library * - Setting default auto focus areas instead of single focus point * - Setting Barcode scene mode if available for the device @@ -368,7 +391,8 @@ private void ApplyCameraSettings() } /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, VK, Apacheta Corp 11/14/2018. + ///This method sets the best expsure setting for the device. /// private void SetBestExposure(Camera.Parameters parameters, bool lowLight) { @@ -400,7 +424,8 @@ private void SetBestExposure(Camera.Parameters parameters, bool lowLight) } /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, VK Apacheta Corp 11/14/2018. + ///This method sets the focus area setting for the device. center rectangle /// private void SetDefaultFocusArea(Camera.Parameters parameters) { @@ -416,8 +441,10 @@ private void SetDefaultFocusArea(Camera.Parameters parameters) } } + /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, VK Apacheta Corp 11/14/2018. + ///This method sets the meter setting for the device. center rectangle /// private void SetMetering(Camera.Parameters parameters) { @@ -434,7 +461,8 @@ private void SetMetering(Camera.Parameters parameters) } /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, VK Apacheta Corp 11/14/2018. + ///This method builds the middle are i.e., center rectangle for the device /// private List BuildMiddleArea(int areaPer1000) { @@ -444,8 +472,11 @@ private void SetMetering(Camera.Parameters parameters) }; } + /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, VK Apacheta Corp 11/14/2018. + ///This method sets the Video stabilization setting for the device. + ///This method is not used in the code for now. /// private void SetVideoStabilization(Camera.Parameters parameters) { @@ -468,7 +499,8 @@ private void SetVideoStabilization(Camera.Parameters parameters) } /// - ///Scanning Improvement, VK 10/2018 + ///Scanning Improvement, VK Apacheta Corp 11/14/2018. + ///This method sets the scene to barcode for the device. If the device supports scenes. /// private void SetBarcodeSceneMode(Camera.Parameters parameters) {