Leadtools.Forms.Ocrアセンブリ > Leadtools.Forms.Ocr名前空間 > IOcrPageCollectionインターフェース > AddPageメソッド :AddPage(RasterImage、OcrProgressCallback)メソッド |
IOcrPage AddPage( RasterImage image, OcrProgressCallback callback )
'Declaration
Overloads Function AddPage( _ ByVal image As RasterImage, _ ByVal callback As OcrProgressCallback _ ) As IOcrPage
'Usage
Dim instance As IOcrPageCollection Dim image As RasterImage Dim callback As OcrProgressCallback Dim value As IOcrPage value = instance.AddPage(image, callback)
IOcrPage AddPage( RasterImage image, OcrProgressCallback callback )
- (nullable LTOcrPage *)addPageWithImage:(LTRasterImage *)image error:(NSError **)error
public OcrPage addPage(RasterImage image,
OcrProgressListener callback)
function Leadtools.Forms.Ocr.IOcrPageCollection.AddPage(RasterImage,OcrProgressCallback)( image , callback )
IOcrPage^ AddPage( RasterImage^ image, OcrProgressCallback^ callback )
このメソッドは、新しく作成されたIOcrPageにRasterImageオブジェクト画像データをコピーします。したがって、このメソッドが返ったあと、imageとIOcrPageの関係がOCRドキュメント内部にありません。たとえば、このメソッドを呼び出した後にimageオブジェクトを必要としないならば、このメソッドが返ったあと、それを破棄しなければなりません。
このメソッドは、変化がimageになされないことを保証します。
imageが1ページ以上を格納するならば、RasterImage.Pageで定義される現在のページはOCRドキュメントに追加されるものです。
OCRドキュメントにすべてまたはマルチページRasterImageオブジェクトのページの特定の範囲を追加するために、1からRasterImage.PageCountへ行くためにRasterImage.Pageの値に変更することによってページを反復処理するか、AddPages(RasterImage image、int imageFirstPageNumber、int imageLastPageNumber、OcrProgressCallbackコールバック)メソッドを使います。
このIOcrPageCollectionにおけるページをすでに持っているならば、このメソッドはコレクションの終わりまでページを追加します。
操作進捗を示すか、それを中止するために、OcrProgressCallbackを使うことができます。詳細情報とサンプルについては、「OcrProgressCallback」を参照してください。
LEADTOOLS OCRエンジンは、150 ドット/インチ(DPI)以上のページをサポートします。DPIが150未満のページを追加しようとするとき、このページのデータを認識することができるかもしれません。
注意:設定している「Recognition.ShareOriginalImage」(Advantage OCRエンジンでサポートされるだけの)の値がサポートされて、trueに設定されるならば、このメソッドを呼び出すことはページの中に参照imageを保存します、そして、IOcrPageが生きる限り、image参照は生きていておかれなければなりません。このモードでは、IOcrPage.GetRasterImage(OcrPageType.Original)を使用して、ページからオリジナル画像の参照を取得できます。オリジナル画像を共有すると、OCR操作中に使用されるメモリ量が少なくなります。
このメンバはメモリベースのドキュメントで機能して、そうでない場合例外をスローするだけです。詳細については、「LEADTOOLS .NET OCRによるIOcrDocumentManager.CreateDocumentとプログラミング」を参照してください。
このサンプルはRasterImageオブジェクトをロードして、LEADTOOLSを用いてそれの上でimageクリーンアップを実行して、そして、OCRドキュメントにそれを追加します
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms.Ocr Imports Leadtools.Forms.DocumentWriters Imports Leadtools.Forms Imports Leadtools.ImageProcessing.Core <TestMethod> Public Sub AddPageOcrExample() ' For this example, we will use the Clean.tif image. This image is skewed so we will do that using the ' LEADTOOLS Deskew command before we add it to the document Dim tifFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif") Dim pdfFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Clean.pdf") ' Load the TIF file Dim codecs As New RasterCodecs() Dim image As RasterImage = codecs.Load(tifFileName) ' Check if the image needs to be deskewed Dim deskewCommand As New DeskewCommand() deskewCommand.FillColor = RasterColor.FromKnownColor(RasterKnownColor.White) deskewCommand.Flags = DeskewCommandFlags.ReturnAngleOnly deskewCommand.Run(image) If deskewCommand.Angle <> 0 Then ' Deskew it deskewCommand.Flags = DeskewCommandFlags.RotateLinear deskewCommand.Run(image) End If ' Create an instance of the engine Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) ' Start the engine using default parameters ' Since we have a RasterCodecs object, re-use it in the OCR engine. Although ' this demo will not use it, it is always a good practice ocrEngine.Startup(codecs, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir) ' Create an OCR document Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() ' Add the image ocrDocument.Pages.AddPage(image, Nothing) ' We do not need the image anymore image.Dispose() ' Recognize ocrDocument.Pages.Recognize(Nothing) ' Save 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 codecs.Dispose() 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.DocumentWriters; using Leadtools.Forms; using Leadtools.ImageProcessing.Core; public void AddPageOcrExample() { // For this example, we will use the Clean.tif image. This image is skewed so we will do that using the // LEADTOOLS Deskew command before we add it to the document string tifFileName = Path.Combine(LEAD_VARS.ImagesDir, "Clean.tif"); string pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Clean.pdf"); // Load the TIF file RasterCodecs codecs = new RasterCodecs(); RasterImage image = codecs.Load(tifFileName); // Check if the image needs to be deskewed DeskewCommand deskewCommand = new DeskewCommand(); deskewCommand.FillColor = RasterColor.FromKnownColor(RasterKnownColor.White); deskewCommand.Flags = DeskewCommandFlags.ReturnAngleOnly; deskewCommand.Run(image); if (deskewCommand.Angle != 0) { // Deskew it deskewCommand.Flags = DeskewCommandFlags.RotateLinear; deskewCommand.Run(image); } // Create an instance of the engine using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)) { // Start the engine using default parameters // Since we have a RasterCodecs object, re-use it in the OCR engine. Although // this demo will not use it, it is always a good practice ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrAdvantageRuntimeDir); // Create an OCR document using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) { // Add the image ocrDocument.Pages.AddPage(image, null); // We do not need the image anymore image.Dispose(); // Recognize ocrDocument.Pages.Recognize(null); // Save 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(); } codecs.Dispose(); } 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.Forms.Ocr; using Leadtools.Forms.DocumentWriters; using Leadtools.Forms; using Leadtools.ImageProcessing.Core; public async Task AddPageOcrExample() { // For this example, we will use the Clean.tif image. This image is skewed so we will do that using the // LEADTOOLS Deskew command before we add it to the document string tifFileName = @"Assets\Clean.tif"; string pdfFileName = "Clean.pdf"; // Load the TIF file RasterCodecs codecs = new RasterCodecs(); StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(tifFileName); RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); // Check if the image needs to be deskewed DeskewCommand deskewCommand = new DeskewCommand(); deskewCommand.FillColor = RasterColorHelper.FromKnownColor(RasterKnownColor.White); deskewCommand.Flags = DeskewCommandFlags.ReturnAngleOnly; deskewCommand.Run(image); if(deskewCommand.Angle != 0) { // Deskew it deskewCommand.Flags = DeskewCommandFlags.RotateLinear; deskewCommand.Run(image); } // Create an instance of the engine IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false); // Start the engine using default parameters // Since we have a RasterCodecs object, re-use it in the OCR engine. Although // this demo will not use it, it is always a good practice ocrEngine.Startup(codecs, null, String.Empty, Tools.OcrEnginePath); // Create an OCR document IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument(); // Add the image ocrDocument.Pages.AddPage(image, null); // We do not need the image anymore image.Dispose(); // Recognize ocrDocument.Pages.Recognize(null); // Save StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(pdfFileName, CreationCollisionOption.ReplaceExisting); await ocrDocument.SaveAsync(LeadStreamFactory.Create(saveFile), DocumentFormat.Pdf, null); // Shutdown the engine ocrEngine.Shutdown(); codecs.Dispose(); }