void RunDocumentDetection(NSUrl imgurl)
        {
            DebugLog("Performing document detection on image " + imgurl);
            Task.Run(() =>
            {
                // The SDK call is sync!
                var detectionResult = SBSDK.DetectDocument(imgurl);
                if (detectionResult.Status.IsOk())
                {
                    var imageResult = detectionResult.Image as UIImage;
                    DebugLog("Detection result image: " + imageResult);
                    documentImageUrl = AppDelegate.TempImageStorage.AddImage(imageResult);

                    ShowImageView(imageResult);

                    DebugLog("Detection result polygon: ");
                    string resultString = "";
                    foreach (var p in detectionResult.Polygon)
                    {
                        resultString += p + "\n";
                    }
                    DebugLog(resultString);
                }
                else
                {
                    DebugLog("No Document detected! DetectionStatus = " + detectionResult.Status);
                    ShowErrorMessage("No Document detected! DetectionStatus = " + detectionResult.Status);
                }
            });
        }
Esempio n. 2
0
        void RunDocumentDetection(AndroidNetUri imageUri)
        {
            DebugLog("Running document detection on image: " + imageUri);

            Task.Run(() =>
            {
                try
                {
                    // The SDK call is sync!
                    var detectionResult = SBSDK.DetectDocument(imageUri, this);
                    DebugLog("Document detection result: " + detectionResult.Status);
                    if (detectionResult.Status.IsOk())
                    {
                        var documentImage = detectionResult.Image as Bitmap;
                        documentImageUri  = MainApplication.TempImageStorage.AddImage(documentImage);
                        ShowImageView(documentImage);

                        DebugLog("Detected polygon: ");
                        foreach (var p in detectionResult.Polygon)
                        {
                            DebugLog(p.ToString());
                        }
                    }
                    else
                    {
                        DebugLog("No document detected!");
                        RunOnUiThread(() =>
                        {
                            Toast.MakeText(this, "No document detected! (Detection result: " + detectionResult.Status + ")", ToastLength.Long).Show();
                        });
                    }
                }
                catch (Exception e)
                {
                    ErrorLog("Error while document detection", e);
                }
            });
        }
Esempio n. 3
0
        private void DetectDocument(Bitmap bitmap)
        {
            if (!CheckScanbotSDKLicense())
            {
                return;
            }

            //store original image as file
            var originalImgUri  = MainApplication.TempImageStorage.AddImage(bitmap);
            var detectionResult = SBSDK.DetectDocument(bitmap);

            DebugLog("Document detection result: " + detectionResult.Status);

            if (detectionResult.Status.IsOk())
            {
                var documentImage = detectionResult.Image as Bitmap;
                imageView1.SetImageBitmap(documentImage);
                //Store data as docu file
                documentImageUri = MainApplication.TempImageStorage.AddImage(documentImage);

                DebugLog("Detected polygon: ");
                foreach (var p in detectionResult.Polygon)
                {
                    DebugLog(p.ToString());
                }
            }
            else
            {
                //No docu!
                documentImageUri = originalImgUri;
                DebugLog("No document detected!");
            }

            if (documentImageUri != null)
            {
                RecognizeText();
            }
        }
        public void OnPictureTaken(byte[] image, int imageOrientation)
        {
            // Here we get the full image from the camera and apply document detection on it.
            // Implement a suitable async(!) detection and image handling here.
            // This is just a demo showing detected image as downscaled preview image.

            Log.Debug(LOG_TAG, "OnPictureTaken: imageOrientation = " + imageOrientation);

            // Show progress spinner:
            RunOnUiThread(() => {
                imageProcessingProgress.Visibility = ViewStates.Visible;
                userGuidanceTextView.Visibility    = ViewStates.Gone;
            });

            // decode bytes as Bitmap
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InSampleSize = 1;
            var originalBitmap = BitmapFactory.DecodeByteArray(image, 0, image.Length, options);

            // rotate original image if required:
            if (imageOrientation > 0)
            {
                Matrix matrix = new Matrix();
                matrix.SetRotate(imageOrientation, originalBitmap.Width / 2f, originalBitmap.Height / 2f);
                originalBitmap = Bitmap.CreateBitmap(originalBitmap, 0, 0, originalBitmap.Width, originalBitmap.Height, matrix, false);
            }

            // Store the original image as file:
            var originalImgUri = MainApplication.TempImageStorage.AddImage(originalBitmap);

            Android.Net.Uri documentImgUri = null;
            // Run document detection on original image:
            var detectionResult = SBSDK.DetectDocument(originalBitmap);

            if (detectionResult.Status.IsOk())
            {
                var documentImage = detectionResult.Image as Bitmap;
                // Store the document image as file:
                documentImgUri = MainApplication.TempImageStorage.AddImage(documentImage);
            }
            else
            {
                // No document detected! Use original image as document image, so user can try to apply manual cropping.
                documentImgUri = originalImgUri;
            }

            //this.detectedPolygon = detectionResult.Polygon;

            Bundle extras = new Bundle();

            extras.PutString(EXTRAS_ARG_DOC_IMAGE_FILE_URI, documentImgUri.ToString());
            extras.PutString(EXTRAS_ARG_ORIGINAL_IMAGE_FILE_URI, originalImgUri.ToString());
            Intent intent = new Intent();

            intent.PutExtras(extras);
            SetResult(Result.Ok, intent);

            Finish();
            return;

            /* If you want to continue scanning:
             * RunOnUiThread(() => {
             *  // continue camera preview
             *  cameraView.StartPreview();
             *  cameraView.ContinuousFocus();
             * });
             */
        }