ストリームから読む方法
ストリームデータとは、読み書き可能なバイナリ情報の連続的な流れを指します。 プログラミングおよびデータ処理のコンテキストでは、ストリームはメモリ全体に収まらない可能性があるデータを効率的に処理するために使用されます。 ストリームは、データをより小さく管理可能なチャンクで読み書きすることを可能にします。
IronOCRのインポートメソッドは、インポートして読み取るための画像のデータストリームも受け入れます。 これは、単にストリームデータをインポートメソッドの1つに渡すことによって行うことができます。 メソッドは、画像をインポートするために必要なすべての手順を処理します。
IronOCRを始めましょう
今日から無料トライアルでIronOCRをあなたのプロジェクトで使い始めましょう。
ストリームから読む方法
- ストリームから読み取りを行うためのC#ライブラリをダウンロードしてください。
- 画像ストリームデータを取得および準備する
- 画像ストリームを次に渡します OcrImageInput 画像をインポートするためのコンストラクター
- 以下を使用
読み取り
OCRを実行する方法 - クロップ領域を指定して読み取り領域を定義します
ストリーム読み取りの例
まず、OCRを実行するためにIronTesseractクラスをインスタンス化します。 AnyBitmapのFromFile
メソッドを使用して画像ファイルをインポートします。このAnyBitmapオブジェクトは、画像データをストリームに変換することができます。 次に、using
ステートメントを使用して、AnyBitmapオブジェクトのGetStream
メソッドで画像ストリームを渡すことにより、OcrImageInputオブジェクトを作成します。 最後に、OCRを実行するためにRead
メソッドを使用します。
:path=/static-assets/ocr/content-code-examples/how-to/input-streams-read-streams.cs
using IronOcr;
using IronSoftware.Drawing;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Read image file to AnyBitmap
AnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");
// Import image stream
using var imageInput = new OcrImageInput(anyBitmap.GetStream());
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
Imports IronOcr
Imports IronSoftware.Drawing
' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()
' Read image file to AnyBitmap
Private anyBitmap As AnyBitmap = AnyBitmap.FromFile("Potter.tiff")
' Import image stream
Private imageInput = New OcrImageInput(anyBitmap.GetStream())
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)
スキャン領域の指定
大きな画像のパフォーマンスを向上させ、特定の領域から特定の読み取り結果を取得するためには、CropRectangle クラスを利用できます。 OcrImageInputコンストラクタは、2番目のパラメーターとしてCropRectangleオブジェクトを受け入れます。 これにより、画像文書のどの領域を読み取るかを指定することができます。 次のコード例では、章番号とタイトルの領域のみが読み取られるように指定しています。
:path=/static-assets/ocr/content-code-examples/how-to/input-streams-read-specific-region.cs
using IronOcr;
using IronSoftware.Drawing;
using System;
// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();
// Read image file to AnyBitmap
AnyBitmap anyBitmap = AnyBitmap.FromFile("Potter.tiff");
// Specify crop region
Rectangle scanRegion = new Rectangle(800, 200, 900, 400);
// Add image
using var imageInput = new OcrImageInput(anyBitmap.GetStream(), ContentArea: scanRegion);
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);
// Output the result to console
Console.WriteLine(ocrResult.Text);
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()
' Read image file to AnyBitmap
Private anyBitmap As AnyBitmap = AnyBitmap.FromFile("Potter.tiff")
' Specify crop region
Private scanRegion As New Rectangle(800, 200, 900, 400)
' Add image
Private imageInput = New OcrImageInput(anyBitmap.GetStream(), ContentArea:= scanRegion)
' Perform OCR
Private ocrResult As OcrResult = ocrTesseract.Read(imageInput)
' Output the result to console
Console.WriteLine(ocrResult.Text)