当前位置: 首页>>代码示例>>C#>>正文


C# TesseractEngine.Process方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:JonathanKeav,项目名称:tesseract,代码行数:25,代码来源:Default.aspx.cs

示例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);
            }
        }
开发者ID:nonameShadow,项目名称:tesseract,代码行数:25,代码来源:EngineTests.cs

示例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(""));

                    }
                }
            }
        }
开发者ID:nikolay87,项目名称:tesseract,代码行数:13,代码来源:EngineTests.cs

示例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));
                    }
                }
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:15,代码来源:EngineTests.cs

示例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));

					}
				}    
			}
		}
开发者ID:Picazsoo,项目名称:tesseract,代码行数:15,代码来源:EngineTests.cs

示例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));
                    }
                }
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:16,代码来源:EngineTests.cs

示例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>
            "));
        }
开发者ID:odflash,项目名称:tesseract,代码行数:17,代码来源:EngineTests.cs

示例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++;
					}
				}
			}
		}
开发者ID:Picazsoo,项目名称:tesseract,代码行数:17,代码来源:EngineTests.cs

示例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));
                    }
                }
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:23,代码来源:EngineTests.cs

示例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));
                    }
                }
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:20,代码来源:EngineTests.cs

示例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));
                    }
                }
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:24,代码来源:EngineTests.cs

示例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));
                    }
                }
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:16,代码来源:EngineTests.cs

示例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);
            }
        }
开发者ID:odflash,项目名称:tesseract,代码行数:19,代码来源:EngineTests.cs

示例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);
        }
开发者ID:modulexcite,项目名称:tessseract-samples,代码行数:69,代码来源:Program.cs


注:本文中的TesseractEngine.Process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。