本文整理汇总了C#中TesseractEngine类的典型用法代码示例。如果您正苦于以下问题:C# TesseractEngine类的具体用法?C# TesseractEngine怎么用?C# TesseractEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TesseractEngine类属于命名空间,在下文中一共展示了TesseractEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialise_WithTessDataPrefixSet
public void Initialise_WithTessDataPrefixSet()
{
Environment.SetEnvironmentVariable("TESSDATA_PREFIX", Environment.CurrentDirectory);
using (var engine = new TesseractEngine(null, "eng", EngineMode.Default)) {
}
}
示例2: CanGenerateHOCROutput
public void CanGenerateHOCROutput()
{
string actualResult;
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using (var img = Pix.LoadFromFile("./phototest.tif")) {
using (var page = engine.Process(img)) {
actualResult = NormaliseNewLine(page.GetHOCRText(1));
}
}
}
const string ExpectedResultPath = "./Results/EngineTests.CanGenerateHOCROutput.txt";
if (File.Exists(ExpectedResultPath)) {
var expectedResult = NormaliseNewLine(File.ReadAllText(ExpectedResultPath));
if (expectedResult != actualResult) {
var actualResultPath = String.Format("./Results/EngineTests.CanGenerateHOCROutput_{0:yyyyMMddTHHmmss}.txt", DateTime.UtcNow);
File.WriteAllText(actualResultPath, actualResult);
Assert.Fail("Expected results to be {0} but was {1}", ExpectedResultPath, actualResultPath);
}
} else {
var actualResultPath = String.Format("./Results/EngineTests.CanGenerateHOCROutput_{0:yyyyMMddTHHmmss}.txt", DateTime.UtcNow);
File.WriteAllText(actualResultPath, actualResult);
Assert.Fail("Expected result did not exist, actual results saved to {0}", actualResultPath);
}
}
示例3: OnSubmitFileClicked
private void OnSubmitFileClicked(object sender, EventArgs args)
{
if (imageFile.PostedFile != null && imageFile.PostedFile.ContentLength > 0)
{
// for now just fail hard if there's any error however in a propper app I would expect a full demo.
using (var engine = new TesseractEngine(Server.MapPath(@"./tessdata"), "eng", EngineMode.Default))
{
// have to load Pix via a bitmap since Pix doesn't support loading a stream.
using (var image = new System.Drawing.Bitmap(imageFile.PostedFile.InputStream))
{
using (var pix = PixConverter.ToPix(image))
{
using (var page = engine.Process(pix))
{
meanConfidenceLabel.InnerText = String.Format("{0:P}", page.GetMeanConfidence());
resultText.InnerText = page.GetText();
}
}
}
}
inputPanel.Visible = false;
resultPanel.Visible = true;
}
}
示例4: Initialise_Rus_ShouldStartEngine
public void Initialise_Rus_ShouldStartEngine()
{
using (var engine = new TesseractEngine(@"./tessdata", "rus", EngineMode.Default)) {
}
}
示例5: Initialise_ShouldStartEngine
public void Initialise_ShouldStartEngine(
[ValueSource("DataPaths")] string datapath)
{
using (var engine = new TesseractEngine(datapath, "eng", EngineMode.Default)) {
}
}
示例6: Initialise_ShouldThrowErrorIfDatapathNotCorrect
public void Initialise_ShouldThrowErrorIfDatapathNotCorrect()
{
Assert.That(() => {
using (var engine = new TesseractEngine(@"./IDontExist", "eng", EngineMode.Default)) {
}
}, Throws.InstanceOf(typeof(TesseractException)));
}
示例7: CanSetDoubleVariable
public void CanSetDoubleVariable(string variableName, double 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);
double result;
if(engine.TryGetDoubleVariable(variableName, out result)) {
Assert.That(result, Is.EqualTo(variableValue));
} else {
Assert.Fail("Failed to retrieve value for '{0}'.", variableName);
}
}
}
示例8: CanParseText
public void CanParseText()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using(var img = Pix.LoadFromFile("./phototest.tiff")) {
using(var page = engine.Process(img)) {
var text = page.GetText();
Assert.That(text, Is.EqualTo(""));
}
}
}
}
示例9: CanSetBooleanVariable
public void CanSetBooleanVariable(bool variableValue)
{
const string VariableName = "classify_enable_learning";
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);
bool result;
if(engine.TryGetBoolVariable(VariableName, out result)) {
Assert.That(result, Is.EqualTo(variableValue));
} else {
Assert.Fail("Failed to retrieve value for '{0}'.", VariableName);
}
}
}
示例10: CanProcessBitmap
public void CanProcessBitmap()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using (var img = new Bitmap("./phototest.tif")) {
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\n";
Assert.That(text, Is.EqualTo(expectedText));
}
}
}
}
示例11: CanParseText_UsingMode
public void CanParseText_UsingMode(PageSegMode mode, String expectedText)
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
var demoFilename = String.Format("./Data/Ocr/PSM_{0}.png", mode);
using (var pix = Pix.LoadFromFile(demoFilename)) {
using (var page = engine.Process(pix, mode)) {
var text = page.GetText().Trim();
Assert.That(text, Is.EqualTo(expectedText));
}
}
}
}
示例12: CanParseUznFile
public void CanParseUznFile()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
var inputFilename = TestFilePath(@"Ocr\uzn-test.png");
using (var img = Pix.LoadFromFile(inputFilename)) {
using (var page = engine.Process(img, inputFilename, PageSegMode.SingleLine)) {
var text = page.GetText();
const string expectedText =
"This is another test\n\n";
Assert.That(text, Is.EqualTo(expectedText));
}
}
}
}
示例13: CanParseMultipageTif
public void CanParseMultipageTif()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using (var pixA = PixArray.LoadMultiPageTiffFromFile("./Data/processing/multi-page.tif")) {
int i = 1;
foreach (var pix in pixA) {
using (var page = engine.Process(pix)) {
var text = page.GetText().Trim();
string expectedText = String.Format("Page {0}", i);
Assert.That(text, Is.EqualTo(expectedText));
}
i++;
}
}
}
}
示例14: CanProcessEmptyPxUsingResultIterator
public void CanProcessEmptyPxUsingResultIterator()
{
string actualResult;
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using (var img = Pix.LoadFromFile("./data/ocr/empty.png")) {
using (var page = engine.Process(img)) {
actualResult = WriteResultsToString(page);
}
}
}
Assert.That(actualResult, Is.EqualTo(
@"</word></line>
</para>
</block>
"));
}
示例15: SetVariablesAccordingToConfig
private static void SetVariablesAccordingToConfig(TesseractEngine engine, ZoneConfiguration barcodeConfig)
{
if (barcodeConfig.TextualDataFilter.FilterType == FilterType.Alpha)
{
engine.SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-");
}
if (barcodeConfig.TextualDataFilter.FilterType == FilterType.AlphaOnly)
{
engine.SetVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZ-");
}
if (barcodeConfig.TextualDataFilter.FilterType == FilterType.Digits)
{
engine.SetVariable("tessedit_char_whitelist", "0123456789");
}
if (barcodeConfig.TextualDataFilter.FilterType == FilterType.Number)
{
engine.SetVariable("tessedit_char_whitelist", "0123456789,.");
}
}