Beispiel #1
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();
        }
Beispiel #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);
        }
Beispiel #4
0
        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
            };
            ocrConfig.TesseractLanguages = new string[] { "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, 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 Bottlecap view from a .json file.
            String configFile = NSBundle.MainBundle.PathForResource(@"Modules/OCR/bottlecap_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/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);
        }