Beispiel #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);
        }
        public async void Sample4JpgWithSetVariable()
        {
            await _api.Init("eng");

            _api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
            using (var stream = LoadSample("sample4.jpg")) {
                var result = await _api.SetImage(stream);

                Assert.IsTrue(result);
                Assert.IsTrue(_api.Text.Contains("Good font for the OCR"));
            }
        }
        public async void Sample4JpgWithSetVariable()
        {
            await _api.Init("eng");

            _api.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
            using (var stream = LoadSample("sample4.jpg")) {
                var result = await _api.SetImage(stream);

                Assert.IsTrue(result);
                Assert.AreEqual(
                    "Good font for the OCR\nDingufrfom n Me am\nhe mm mm m cm\n\nGood 60m size for ocn\n\n", _api.Text);
            }
        }