IronOCRでCAPTCHAを処理する
IronOCR はキャプチャコードを読み取ることができますか?
これは可能ですが、保証されるものではありません。
ほとんどの CAPTCHA ジェネレーターは、OCR ソフトウェアを騙すように意図的に設計されており、Tesseract などの一部のジェネレーターでは、"OCR ソフトウェアによる読み取りの失敗"をユニット テストとして使用しています。
定義上、キャプチャ コードは OCR エンジンにとって読み取るのが非常に困難です。 解像度は非常に低く、各文字は他の文字とは異なる角度と間隔で特別に配置されており、さまざまな背景ノイズが含まれています。
背景ノイズを除去したグレースケール画像はカラー画像よりも成功率が高いですが、それでも課題となることがあります。
以下は、ノイズを除去して CAPTCHA 画像をグレースケールに変換し、OCR の結果を改善しようとするサンプル C# コードです。
using IronOcr;
class CaptchaReader
{
static void Main(string[] args)
{
// Initialize the IronOCR engine
var Ocr = new IronTesseract();
// Create an OCR input object
var Input = new OcrInput("captcha-image.jpg");
// Apply noise reduction to improve OCR accuracy
// This removes background noise while preserving text
Input.DeNoise();
// Optionally apply a deep clean for more aggressive noise removal
Input.DeepCleanBackgroundNoise();
// Convert the image to grayscale
// OCR works better on grayscale images compared to colored ones
Input.ToGrayScale();
// Perform OCR to extract text from the image
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
}using IronOcr;
class CaptchaReader
{
static void Main(string[] args)
{
// Initialize the IronOCR engine
var Ocr = new IronTesseract();
// Create an OCR input object
var Input = new OcrInput("captcha-image.jpg");
// Apply noise reduction to improve OCR accuracy
// This removes background noise while preserving text
Input.DeNoise();
// Optionally apply a deep clean for more aggressive noise removal
Input.DeepCleanBackgroundNoise();
// Convert the image to grayscale
// OCR works better on grayscale images compared to colored ones
Input.ToGrayScale();
// Perform OCR to extract text from the image
var Result = Ocr.Read(Input);
// Output the recognized text to the console
Console.WriteLine(Result.Text);
}
}Imports IronOcr
Friend Class CaptchaReader
Shared Sub Main(ByVal args() As String)
' Initialize the IronOCR engine
Dim Ocr = New IronTesseract()
' Create an OCR input object
Dim Input = New OcrInput("captcha-image.jpg")
' Apply noise reduction to improve OCR accuracy
' This removes background noise while preserving text
Input.DeNoise()
' Optionally apply a deep clean for more aggressive noise removal
Input.DeepCleanBackgroundNoise()
' Convert the image to grayscale
' OCR works better on grayscale images compared to colored ones
Input.ToGrayScale()
' Perform OCR to extract text from the image
Dim Result = Ocr.Read(Input)
' Output the recognized text to the console
Console.WriteLine(Result.Text)
End Sub
End Class説明:
IronOcr: このライブラリは画像からテキストを読み取るために使用されます。OcrInput: このクラスは、OCR 処理用の画像入力を表します。DeNoise: この方法は、画像の背景ノイズを低減するために使用されます。DeepCleanBackgroundNoise: 基本的なDeNoiseでは不十分な場合に、より積極的なノイズ低減を行うためにこの方法が使用されます。ToGrayScale: 画像をグレースケールに変換して認識精度を向上させます。Read: このメソッドは、前処理された画像からテキストを抽出するために呼び出されます。






