IronOCRフィルター使用ガイド
IronOCRは、フィルターという前処理が必要な画像を読み取るために必要なツールを備えています。 画像を加工できるように、幅広いフィルターから選ぶことができる。
IronOCRを始めましょう
今日から無料トライアルでIronOCRをあなたのプロジェクトで使い始めましょう。
OCR画像フィルターのリスト
次のようなイメージフィルターを使用すると、パフォーマンスを向上させることができます:
-
画像の向きを変更するフィルターについて
-
回転 - 画像を時計回りに何度回転させるか指定します。反時計回りの場合は負の数を使用します。
- Deskew(デスキュー) - 画像を回転させます。 これは非常に有用です。なぜなら、Tesseractのスキャンの歪みに対する許容度が5度程度と低いからです。
-
- Scale - Ocr入力ページを比例して拡大縮小する。
-
画像の色を操作するフィルタ
-
二値化 - この画像フィルタは、すべてのピクセルを白か黒にします。 OCRのパフォーマンスをテキストと背景のコントラストが非常に低い場合に改善する可能性があります。
-
ToGrayScale - この画像フィルタはすべてのピクセルをグレースケールの濃淡に変換します。 OCRの精度を向上させる可能性は低いが、速度の向上は期待できる。
- Invert - すべての色を反転させる。 例えば、白が黒になります:黒が白になります。
-
- ReplaceColor - 画像内の色を,ある閾値を持つ別の色に置き換えます.
-
画像のコントラストを向上させるフィルターを試す
-
コントラスト - 自動的にコントラストを上げる。 このフィルターは、低コントラストのスキャンにおいて、OCRの速度と精度を向上させることがよくあります。
- 拡張 - 高度な形態学。 _Dilation_は、画像内のオブジェクトの境界にピクセルを追加します。 「Erode」の反対語
-
- エロード - 高度な形態学。 エロージョンはオブジェクトの境界上のピクセルを削除します。 拡大の反対
-
**画像ノイズを軽減するフィルター
-
シャープ - ぼやけた OCR ドキュメントをシャープにし、アルファチャンネルを白にフラットにします。
-
DeNoise - デジタルノイズを除去する。このフィルターはノイズが予想される場合にのみ使用してください。
-
DeepCleanBackgroundNoise - バックグランドノイズの除去。 このフィルタは、きれいな文書のOCR精度を低下させる危険性があり、CPUコストが非常に高いため、極端な文書背景ノイズがわかっている場合にのみ使用してください。
- EnhanceResolution - 低画質の画像の解像度を上げる。 なぜなら、_OcrInput.MinimumDPI_と_OcrInput.TargetDPI_が自動的に低解像度の入力を捕捉し、解決するからである。
-
フィルターの例と使い方
次の例では、コード内でフィルタを適用する方法を示します。
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-1.cs
using IronOcr;
using System;
var ocr = new IronTesseract();
using var input = new OcrInput();
input.LoadImage("my_image.png");
input.Deskew();
var result = ocr.Read(input);
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
Private ocr = New IronTesseract()
Private input = New OcrInput()
input.LoadImage("my_image.png")
input.Deskew()
Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
デバッグ・フィルター / フィルターは何をしているのか?
プログラム内で画像やバーコードの読み取りに問題がある場合。 プログラム内でフィルター結果の画像を保存する方法があります。 こうすることで、各フィルターが何を行い、どのように画像を操作しているかを正確にデバッグして確認することができます。
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-2.cs
using IronOcr;
using System;
var file = "skewed_image.tiff";
var ocr = new IronTesseract();
using var input = new OcrInput();
var pageindices = new int[] { 1, 2 };
input.LoadImageFrames(file, pageindices);
// Here we apply the filter: Deskew
input.Deskew();
// Save the input with filter(s) applied
input.SaveAsImages("my_deskewed");
// We read, then print the text to the console
var result = ocr.Read(input);
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
Private file = "skewed_image.tiff"
Private ocr = New IronTesseract()
Private input = New OcrInput()
Private pageindices = New Integer() { 1, 2 }
input.LoadImageFrames(file, pageindices)
' Here we apply the filter: Deskew
input.Deskew()
' Save the input with filter(s) applied
input.SaveAsImages("my_deskewed")
' We read, then print the text to the console
Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
フィルター使用例
回転
フィルターの説明
回転... は画像に既知の回転を手動で設定し、最も直線に近くするためのフィルターです。 IronOCR には Deskew' を実行する機能がある。()ただし、この許容範囲はかなり狭く、ほぼ完全にまっすぐな画像に最適です。(15度以内). 入力画像が90度ずれていたり、上下逆になっていたりする場合は、
Rotate()`.
ユースケース・コードの例
これは、逆さまの画像を修正するためにRotateを呼び出した例である:
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-3.cs
using IronOcr;
using System;
var image = "screenshot.png";
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);
// Rotate 180 degrees because image is upside-down
input.Rotate(180);
// Read image into variable: result
var result = ocr.Read(input);
// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
Private image = "screenshot.png"
Private ocr = New IronTesseract()
Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)
' Rotate 180 degrees because image is upside-down
input.Rotate(180)
' Read image into variable: result
Dim result = ocr.Read(input)
' Example print to console
Console.WriteLine(result.Text)
Input.Rotateの前(180)` Input.Rotateの後(180)`
傾き補正
フィルターの説明
ハフ変換を使って、ある許容範囲内で画像をまっすぐにしようとする。 文書が傾いていると誤読の原因になることがあるからだ。
*注意: このメソッドは、フィルターが適用された場合はtrueを、画像の向きを検出できなかったために適用に失敗した場合はfalseを返すブール値を返します。 ページがオリエンテーションのベースとなるコンテンツを持っていない場合、これは失敗する。
ユースケース・コードの例
これは、傾いた画像を補正するためにDeskewを呼び出した例である:
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-4.cs
using IronOcr;
using System;
var image = @"paragraph_skewed.png";
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);
// Apply deskew with 15 degree snap
bool didDeskew = input.Deskew(15);
if (didDeskew)
{
// Read image into variable: result
var result = ocr.Read(input);
Console.WriteLine(result.Text);
}
else
{
Console.WriteLine("Deskew not applied because Image Orientation could not be determined.");
}
Imports IronOcr
Imports System
Private image = "paragraph_skewed.png"
Private ocr = New IronTesseract()
Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)
' Apply deskew with 15 degree snap
Dim didDeskew As Boolean = input.Deskew(15)
If didDeskew Then
' Read image into variable: result
Dim result = ocr.Read(input)
Console.WriteLine(result.Text)
Else
Console.WriteLine("Deskew not applied because Image Orientation could not be determined.")
End If
デスキュー前()` デスキューの後()`
スケール
フィルターの説明
拡大縮小 は便利な画像加工フィルターで、 画像がすでに持っている画素数で画像サイズを変更するのに役立ちます。 これは、画像が数十ピクセル幅しかなく、各バーが1ピクセルであるためにバーコードがスキャンされない場合や、アンチエイリアシングがなくテキストが小さすぎる場合に使用できる。
*注:バーコードのサイズにはスイートスポット(1000px x 1000px)があります。
ユースケース・コードの例
これは、スキャンのためにバーコードのバー間のギャップを拡大するためにScaleを呼び出す例です:
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-5.cs
using IronOcr;
using System;
var image = @"small_barcode.png";
var ocr = new IronTesseract();
// Optional: This example uses a barcode
ocr.Configuration.ReadBarCodes = true;
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);
// Apply scale
input.Scale(400); // 400% is 4 times larger
// Read image into variable: result
var result = ocr.Read(input);
// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
Private image = "small_barcode.png"
Private ocr = New IronTesseract()
' Optional: This example uses a barcode
ocr.Configuration.ReadBarCodes = True
Dim input = New OcrInput()
' Load at least one image
input.LoadImage(image)
' Apply scale
input.Scale(400) ' 400% is 4 times larger
' Read image into variable: result
Dim result = ocr.Read(input)
' Example print to console
Console.WriteLine(result.Text)
スケールの前()` スケール()`
2値化
フィルターの説明
Binarizeフィルタは、画像と背景と思われる色を評価する適応的アルゴリズムによって、画像内のすべてのピクセルを黒か白のいずれかに分類します。 色数の多い画像で、文字が目立つような場合、二値化フィルタはすべての色を除去して背景を真っ白に分離し、文字として認識されるものは読みやすいように真っ黒に着色する。
ユースケース・コードの例
これは、Binarizeを呼び出して色つきテキストを整列させ、背景色とノイズを除去した例である:
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-6.cs
using IronOcr;
using System;
var image = @"no-binarize.jpg";
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);
// Apply Binarize
input.Binarize();
// Read image into variable: result
var result = ocr.Read(input);
// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
Private image = "no-binarize.jpg"
Private ocr = New IronTesseract()
Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)
' Apply Binarize
input.Binarize()
' Read image into variable: result
Dim result = ocr.Read(input)
' Example print to console
Console.WriteLine(result.Text)
2値化する前()` 二値化()`
反転
フィルターの説明
IronOCRは、白地に黒文字の画像を読み取る場合に最適です。 一連のフィルターを適用する場合、読み出しの前にこの結果を達成しようとすることが重要である。 反転... フィルターは画像のすべての色を反転させるシンプルなフィルターです。 白が黒になり、黒が白になり、その間のすべてが反転する。
ユースケース・コードの例
これは、黒地に白を白地に黒にするためにInvertを呼び出した例である:
:path=/static-assets/ocr/content-code-examples/tutorials/c-sharp-ocr-image-filters-7.cs
using IronOcr;
using System;
var image = @"before-invert.png";
var ocr = new IronTesseract();
using var input = new OcrInput();
// Load at least one image
input.LoadImage(image);
// Apply Invert
input.Invert(true);
// Read image into variable: result
var result = ocr.Read(input);
// Example print to console
Console.WriteLine(result.Text);
Imports IronOcr
Imports System
Private image = "before-invert.png"
Private ocr = New IronTesseract()
Private input = New OcrInput()
' Load at least one image
input.LoadImage(image)
' Apply Invert
input.Invert(True)
' Read image into variable: result
Dim result = ocr.Read(input)
' Example print to console
Console.WriteLine(result.Text)
前 アフター