Esempio 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);
        }
Esempio n. 2
0
        void IAnylineOCRModuleDelegate.ReportsRunFailure(AnylineOCRModuleView anylineOCRModuleView, ALOCRError error)
        {
            switch (error)
            {
            case ALOCRError.ConfidenceNotReached:
                Console.WriteLine("Confidence not reached.");
                break;

            case ALOCRError.NoLinesFound:
                Console.WriteLine("No lines found.");
                break;

            case ALOCRError.NoTextFound:
                Console.WriteLine("No text found.");
                break;

            case ALOCRError.ResultNotValid:
                Console.WriteLine("Result is not valid.");
                break;

            case ALOCRError.SharpnessNotReached:
                Console.WriteLine("Sharpness is not reached.");
                break;

            case ALOCRError.Unkown:
                Console.WriteLine("Unknown run error.");
                break;
            }
        }
Esempio n. 3
0
        /*
         * This is the main delegate method Anyline uses to report its results
         */
        void IAnylineOCRModuleDelegate.DidFindResult(AnylineOCRModuleView anylineOCRModuleView, ALOCRResult result)
        {
            StopAnyline();
            View.BringSubviewToFront(resultView);

            resultView.UpdateResult(result.Text);

            // Present the information to the user
            resultView.AnimateFadeIn(this.View);
        }
Esempio n. 4
0
        /*
         * This is the main delegate method Anyline uses to report its results
         */
        void IAnylineOCRModuleDelegate.DidFindResult(AnylineOCRModuleView anylineOCRModuleView, ALOCRResult result)
        {
            StopAnyline();
            if (_resultView != null)
            {
                View.BringSubviewToFront(_resultView);
            }

            _resultView?.UpdateResult(result.Text);

            // Present the information to the user
            _resultView?.AnimateFadeIn(View);
        }
Esempio n. 5
0
        public override void ViewDidDisappear(bool animated)
        {
            base.ViewDidDisappear(animated);

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

            base.Dispose();
        }
Esempio n. 6
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();
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
 bool IAnylineOCRModuleDelegate.TextOutlineDetected(AnylineOCRModuleView anylineOCRModuleView, ALSquare outline)
 {
     return(false);
 }
Esempio n. 9
0
 void IAnylineOCRModuleDelegate.ReportsVariable(AnylineOCRModuleView anylineOCRModuleView, string variableName, NSObject value)
 {
 }
        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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        /*
         * This is the main delegate method Anyline uses to report its results
         */
        void IAnylineOCRModuleDelegate.DidFindResult(AnylineOCRModuleView anylineOCRModuleView, ALOCRResult result)
        {
            StopAnyline();
            if (_drivingLicenseResultView != null)
            {
                View.BringSubviewToFront(_drivingLicenseResultView);
            }

            string[] comps = result.Result.ToString().Split('|');

            string name        = comps[0];
            string birthdateID = comps[1];

            string[] nameComps = name.Split(' ');

            switch (nameComps.Length)
            {
            case 0:
                break;

            case 1:
                _drivingLicenseResultView.Surname.Text    = nameComps[0];
                _drivingLicenseResultView.Surname2.Text   = "";
                _drivingLicenseResultView.GivenNames.Text = "";
                break;

            case 2:
                _drivingLicenseResultView.Surname.Text    = nameComps[0];
                _drivingLicenseResultView.Surname2.Text   = "";
                _drivingLicenseResultView.GivenNames.Text = nameComps[1];
                break;

            case 3:
                _drivingLicenseResultView.Surname.Text    = nameComps[0];
                _drivingLicenseResultView.Surname2.Text   = nameComps[1];
                _drivingLicenseResultView.GivenNames.Text = nameComps[2];
                break;

            default:
                break;
            }

            string[] birthdateIDComps = birthdateID.Split(' ');

            string birthday = birthdateIDComps[0];

            NSDateFormatter formatter = new NSDateFormatter();

            formatter.DateFormat = @"ddMMyyyy";

            NSDate date = formatter.Parse(birthday);

            if (date == null)
            {
                formatter.DateFormat = @"yyyyMMdd";
                date = formatter.Parse(birthday);
            }

            formatter.DateFormat = @"yyyy-MM-dd";
            _drivingLicenseResultView.Birthdate.Text = formatter.StringFor(date);
            _drivingLicenseResultView.IDNumber.Text  = birthdateIDComps[1];

            // Present the information to the user
            _drivingLicenseResultView?.AnimateFadeIn(View);
        }
        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);
        }