Leadtools.Forms.Ocrアセンブリ > Leadtools.Forms.Ocr名前空間 > IOcrPageインターフェース :AutoPreprocessメソッド |
void AutoPreprocess( OcrAutoPreprocessPageCommand command, OcrProgressCallback callback )
'Declaration
Sub AutoPreprocess( _ ByVal command As OcrAutoPreprocessPageCommand, _ ByVal callback As OcrProgressCallback _ )
'Usage
Dim instance As IOcrPage Dim command As OcrAutoPreprocessPageCommand Dim callback As OcrProgressCallback instance.AutoPreprocess(command, callback)
void AutoPreprocess( OcrAutoPreprocessPageCommand command, OcrProgressCallback callback )
- (BOOL)autoPreprocess:(LTOcrAutoPreprocessPageCommand)command progress:(nullable LTOcrProgressHandler)progressHandler error:(NSError **)error
public void autoPreprocess(OcrAutoPreprocessPageCommand command, OcrProgressListener callback)
void AutoPreprocess( OcrAutoPreprocessPageCommand command, OcrProgressCallback^ callback )
傾きにこのメソッドを使うか、回転するか、コマンドによってimageを反転します。ページの上で自動前処理を実行することによって、ドラフトモードファックスの画質を改善することができます。
操作進捗を示すか、それを中止するために、OcrProgressCallbackを使います。詳細情報とサンプルについては、「OcrProgressCallback」を参照してください。
Recognizeを呼び出す前に、このメソッドを呼び出します。
このメソッドはページが処理を必要とするかどうか決定するためにGetDeskewAngle、GetRotateAngleとIsInvertedを呼び出します、ページがそうするならば、このメソッド意志はそれに応じてimageを内部的にひずみ補正するか、回転させるか、反転します。
imageがゆがめられるならば、GetDeskewAngleはimageをひずみ補正するために必要な角度を返します、ページの上でAutoPreprocessを呼び出すならば、imageがもはやゆがめられないため、GetDeskewAngleへのすべての以降の呼び出しは0を返します。GetRotateAngleとIsInvertedも同様。
累積的な前処理値を得る使用GetPreprocessValuesは、このIOcrPageに適用しました。
このメソッドは、imageの流れと処理バージョンの上で機能します。たとえば斜めになっているページを追加してAutoPreprocess幅OcrAutoPreprocessPageCommand.Deskewを呼び出す場合、現在の画像または処理中の画像をGetRasterImageで取得すると、取得するラスター画像オブジェクトは2つとも回転しています(斜めになっています)。
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms.Ocr Imports Leadtools.Forms Imports Leadtools.Forms.DocumentWriters Imports Leadtools.WinForms Imports Leadtools.Drawing Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color <TestMethod> Public Sub AutoPreprocessExample() Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif") Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Clean.pdf") ' Create an instance of the engine Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) ' Start the engine using default parameters ocrEngine.Startup(Nothing, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir) ' Create an OCR document Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() ' Add this image to the document Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(tifFileName, Nothing) ' Auto-preprocess it ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, Nothing) ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Invert, Nothing) ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Rotate, Nothing) ' Recognize it and save it as PDF ocrPage.Recognize(Nothing) ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, Nothing) End Using ' Shutdown the engine ' Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown() End Using End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms.Ocr; using Leadtools.Forms; using Leadtools.Forms.DocumentWriters; using Leadtools.WinForms; using Leadtools.Drawing; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; public void AutoPreprocessExample() { string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif"); string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Clean.pdf"); // Create an instance of the engine using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)) { // Start the engine using default parameters ocrEngine.Startup(null, null, null, LEAD_VARS.OcrAdvantageRuntimeDir); // Create an OCR document using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) { // Add this image to the document IOcrPage ocrPage = ocrDocument.Pages.AddPage(tifFileName, null); // Auto-preprocess it ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, null); ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Invert, null); ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Rotate, null); // Recognize it and save it as PDF ocrPage.Recognize(null); ocrDocument.Save(pdfFileName, DocumentFormat.Pdf, null); } // Shutdown the engine // Note: calling Dispose will also automatically shutdown the engine if it has been started ocrEngine.Shutdown(); } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"; }
using Leadtools; using Leadtools.Codecs; using Leadtools.Controls; using Leadtools.Forms.Ocr; using Leadtools.Forms; using Leadtools.Forms.DocumentWriters; using Leadtools.ImageProcessing; public async Task AutoPreprocessExample() { string tifFileName = @"Assets\Clean.tif"; string pdfFileName = "Clean.pdf"; // Create an instance of the engine IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false); // Start the engine using default parameters ocrEngine.Startup(null, null, String.Empty, Tools.OcrEnginePath); // Create an OCR document IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(); // Add this image to the document IOcrPage ocrPage = null; using (RasterCodecs codecs = new RasterCodecs()) { StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName); using (RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile))) ocrPage = ocrDocument.Pages.AddPage(image, null); } // Auto-preprocess it ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Deskew, null); ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Invert, null); ocrPage.AutoPreprocess(OcrAutoPreprocessPageCommand.Rotate, null); // Recognize it and save it as PDF ocrPage.Recognize(null); StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting); await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null); // Shutdown the engine ocrEngine.Shutdown(); }