示例#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);
        }
示例#2
0
        new void Dispose()
        {
            //un-register any event handlers here, if you have any

            //remove result view
            _resultView?.RemoveFromSuperview();
            _resultView?.Dispose();
            _resultView = null;

            //we have to erase the scan view so that there are no dependencies for the viewcontroller left.
            _scanView?.RemoveFromSuperview();
            _scanView?.Dispose();
            _scanView = null;

            GC.Collect(GC.MaxGeneration);

            base.Dispose();
        }
        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);
        }