Exemplo n.º 1
0
 public virtual void TestDefaultTessDataPathValidationForLib()
 {
     NUnit.Framework.Assert.That(() => {
         String path      = TEST_IMAGES_DIRECTORY + "numbers_01.jpg";
         FileInfo imgFile = new FileInfo(path);
         Tesseract4LibOcrEngine engine = new Tesseract4LibOcrEngine(new Tesseract4OcrEngineProperties());
         engine.DoImageOcr(imgFile);
     }
                                 , NUnit.Framework.Throws.InstanceOf <Tesseract4OcrException>().With.Message.EqualTo(Tesseract4OcrException.PATH_TO_TESS_DATA_IS_NOT_SET))
     ;
 }
Exemplo n.º 2
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))
     ;
 }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }