Пример #1
0
        public virtual void TestPixSavingAsPng()
        {
            String path        = TEST_IMAGES_DIRECTORY + "numbers_01.jpg";
            String tmpFileName = GetTargetDirectory() + "testPixSavingAsPng.png";

            NUnit.Framework.Assert.IsFalse(File.Exists(System.IO.Path.Combine(tmpFileName)));
            Pix pix = ImagePreprocessingUtil.ReadPix(new FileInfo(path));

            TesseractOcrUtil.SavePixToTempPngFile(tmpFileName, pix);
            NUnit.Framework.Assert.IsTrue(File.Exists(System.IO.Path.Combine(tmpFileName)));
            TesseractHelper.DeleteFile(tmpFileName);
            NUnit.Framework.Assert.IsFalse(File.Exists(System.IO.Path.Combine(tmpFileName)));
        }
Пример #2
0
        public virtual void TestTesseract4OcrForPix()
        {
            String   path     = TEST_IMAGES_DIRECTORY + "numbers_02.jpg";
            String   expected = "0123456789";
            FileInfo imgFile  = new FileInfo(path);
            Pix      pix      = ImagePreprocessingUtil.ReadPix(imgFile);
            Tesseract4LibOcrEngine tesseract4LibOcrEngine = GetTesseract4LibOcrEngine();

            tesseract4LibOcrEngine.SetTesseract4OcrEngineProperties(new Tesseract4OcrEngineProperties().SetPathToTessData
                                                                        (GetTessDataDirectory()));
            tesseract4LibOcrEngine.InitializeTesseract(OutputFormat.TXT);
            String result = new TesseractOcrUtil().GetOcrResultAsString(tesseract4LibOcrEngine.GetTesseractInstance(),
                                                                        pix, OutputFormat.TXT);

            NUnit.Framework.Assert.IsTrue(result.Contains(expected));
        }