OCR領域検出のための矩形座標
いくつかのIronOCRメソッドはRectangleを受け入れ、画像の一部だけにOCRを実行することができます。 必要な4つの値、heightはMicrosoft Paintから直接読み取ることができます。
コンストラクタは以下のようになります:
Rectangle(int x, int y, int width, int height, MeasurementUnits units = MeasurementUnits.Pixels)
Rectangle(int x, int y, int width, int height, MeasurementUnits units = MeasurementUnits.Pixels)
Rectangle(x As Integer, y As Integer, width As Integer, height As Integer, Optional units As MeasurementUnits = MeasurementUnits.Pixels)
各パラメータは1つの測定値に対応します:
x: 画像の左端から領域の開始までの距離。y: 画像の上端から領域の開始までの距離。width: 読み取りたい領域の幅。height: 読み取りたい領域の高さ。MeasurementUnits.Pixels: IronOCRにその値がピクセル単位であることを示します。
座標は画像の左上隅から始まります: yは下に成長します。

開始前に、Microsoft Paint(またはカーソル位置と選択サイズをピクセル単位で表示するエディタ)、読み取りたい画像、プロジェクトに追加されたIronOCRが必要です。
解決策
1. XおよびYの開始点を読む
画像をMicrosoft Paintで開き、読み取りたい領域の左上隅にカーソルを移動します。 カーソルの位置はウィンドウの左下に表示されます。 2403, 1653pxの読み取りはその領域のスタートを示しています。

X = 2403
Y = 1653
2. 幅と高さを読む
選択ツールに切り替え、ターゲットのテキストをボックスで囲みます。 Paintは選択サイズを左下に表示します。 1031 × 214pxの読み取りは、領域の寸法です。

Width = 1031
Height = 214
3. 矩形を構築
4つの値を手に入れたら、Rectangleを構築します。 上記のTesting123領域の場合:
var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
Dim rectangle = New Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels)
4. IronOCRに渡す
OCRを実行する前に入力をその領域にトリミングするために、長方形をLoadImageに渡します。
var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
ocrInput.LoadImage(frame, rectangle);
var rectangle = new Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels);
ocrInput.LoadImage(frame, rectangle);
Dim rectangle = New Rectangle(2403, 1653, 1031, 214, MeasurementUnits.Pixels)
ocrInput.LoadImage(frame, rectangle)
デバッグのヒント
- ステータスバーの
1031 × 214px値は選択の幅と高さであり、座標ではありません。 2403, 1653pxカーソルの読み取りはXとYの開始点、つまり領域の左上を意味します。- Paintはピクセルでレポートするので、
MeasurementUnits.Pixelsを渡して一致させます。 目で値を読むと数ピクセルずれます。 クロップがテキストの一部をクリップする場合、yを低くしてください。

