Ejemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initializing the Voucher Code module.
            CGRect frame = UIScreen.MainScreen.ApplicationFrame;

            frame = new CGRect(frame.X,
                               frame.Y + NavigationController.NavigationBar.Frame.Size.Height,
                               frame.Width,
                               frame.Height - NavigationController.NavigationBar.Frame.Size.Height);

            _scanView = new AnylineOCRModuleView(frame);

            // We'll define the OCR Config here:
            _ocrConfig = new ALOCRConfig();
            _ocrConfig.TesseractLanguages = new[] { @"anyline_capitals" };
            _ocrConfig.CharWhiteList      = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            _ocrConfig.ScanMode           = ALOCRScanMode.Auto;
            _ocrConfig.ValidationRegex    = "[A-Z0-9]{8}$";

            // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called
            // by the module once we start receiving results.
            _error   = null;
            _success = _scanView.SetupWithLicenseKey(_licenseKey, Self, _ocrConfig, out _error);
            // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong
            // we have to check the error object for the error message.
            if (!_success)
            {
                // Something went wrong. The error object contains the error description
                (Alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show();
            }

            // We stop scanning manually
            _scanView.CancelOnResult = false;

            // We load the UI config for our VoucherCode view from a .json file.
            string configFile = NSBundle.MainBundle.PathForResource(@"Modules/OCR/voucher_code_config", @"json");

            _scanView.CurrentConfiguration = ALUIConfiguration.CutoutConfigurationFromJsonFile(configFile);

            // After setup is complete we add the module to the view of this view controller
            View.AddSubview(_scanView);

            /*
             * The following view will present the scanned values. Here we start listening for taps
             * to later dismiss the view.
             */
            _resultView = new ResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height), UIImage.FromBundle(@"drawable/gift_card_background.png"));
            _resultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:")));

            _resultView.Center = View.Center;
            _resultView.Alpha  = 0;

            _resultView.Result.Center    = new CGPoint(View.Center.X, View.Center.Y - 45);
            _resultView.Result.Font      = UIFont.BoldSystemFontOfSize(18);
            _resultView.Result.TextColor = UIColor.White;

            View.AddSubview(_resultView);
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initializing the IBAN module.
            CGRect frame = UIScreen.MainScreen.ApplicationFrame;

            frame = new CGRect(frame.X,
                               frame.Y + NavigationController.NavigationBar.Frame.Size.Height,
                               frame.Width,
                               frame.Height - NavigationController.NavigationBar.Frame.Size.Height);

            scanView = new AnylineOCRModuleView(frame);

            if (error != null)
            {
                (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show();
            }

            // We'll define the OCR Config here:
            ocrConfig            = new ALOCRConfig();
            ocrConfig.CharHeight = new ALRange {
                min = 30, max = 60
            };
            ocrConfig.TesseractLanguages  = new string[] { @"eng_no_dict", @"deu" };
            ocrConfig.CharWhiteList       = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            ocrConfig.MinConfidence       = 65;
            ocrConfig.ScanMode            = ALOCRScanMode.Line;
            ocrConfig.ValidationRegex     = "^[A-Z]{2}([0-9A-Z]\\s*){13,32}$";
            ocrConfig.RemoveSmallContours = true;
            // Experimental parameter to set the minimum sharpness (value between 0-100; 0 to turn sharpness detection off)
            // The goal of the minimum sharpness is to avoid a time consuming ocr step,
            // if the image is blurry and good results are therefore not likely.
            ocrConfig.MinSharpness = 66;

            // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called
            // by the module once we start receiving results.
            error   = null;
            success = scanView.SetupWithLicenseKey(licenseKey, this.Self, ocrConfig, out error);
            // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong
            // we have to check the error object for the error message.
            if (!success)
            {
                // Something went wrong. The error object contains the error description
                (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show();
            }

            // We stop scanning manually
            scanView.CancelOnResult = false;

            // We load the UI config for our IBAN view from a .json file.
            String configFile = NSBundle.MainBundle.PathForResource(@"Modules/OCR/iban_config", @"json");

            scanView.CurrentConfiguration = ALUIConfiguration.CutoutConfigurationFromJsonFile(configFile);
            scanView.TranslatesAutoresizingMaskIntoConstraints = false;

            // After setup is complete we add the module to the view of this view controller
            View.AddSubview(scanView);

            /*
             * The following view will present the scanned values. Here we start listening for taps
             * to later dismiss the view.
             */
            resultView = new ResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height), UIImage.FromBundle(@"drawable/iban_background.png"));
            resultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:")));

            resultView.Center = View.Center;
            resultView.Alpha  = 0;

            View.AddSubview(resultView);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initializing the Voucher Code module.
            CGRect frame = UIScreen.MainScreen.ApplicationFrame;

            frame = new CGRect(frame.X,
                               frame.Y + NavigationController.NavigationBar.Frame.Size.Height,
                               frame.Width,
                               frame.Height - NavigationController.NavigationBar.Frame.Size.Height);

            scanView = new AnylineOCRModuleView(frame);

            SetupLicensePlateConfig();

            // We'll copy the required traineddata files here
            error   = null;
            success = scanView.CopyTrainedData(NSBundle.MainBundle.PathForResource(@"Modules/OCR/Alte", @"traineddata"),
                                               @"f52e3822cdd5423758ba19ed75b0cc32", out error);
            if (!success)
            {
                (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show();
            }
            error   = null;
            success = scanView.CopyTrainedData(NSBundle.MainBundle.PathForResource(@"Modules/OCR/Arial", @"traineddata"),
                                               @"9a5555eb6ac51c83cbb76d238028c485", out error);
            if (!success)
            {
                (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show();
            }
            error   = null;
            success = scanView.CopyTrainedData(NSBundle.MainBundle.PathForResource(@"Modules/OCR/GL-Nummernschild-Mtl7_uml", @"traineddata"),
                                               @"8ea050e8f22ba7471df7e18c310430d8", out error);
            if (!success)
            {
                (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show();
            }

            // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called
            // by the module once we start receiving results.
            error   = null;
            success = scanView.SetupWithLicenseKey(licenseKey, this.Self, ocrConfig, out error);
            // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong
            // we have to check the error object for the error message.
            if (!success)
            {
                // Something went wrong. The error object contains the error description
                (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show();
            }

            // We stop scanning manually
            scanView.CancelOnResult = false;

            // We load the UI config for our VoucherCode view from a .json file.
            String configFile = NSBundle.MainBundle.PathForResource(@"Modules/OCR/license_plate_view_config", @"json");

            scanView.CurrentConfiguration = ALUIConfiguration.CutoutConfigurationFromJsonFile(configFile);
            scanView.TranslatesAutoresizingMaskIntoConstraints = false;

            // After setup is complete we add the module to the view of this view controller
            View.AddSubview(scanView);

            /*
             * The following view will present the scanned values. Here we start listening for taps
             * to later dismiss the view.
             */
            resultView = new ResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height), UIImage.FromBundle(@"drawable/license_plate_background.png"));
            resultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:")));

            resultView.Center = View.Center;
            resultView.Alpha  = 0;

            resultView.Result.Center    = new CGPoint(View.Center.X, View.Center.Y);
            resultView.Result.Font      = UIFont.BoldSystemFontOfSize(27);
            resultView.Result.TextColor = UIColor.Black;

            View.AddSubview(resultView);
        }
Ejemplo n.º 4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initializing the Driving License module.
            CGRect frame = UIScreen.MainScreen.ApplicationFrame;

            frame = new CGRect(frame.X,
                               frame.Y + NavigationController.NavigationBar.Frame.Size.Height,
                               frame.Width,
                               frame.Height - NavigationController.NavigationBar.Frame.Size.Height);

            _scanView = new AnylineOCRModuleView(frame);

            // We'll define the OCR Config here:
            _ocrConfig = new ALOCRConfig();

            string engTraineddata = NSBundle.MainBundle.PathForResource(@"Modules/OCR/eng_no_dict", @"traineddata");
            string deuTraineddata = NSBundle.MainBundle.PathForResource(@"Modules/OCR/deu", @"traineddata");

            _ocrConfig.Languages = new[] { engTraineddata, deuTraineddata };

            _ocrConfig.CustomCmdFilePath = NSBundle.MainBundle.PathForResource(@"Modules/DrivingLicense/anyline_austrian_driving_license", @"ale");

            // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called
            // by the module once we start receiving results.
            _error   = null;
            _success = _scanView.SetupWithLicenseKey(_licenseKey, Self, _ocrConfig, out _error);
            // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong
            // we have to check the error object for the error message.
            if (!_success)
            {
                // Something went wrong. The error object contains the error description
                (Alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show();
            }

            // We stop scanning manually
            _scanView.CancelOnResult = false;

            // We load the UI config for our DrivingLicense view from a .json file.
            string configFile = NSBundle.MainBundle.PathForResource(@"Modules/DrivingLicense/drivinglicense_capture_config", @"json");

            _scanView.CurrentConfiguration = ALUIConfiguration.CutoutConfigurationFromJsonFile(configFile);

            // After setup is complete we add the module to the view of this view controller
            View.AddSubview(_scanView);

            /*
             * The following view will present the scanned values. Here we start listening for taps
             * to later dismiss the view.
             */
            _drivingLicenseResultView = new DrivingLicenseResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height));
            //new CGRect(0, 0, View.Frame.Width, View.Frame.Width / 1.4));

            _drivingLicenseResultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:")));

            _drivingLicenseResultView.Center = View.Center;
            _drivingLicenseResultView.Alpha  = 0;

            View.AddSubview(_drivingLicenseResultView);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initializing the Bottlecap scan module.
            CGRect frame = UIScreen.MainScreen.ApplicationFrame;

            frame = new CGRect(frame.X,
                               frame.Y + NavigationController.NavigationBar.Frame.Size.Height,
                               frame.Width,
                               frame.Height - NavigationController.NavigationBar.Frame.Size.Height);

            _scanView = new AnylineOCRModuleView(frame);

            // We'll define the OCR Config here:
            _ocrConfig            = new ALOCRConfig();
            _ocrConfig.CharHeight = new ALRange {
                min = 14, max = 95
            };

            // as of 3.20, we use Languages instead of TesseractLanguages as it doesn't require to copy the traineddata file
            string bottlecap = NSBundle.MainBundle.PathForResource(@"Modules/OCR/bottlecap", @"traineddata");

            _ocrConfig.Languages = new[] { bottlecap };
            //_ocrConfig.TesseractLanguages = new[] { "bottlecap" };

            _ocrConfig.CharWhiteList      = "123456789ABCDEFGHJKLMNPRSTUVWXYZ";
            _ocrConfig.MinConfidence      = 75;
            _ocrConfig.ScanMode           = ALOCRScanMode.Grid;
            _ocrConfig.CharCountX         = 3;
            _ocrConfig.CharCountY         = 3;
            _ocrConfig.CharPaddingXFactor = 0.3;
            _ocrConfig.CharPaddingYFactor = 0.5;

            _ocrConfig.IsBrightTextOnDark = true;
            _ocrConfig.ValidationRegex    = "^[0-9A-Z]{3}\n[0-9A-Z]{3}\n[0-9A-Z]{3}";

            // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called
            // by the module once we start receiving results.
            _error   = null;
            _success = _scanView.SetupWithLicenseKey(_licenseKey, Self, _ocrConfig, out _error);
            // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong
            // we have to check the error object for the error message.
            if (!_success)
            {
                // Something went wrong. The error object contains the error description
                (Alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show();
            }

            // We stop scanning manually
            _scanView.CancelOnResult = false;

            // We load the UI config for our Bottlecap view from a .json file.
            string configFile = NSBundle.MainBundle.PathForResource(@"Modules/OCR/bottlecap_config", @"json");

            _scanView.CurrentConfiguration = ALUIConfiguration.CutoutConfigurationFromJsonFile(configFile);

            // After setup is complete we add the module to the view of this view controller
            View.AddSubview(_scanView);

            /*
             * The following view will present the scanned values. Here we start listening for taps
             * to later dismiss the view.
             */
            _resultView = new ResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height), UIImage.FromBundle(@"drawable/bottle_background.png"));
            _resultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:")));

            _resultView.Result.Font          = UIFont.BoldSystemFontOfSize(17);
            _resultView.Result.TextColor     = UIColor.Black;
            _resultView.Result.Lines         = 3;
            _resultView.Result.LineBreakMode = UILineBreakMode.Clip;
            _resultView.Center = View.Center;
            _resultView.Alpha  = 0;

            View.AddSubview(_resultView);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initializing the IBAN module.
            CGRect frame = UIScreen.MainScreen.ApplicationFrame;

            frame = new CGRect(frame.X,
                               frame.Y + NavigationController.NavigationBar.Frame.Size.Height,
                               frame.Width,
                               frame.Height - NavigationController.NavigationBar.Frame.Size.Height);

            _scanView = new AnylineOCRModuleView(frame);

            if (_error != null)
            {
                (Alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show();
            }

            // We'll define the OCR Config here:
            _ocrConfig = new ALOCRConfig();

            // as of 3.20, we use Languages instead of TesseractLanguages as it doesn't require to copy the traineddata file
            string engNoDict = NSBundle.MainBundle.PathForResource(@"Modules/OCR/eng_no_dict", @"traineddata");
            string deu       = NSBundle.MainBundle.PathForResource(@"Modules/OCR/deu", @"traineddata");

            _ocrConfig.Languages = new[] { engNoDict, deu };
            //_ocrConfig.TesseractLanguages = new[] {@"eng_no_dict", @"deu"};
            _ocrConfig.CharWhiteList   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
            _ocrConfig.MinConfidence   = 60;
            _ocrConfig.ScanMode        = ALOCRScanMode.Auto;
            _ocrConfig.ValidationRegex = "^[A-Z]{2}([0-9A-Z]\\s*){13,32}$";

            // We tell the module to bootstrap itself with the license key and delegate. The delegate will later get called
            // by the module once we start receiving results.
            _error   = null;
            _success = _scanView.SetupWithLicenseKey(_licenseKey, Self, _ocrConfig, out _error);
            // SetupWithLicenseKey:delegate:error returns true if everything went fine. In the case something wrong
            // we have to check the error object for the error message.
            if (!_success)
            {
                // Something went wrong. The error object contains the error description
                (Alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show();
            }

            // We load the UI config for our IBAN view from a .json file.
            string configFile = NSBundle.MainBundle.PathForResource(@"Modules/OCR/iban_config", @"json");

            _scanView.CurrentConfiguration = ALUIConfiguration.CutoutConfigurationFromJsonFile(configFile);

            // We stop scanning manually
            _scanView.CancelOnResult = false;

            // After setup is complete we add the module to the view of this view controller
            View.AddSubview(_scanView);

            /*
             * The following view will present the scanned values. Here we start listening for taps
             * to later dismiss the view.
             */
            _resultView = new ResultOverlayView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height), UIImage.FromBundle(@"drawable/iban_background.png"));
            _resultView.AddGestureRecognizer(new UITapGestureRecognizer(this, new ObjCRuntime.Selector("ViewTapSelector:")));

            _resultView.Center = View.Center;
            _resultView.Alpha  = 0;

            View.AddSubview(_resultView);
        }