IronOCRでCAPTCHAを処理する

This article was translated from English: Does it need improvement?
Translated
View the article in English

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
$vbLabelText   $csharpLabel

説明:

  • IronOcr : このライブラリは画像からテキストを読み取るために使用されます。
  • OcrInput : このクラスは、OCR 処理用の画像入力を表します。
  • DeNoise : この方法は、画像の背景ノイズを低減するために使用されます。
  • DeepCleanBackgroundNoise : 基本的なDeNoiseでは不十分な場合に、より積極的なノイズ低減を行うためにこの方法が使用されます。
  • ToGrayScale : 画像をグレースケールに変換して認識精度を向上させます。
  • Read : このメソッドは、前処理された画像からテキストを抽出するために呼び出されます。
カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 5,167,857 | Version: 2025.11 リリース