Example #1
0
 public virtual void TestOcrResultForSinglePageForNullImage()
 {
     NUnit.Framework.Assert.That(() => {
         Tesseract4LibOcrEngine tesseract4LibOcrEngine = GetTesseract4LibOcrEngine();
         tesseract4LibOcrEngine.SetTesseract4OcrEngineProperties(new Tesseract4OcrEngineProperties().SetPathToTessData
                                                                     (GetTessDataDirectory()));
         tesseract4LibOcrEngine.InitializeTesseract(OutputFormat.TXT);
         tesseract4LibOcrEngine.DoTesseractOcr(null, null, OutputFormat.HOCR);
     }
                                 , NUnit.Framework.Throws.InstanceOf <Tesseract4OcrException>().With.Message.EqualTo(Tesseract4OcrException.TESSERACT_FAILED))
     ;
 }
Example #2
0
        public virtual void TestGetOcrResultAsStringForFile()
        {
            String   path     = TEST_IMAGES_DIRECTORY + "numbers_01.jpg";
            String   expected = "619121";
            FileInfo imgFile  = new FileInfo(path);
            Tesseract4LibOcrEngine tesseract4LibOcrEngine = GetTesseract4LibOcrEngine();

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

            NUnit.Framework.Assert.IsTrue(result.Contains(expected));
        }
Example #3
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));
        }
Example #4
0
        public virtual void TestOcrResultConditions()
        {
            Tesseract4LibOcrEngine tesseract4LibOcrEngine = GetTesseract4LibOcrEngine();

            tesseract4LibOcrEngine.SetTesseract4OcrEngineProperties(new Tesseract4OcrEngineProperties().SetPathToTessData
                                                                        (GetTessDataDirectory()));
            tesseract4LibOcrEngine.InitializeTesseract(OutputFormat.HOCR);
            Pix pix = null;

            NUnit.Framework.Assert.IsNull(new TesseractOcrUtil().GetOcrResultAsString(tesseract4LibOcrEngine.GetTesseractInstance
                                                                                          (), pix, OutputFormat.HOCR));
            FileInfo file = null;

            NUnit.Framework.Assert.IsNull(new TesseractOcrUtil().GetOcrResultAsString(tesseract4LibOcrEngine.GetTesseractInstance
                                                                                          (), file, OutputFormat.HOCR));
            System.Drawing.Bitmap bi = null;
            NUnit.Framework.Assert.IsNull(new TesseractOcrUtil().GetOcrResultAsString(tesseract4LibOcrEngine.GetTesseractInstance
                                                                                          (), bi, OutputFormat.HOCR));
        }