IronOCRでCAPTCHAを処理する
Curtis Chau
更新日: 2026年8月2日
IronOCR はキャプチャコードを読み取ることができますか?
これは可能ですが、保証されるものではありません。
ほとんどの CAPTCHA ジェネレーターは、OCR ソフトウェアを騙すように意図的に設計されており、Tesseract などの一部のジェネレーターでは、「OCR ソフトウェアによる読み取りの失敗」をユニット テストとして使用しています。
定義上、キャプチャ コードは OCR エンジンにとって読み取るのが非常に困難です。 解像度は非常に低く、各文字は他の文字とは異なる角度と間隔で特別に配置されており、さまざまな背景ノイズが含まれています。
背景ノイズを除去したグレースケール画像はカラー画像よりも成功率が高いですが、それでも課題となることがあります。
- OcrInput.DeNoise() または OcrInput.Despeckle() フィルター
- OcrInput.ToGrayScale() フィルター
以下は、ノイズを除去して 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 and load the CAPTCHA image
var Input = new OcrInput();
Input.LoadImage("captcha-image.jpg");
// Apply noise reduction to improve OCR accuracy
// This removes background noise while preserving text
Input.DeNoise();
// Optionally apply despeckle for more aggressive noise removal
Input.Despeckle();
// 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
Class CaptchaReader
Shared Sub Main(args As String())
' Initialize the IronOCR engine
Dim Ocr = New IronTesseract()
' Create an OCR input object and load the CAPTCHA image
Dim Input = New OcrInput()
Input.LoadImage("captcha-image.jpg")
' Apply noise reduction to improve OCR accuracy
' This removes background noise while preserving text
Input.DeNoise()
' Optionally apply despeckle for more aggressive noise removal
Input.Despeckle()
' 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 ClassImports IronOcr
Class CaptchaReader
Shared Sub Main(args As String())
' Initialize the IronOCR engine
Dim Ocr = New IronTesseract()
' Create an OCR input object and load the CAPTCHA image
Dim Input = New OcrInput()
Input.LoadImage("captcha-image.jpg")
' Apply noise reduction to improve OCR accuracy
' This removes background noise while preserving text
Input.DeNoise()
' Optionally apply despeckle for more aggressive noise removal
Input.Despeckle()
' 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: このメソッドは画像の背景ノイズを低減するために使用されます。Despeckle: このメソッドは、基本的なDeNoiseが十分でない場合に、より積極的なノイズ低減を行うために使用されます。ToGrayScale: これは画像をグレースケールに変換して認識精度を向上させます。Read: このメソッドは、前処理済みの画像からテキストを抽出するために呼び出されます。
テクニカルライター
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。