使用IronOCR處理CAPTCHA
This article was translated from English: Does it need improvement?
Translated
View the article in English
IronOCR會識別captcha程式碼嗎?
這是可能的,但不能保證。
大多數CAPTCHA生成器故意設計來愚弄OCR軟體,有些甚至使用類似Tesseract的"不能被OCR軟體讀取"作為單元測試。
Captcha程式碼本質上對OCR引擎來說非常難以識別。 解析度非常低,每個字元的角度和間隙都與其他字元不同,並且包括可變的背景噪音。
去除背景噪音的灰階圖像比彩色圖像更成功,但仍然具有挑戰性:
- OcrInput.DeNoise() or OcrInput.DeepCleanBackgroundNoise() Filter
- OcrInput.ToGrayScale() Filter
以下是嘗試去除噪音並將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:此方法用於減少圖像中的背景噪音。DeNoise不夠,此方法用於更積極地降噪。ToGrayScale:這將圖像轉換為灰階以提高識別準確性。Read:此方法用於從預處理的圖像中提取文字。
準備開始了嗎?
Nuget 下載 6,151,372 | 版本: 2026.7 剛剛發布

