Пример #1
0
        void ProcessTakenPicture(object sender, PictureCallbackEventArgs args)
        {
            cameraView.Post(delegate
            {
                progress.Visibility = ViewStates.Visible;
            });

            var bitmap = BitmapFactory.DecodeByteArray(args.image, 0, args.image.Length);

            var matrix = new Matrix();

            matrix.SetRotate(args.imageOrientation, bitmap.Width / 2, bitmap.Height / 2);
            var result = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, false);

            var detector = sdk.MultipleObjectsDetector();

            if (modParams != null)
            {
                detector.SetParams(modParams);
            }
            var polygons = detector.DetectOnBitmap(result, 0);
            var pages    = new List <Page>();

            foreach (var polygon in polygons)
            {
                var id      = sdk.PageFileStorage.Add(result);
                var page    = new Page(id, new List <PointF>(), DetectionResult.Ok, ImageFilterType.Binarized);
                var cropped = sdk.PageProcessor().CropAndRotate(page, 0, polygon.PolygonF);
                pages.Add(cropped);
            }

            var processor = sdk.BusinessCardsImageProcessor();
            var languages = sdk.OcrRecognizer().InstalledLanguages;

            ProcessedResults = processor.ProcessPages(pages, languages, true, true).ToList();

            var i = 1;

            foreach (var item in ProcessedResults)
            {
                var text = item.OcrResult.RecognizedText;
                Console.WriteLine($"Recognized text on card {i}:\n {text}\n\n");
                i++;
            }

            RunOnUiThread(delegate
            {
                Toast.MakeText(this, $"Found {ProcessedResults.Count} business cards", ToastLength.Short).Show();
                progress.Visibility = ViewStates.Gone;
                var intent          = new Intent(this, typeof(BusinessCardsPreviewActivity));
                StartActivity(intent);
            });
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.BusinessCardsLayout);

            cameraView = FindViewById <ScanbotCameraView>(Resource.Id.camera);

            pictureCallbackDelegate = new PictureCallbackDelegate();
            pictureCallbackDelegate.OnPictureTakenHandler += ProcessTakenPicture;
            cameraView.AddPictureCallback(pictureCallbackDelegate);

            cameraView.SetCameraOpenCallback(this);
            cameraView.SetAutoFocusSound(false);

            progress = FindViewById <ProgressBar>(Resource.Id.progressView);

            shutterButton        = FindViewById <ShutterButton>(Resource.Id.snap);
            shutterButton.Click += delegate
            {
                cameraView.TakePicture(false);
            };
            shutterButton.Post(delegate
            {
                shutterButton.ShowAutoButton();
            });

            sdk = new IO.Scanbot.Sdk.ScanbotSDK(this);
            var detector = sdk.MultipleObjectsDetector();

            if (modParams != null)
            {
                detector.SetParams(modParams);
            }

            var handler = MultipleObjectsFrameHandler.Attach(cameraView, detector);

            var polygon = FindViewById <MultiplePolygonsView>(Resource.Id.polygonView);

            handler.AddResultHandler(new MultipleObjectsCallback());

            FindViewById(Resource.Id.flash).Click += delegate
            {
                flashEnabled = !flashEnabled;
                cameraView.UseFlash(flashEnabled);
            };
        }