Example #1
0
        public void Initialise_CanLoadConfigFile()
        {
            var tessDataPath = Path.Combine(Environment.CurrentDirectory, @"tessdata\");

            using (var engine = new TesseractEngine(tessDataPath, "eng", EngineMode.Default, "bazzar")) {
                // verify that the config file was loaded
                string user_patterns_suffix;
                if (engine.TryGetStringVariable("user_words_suffix", out user_patterns_suffix))
                {
                    Assert.That(user_patterns_suffix, Is.EqualTo("user-words"));
                }
                else
                {
                    Assert.Fail("Failed to retrieve value for 'user_words_suffix'.");
                }

                using (var img = Pix.LoadFromFile("./phototest.tif")) {
                    using (var page = engine.Process(img)) {
                        var text = page.GetText();

                        const string expectedText =
                            "This is a Iot of 12 point text to test the\nocr code and see if it works on all types\nof file format.\n\nThe quick brown dog jumped over the\nIazy fox. The quick brown dog jumped\nover the Iazy fox. The quick brown dog\njumped over the Iazy fox. The quick\nbrown dog jumped over the Iazy fox.\n\n";

                        Assert.That(text, Is.EqualTo(expectedText));
                    }
                }
            }
        }
Example #2
0
        public void Initialise_CanLoadConfigFile()
        {
            using (var engine = new TesseractEngine(DataPath, "eng", EngineMode.Default, "bazzar"))
            {
                // verify that the config file was loaded
                string user_patterns_suffix;
                if (engine.TryGetStringVariable("user_words_suffix", out user_patterns_suffix))
                {
                    Assert.AreEqual(user_patterns_suffix, "user-words");
                }
                else
                {
                    Assert.Fail("Failed to retrieve value for 'user_words_suffix'.");
                }

                using (var img = LoadTestPix(TestImagePath))
                {
                    using (var page = engine.Process(img))
                    {
                        var text = page.GetText();

                        const string expectedText =
                            "This is a lot of 12 point text to test the\nocr code and see if it works on all types\nof file format.\n\nThe quick brown dog jumped over the\nlazy fox. The quick brown dog jumped\nover the lazy fox. The quick brown dog\njumped over the lazy fox. The quick\nbrown dog jumped over the lazy fox.\n";
                        Assert.AreEqual(text, expectedText);
                    }
                }
            }
        }
Example #3
0
 public void CanGetStringVariableThatDoesNotExist()
 {
     using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
         String  result;
         Boolean success = engine.TryGetStringVariable("illegal-variable", out result);
         Assert.That(success, Is.False);
         Assert.That(result, Is.Null);
     }
 }
Example #4
0
 [TestCase("tessedit_char_whitelist", "chinese 漢字")] // Issue 68
 public void CanSetStringVariable(string variableName, string variableValue)
 {
     using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
         var variableWasSet = engine.SetVariable(variableName, variableValue);
         Assert.That(variableWasSet, Is.True, "Failed to set variable '{0}'.", variableName);
         string result;
         if (engine.TryGetStringVariable(variableName, out result))
         {
             Assert.That(result, Is.EqualTo(variableValue));
         }
         else
         {
             Assert.Fail("Failed to retrieve value for '{0}'.", variableName);
         }
     }
 }
Example #5
0
        /*
         *      [TestCase("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")]
         *      [TestCase("tessedit_char_whitelist", "")]
         *      [TestCase("tessedit_char_whitelist", "Test")]
         *      [TestCase("tessedit_char_whitelist", "chinese 漢字")] // Issue 68
         *      public void CanSetStringVariable(string variableName, string variableValue)
         */
        public void CanSetStringVariable()
        {
            string variableName  = "tessedit_char_whitelist";
            string variableValue = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

            using (var engine = new TesseractEngine(TDP, "eng", EngineMode.Default)) {
                var variableWasSet = engine.SetVariable(variableName, variableValue);
                Assert.IsTrue(variableWasSet, "failed to set variable: " + variableName);
                //Assert.That(variableWasSet, Is.True, "Failed to set variable '{0}'.", variableName);
                string result;
                if (engine.TryGetStringVariable(variableName, out result))
                {
                    Assert.AreEqual(variableValue, result);
                    //Assert.That(result, Is.EqualTo(variableValue));
                }
                else
                {
                    Assert.Fail("Failed to retrieve value for '{0}'.", variableName);
                }
            }
        }
Example #6
0
        public void Initialise_CanLoadConfigFile()
        {
            var tessDataPath = Path.Combine(Environment.CurrentDirectory, @"tessdata\");
            using (var engine = new TesseractEngine(tessDataPath, "eng", EngineMode.Default, "bazzar")) {
                // verify that the config file was loaded
                string user_patterns_suffix;
                if (engine.TryGetStringVariable("user_words_suffix", out user_patterns_suffix)) {
                    Assert.That(user_patterns_suffix, Is.EqualTo("user-words"));
                } else {
                    Assert.Fail("Failed to retrieve value for 'user_words_suffix'.");
                }

                using (var img = Pix.LoadFromFile("./phototest.tif")) {
                    using (var page = engine.Process(img)) {
                        var text = page.GetText();

                        const string expectedText =
                            "This is a Iot of 12 point text to test the\nocr code and see if it works on all types\nof file format.\n\nThe quick brown dog jumped over the\nIazy fox. The quick brown dog jumped\nover the Iazy fox. The quick brown dog\njumped over the Iazy fox. The quick\nbrown dog jumped over the Iazy fox.\n\n";

                        Assert.That(text, Is.EqualTo(expectedText));
                    }
                }
            }
        }
Example #7
0
 public void CanSetStringVariable(string variableName, string variableValue)
 {
     using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
         var variableWasSet = engine.SetVariable(variableName, variableValue);
         Assert.That(variableWasSet, Is.True, "Failed to set variable '{0}'.", variableName);
         string result;
         if (engine.TryGetStringVariable(variableName, out result)) {
             Assert.That(result, Is.EqualTo(variableValue));
         } else {
             Assert.Fail("Failed to retrieve value for '{0}'.", variableName);
         }
     }
 }
Example #8
0
 public void CanGetStringVariableThatDoesNotExist()
 {
     using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
         String result;
         Boolean success = engine.TryGetStringVariable("illegal-variable", out result);
         Assert.That(success, Is.False);
         Assert.That(result, Is.Null);
     }
 }