Esempio n. 1
0
        public static async Task <OCRData> Detect(IEditableImage Img, Context Ctx, int RectWidth, int RectHeight)
        {
            if (TesAPI == null)
            {
                TesAPI = new TesseractApi(Ctx, AssetsDeployment.OncePerInitialization);
                await TesAPI.Init("eng");

                TesAPI.SetVariable("tessedit_char_whitelist", "0123456789kmKM");
            }

            OCRData Result = new OCRData();

            Result.PngOriginal = Img.ToPng();

            // Crop the detection region
            Img = Img.Crop((Img.Width / 2) - (RectWidth / 2), (Img.Height / 2) - (RectHeight / 2), RectWidth, RectHeight).ToMonochrome();
            Result.PngCropped = Img.ToPng();

            using (MemoryStream PngImage = new MemoryStream()) {
                using (Bitmap Pic = ProcessImage((Bitmap)Img.GetNativeImage()))
                    await Pic.CompressAsync(Bitmap.CompressFormat.Png, 100, PngImage);

                PngImage.Seek(0, SeekOrigin.Begin);
                await TesAPI.SetImage(PngImage);

                Result.PngProcessed = PngImage.ToArray();
            }

            Result.Text = TesAPI.Text;
            return(Result);
        }
Esempio n. 2
0
        private void SavePhoto(IEditableImage image)
        {
#if __IOS__
            var tmp = new UIImage(NSData.FromArray(image.ToPng()));
            tmp.BeginInvokeOnMainThread(() => {
                tmp.SaveToPhotosAlbum(new UIImage.SaveStatus((UIImage affs, NSError error) => {
                    ;
                }));
            });
#endif
#if __ANDROID__
#endif
        }
Esempio n. 3
0
        private void SavePhoto(IEditableImage image)
        {
#if __IOS__
            //On iOS11 following code crashed
            //var tmp = new UIImage(NSData.FromArray(image.ToPng()));
            //tmp.BeginInvokeOnMainThread(() => {
            //    tmp.SaveToPhotosAlbum(new UIImage.SaveStatus((UIImage affs, NSError error) => {
            //        ;
            //    }));
            //});
#endif
#if __ANDROID__
#endif
        }
Esempio n. 4
0
        public void OnPictureTaken(byte[] Data, Camera Cam)
        {
            CamUtils.StopPreview();

            Utils.NewThread(() => {
                IEditableImage Img = CrossImageEdit.Current.CreateImage(Data);
                CamUtils.StartPreview();

                if (CamUtils.GetOrientation() != 0)
                {
                    Img = Img.Rotate(90);
                }

                OnPicture(Img).Wait();
            });
        }
Esempio n. 5
0
        async Task OnPicture(IEditableImage Img)
        {
            ShowLabel("Processing...");

            int W = Img.Width;
            int H = Img.Height;

            OCRData OCRData = await OCR.Detect(Img, ApplicationContext, (int)(W * 0.52f), (int)(H * 0.13f));

            OCR.SaveDebug(OCRData);

            if (OCRData.TryParseKM(out int KM))
            {
                string KMFormat = string.Format("{0} km", KM);
                ShowLabel(KMFormat);

                RunOnUiThread(() => {
                    AlertDialog.Builder AlertBuilder = new AlertDialog.Builder(this);
                    AlertBuilder.SetTitle("Success");
                    AlertBuilder.SetMessage("Use the following? " + KMFormat);
                    AlertBuilder.SetPositiveButton("Yes", (S, E) => {
                        RunOnUiThread(() => {
                            ShowLabel("Fetching location...");

                            Kilometers        = KM;
                            DoBeginLocoVoznja = true;

                            LocationManager LocMgr = (LocationManager)GetSystemService(LocationService);
                            LocMgr.RequestSingleUpdate(LocationManager.GpsProvider, this, Looper.MainLooper);
                        });
                    });

                    AlertBuilder.SetNegativeButton("No", (S, E) => {
                        ShowLabel("User cancelled");
                    });

                    AlertBuilder.Show();
                });
            }
            else
            {
                ShowLabel(null);
                ShowInfoDialog("Info", string.Format("Failed to parse km, got '{0}'", OCRData.Text ?? "none"));
            }
        }
Esempio n. 6
0
        void CreateCompare(IEditableImage image, bool isPng = true)
        {
            var array = image.ToArgbPixels();

            Assert.Equal(3, image.Width);
            Assert.Equal(3, image.Height);

            if (isPng)
            {
                for (var i = 0; i < 3; i++)
                {
                    Assert.Equal(0xFF000000, (uint)array[i]);
                }
                for (var i = 3; i < array.Length; i++)
                {
                    Assert.NotEqual(0xFF000000, (uint)array[i]);
                }
            }
        }