本文整理汇总了C#中TesseractEngine.Process方法的典型用法代码示例。如果您正苦于以下问题:C# TesseractEngine.Process方法的具体用法?C# TesseractEngine.Process怎么用?C# TesseractEngine.Process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TesseractEngine
的用法示例。
在下文中一共展示了TesseractEngine.Process方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例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: 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(""));
}
}
}
}
示例4: 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));
}
}
}
}
示例5: 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));
}
}
}
}
示例6: 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));
}
}
}
}
示例7: 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>
"));
}
示例8: 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++;
}
}
}
}
示例9: CanProcessDifferentRegionsInSameImage
public void CanProcessDifferentRegionsInSameImage()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
using (var img = Pix.LoadFromFile("./phototest.tif")) {
using (var page = engine.Process(img, Rect.FromCoords(0, 0, img.Width, 188))) {
var region1Text = page.GetText();
const string expectedTextRegion1 =
"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\n";
Assert.That(region1Text, Is.EqualTo(expectedTextRegion1));
page.RegionOfInterest = Rect.FromCoords(0, 188, img.Width, img.Height);
var region2Text = page.GetText();
const string expectedTextRegion2 =
"The 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(region2Text, Is.EqualTo(expectedTextRegion2));
}
}
}
}
示例10: WritesOutThresholdedImageWhenOCRing
public void WritesOutThresholdedImageWhenOCRing()
{
var expectedFilePath = Path.Combine(Environment.CurrentDirectory, "tessinput.tif");
if (File.Exists(expectedFilePath)) {
File.Delete(expectedFilePath);
}
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
engine.SetVariable("tessedit_write_images", true);
using (var img = Pix.LoadFromFile("./phototest.tif")) {
using (var page = engine.Process(img)) {
var region1Text = page.GetText();
Assert.That(File.Exists(expectedFilePath));
}
}
}
}
示例11: Initialise_CanLoadConfigFile
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));
}
}
}
}
示例12: CanSetClassifyBlnNumericModeVariable
public void CanSetClassifyBlnNumericModeVariable()
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) {
engine.SetVariable("classify_bln_numeric_mode", 1);
using (var img = Pix.LoadFromFile("./Data/processing/numbers.png")) {
using (var page = engine.Process(img)) {
var text = page.GetText();
const string expectedText = "1234567890\n\n";
Assert.That(text, Is.EqualTo(expectedText));
}
}
}
}
示例13: CanProcessPixUsingResultIterator
public void CanProcessPixUsingResultIterator()
{
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 = WriteResultsToString(page);
}
}
}
const string ExpectedResultPath = "./Results/EngineTests.CanProcessPixUsingResultIterator.txt";
var expectedResult = File.ReadAllText(ExpectedResultPath);
if (expectedResult != actualResult) {
var actualResultPath = String.Format("./Results/EngineTests.CanProcessPixUsingResultIterator_{0:yyyyMMddTHHmmss}.txt", DateTime.UtcNow);
File.WriteAllText(actualResultPath, actualResult);
Assert.Fail("Expected results to be {0} but was {1}", ExpectedResultPath, actualResultPath);
}
}
示例14: Main
public static void Main(string[] args)
{
var testImagePath = "./phototest.tif";
if (args.Length > 0)
{
testImagePath = args[0];
}
try
{
using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default))
{
using (var img = Pix.LoadFromFile(testImagePath))
{
using (var page = engine.Process(img))
{
var text = page.GetText();
Console.WriteLine("Mean confidence: {0}", page.GetMeanConfidence());
Console.WriteLine("Text (GetText): \r\n{0}", text);
Console.WriteLine("Text (iterator):");
using (var iter = page.GetIterator())
{
iter.Begin();
do
{
do
{
do
{
do
{
if (iter.IsAtBeginningOf(PageIteratorLevel.Block))
{
Console.WriteLine("<BLOCK>");
}
Console.Write(iter.GetText(PageIteratorLevel.Word));
Console.Write(" ");
if (iter.IsAtFinalOf(PageIteratorLevel.TextLine, PageIteratorLevel.Word))
{
Console.WriteLine();
}
} while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
if (iter.IsAtFinalOf(PageIteratorLevel.Para, PageIteratorLevel.TextLine))
{
Console.WriteLine();
}
} while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
} while (iter.Next(PageIteratorLevel.Block, PageIteratorLevel.Para));
} while (iter.Next(PageIteratorLevel.Block));
}
}
}
}
}
catch (Exception e)
{
Trace.TraceError(e.ToString());
Console.WriteLine("Unexpected Error: " + e.Message);
Console.WriteLine("Details: ");
Console.WriteLine(e.ToString());
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}