How to set DPI Setting in OCR

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

每英寸點數(DPI)是圖像質量的基本衡量標準,決定了掃描文件或數碼照片的細節等級。 雖然掃描文件是一種快速而高效的數字化物理記錄的方式,但該過程常常會生成低分辨率文件,尤其是在使用默認或“快速掃描”設置時。 這種細節的缺乏使得文本顯得模糊或像素化,給數據提取帶來了重大障礙。

這是 OCR 性能直接受到影響的地方。 OCR 引擎通過分析字符的精確形狀和模式來將其轉換為機器可讀文本。 當圖像的 DPI 低時,像素不足以清晰定義每個字母,導致細節丟失並導致不準確的結果。

然而,IronOCR 專門設計來克服這些常見挑戰。 它已被精細調整以在低至 225 DPI 的分辨率掃描上實現高準確率。

快速入門:設置 TargetDPI 以獲得更清晰的 OCR 結果

在一條簡單的命令中,您可以配置 IronOCR 以提升低分辨率圖像,提高文本清晰度和識別效果,而不需費太大力氣。 開發人員可以立即使用 IronOCR 的簡潔 API 開始。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrInput { TargetDPI = 300 }.LoadImage("low-res.png"));
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小工作流程(5 步)

  1. 下載一個 C# 庫來設置 OCR 的 DPI 設置
  2. 實例化一個新的OcrInput
  3. 設置TargetDPI來滿足您的需求
  4. 加載所需的圖像
  5. 使用Read從圖像中讀取並提取數據

DPI 設置示例

本示例使用分辨率約為 100 DPI 的示例圖像,並添加人為噪音以演示TargetDPI功能的有效性。

圖像中的實際文本是:「測試測試測試模糊文本示例示例示例」。

class="content-img-align-center">
class="center-image-wrapper">Blurry Text Image

代碼示例

在此示例中,我們將TargetDPI設置為 300 以將圖像分辨率提高到 300 DPI。 之後,我們將從上面加載輸入圖像,並使用Text打印出提取的測試,使用Confidence打印出信心等級。

:path=/static-assets/ocr/content-code-examples/how-to/dpi-setting.cs
using IronOcr;
using System;

var ocrTesseract = new IronTesseract();

using var ocrInput = new OcrInput();
// Set the target DPI to 300 for better OCR accuracy
ocrInput.TargetDPI = 300;

ocrInput.LoadImage(@"images\image.png");

// Perform OCR on the image with the specified DPI
var ocrResult = ocrTesseract.Read(ocrInput);
// Display the text extracted from the image
Console.WriteLine(ocrResult.Text);
// Display the confidence level of the OCR result
Console.WriteLine(ocrResult.Confidence);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

輸出

class="content-img-align-center">
class="center-image-wrapper">Text Output

如輸出顯示,IronOCR 達到 85% 的信心得分。 儘管源圖像的噪音顯著且初始 DPI 低,結果卻異常準確,展示了升級功能的強大威力。

IronOCR 包含內建功能,可以通過升級自動增強低分辨率圖像,全部包含在一個庫中。

DPI 設置比較

為了說明差別,這裡顯示處理相同低分辨率圖像且未設置TargetDPI屬性的結果。

找到正確的 DPI 是一種平衡。 高 DPI 更準確但更慢; 低 DPI 更快但不可靠。 如有疑問,讓 Iron Tesseract 的自動預處理決定最佳設置。 您還可以通過將 TargetDPI 屬性設置為 0 來禁用自動升級。

輸出

class="content-img-align-center">
class="center-image-wrapper">Text Output

沒有升級,信心得分降至 79%,提取的文本明顯不準確。 這種比較清楚地顯示了如何設置TargetDPI可以顯著改善低質量圖像的 OCR 結果。

PDF 的 DPI 設置

當處理 PDF 時,IronOCR 會將整個文檔升級到目標 DPI,這不僅僅是其中包含的圖像。

雖然更高的 DPI 通常會帶來更好的 OCR 結果,但最佳設置在不同的 PDF 之間可能會有很大差異。 假設您不確定要使用哪個值。 在這種情況下,最好將 DPI 保持在默認設置狀態,讓 IronOCR 自動確定您的文檔的最佳配置。

警告 TargetDPI 的最大值為 32,766。設置高於此限制的 DPI 會導致異常。 這是因為生成的圖像尺寸會超過 Tesseract 支持的最大尺寸 32,767 x 32,767 像素。 若超過限制,您將收到以下錯誤信息: 'TargetDPI 過高,將導致圖像尺寸過大 ({new_width} x {new_height}) 超過 Tesseract 的限度。 Tesseract 的最大圖像尺寸為 32767 x 32767'

常見問題解答

在OCR領域,DPI是什麼?

DPI 代表每英吋點數,用於衡量影像解析度。在 OCR 中,設定合適的 DPI 可以提高文字辨識的準確率,尤其是在低解析度影像中。

DPI設定如何影響IronOCR的OCR辨識準確率?

在 IronOCR 中設定合適的 DPI 可以顯著提高文字辨識準確率,提供更清晰的影像輸入,減少字元辨識錯誤,尤其是在低解析度影像中。

為了獲得最佳的OCR辨識效果,建議的DPI設定是多少?

為了獲得最佳的 OCR 效果,建議使用 DPI 至少為 300 的影像。但是,IronOCR 提供了影像放大功能,可在較低 DPI 的影像上進行有效的 OCR。

我能否在 IronOCR 中提升低解析度影像的解析度以獲得更好的結果?

是的,IronOCR 提供影像放大功能,可提高低品質影像的分辨率,從而提高 OCR 的準確性。

IronOCR是否支援自動DPI調節?

IronOCR 允許自訂 DPI 設置,從而能夠根據輸入影像品質自動調整以優化 OCR 性能。

如何使用 C# 在 IronOCR 中設定 DPI?

您可以透過在 C# 代碼中指定所需的 DPI 值來設定 IronOCR 的 DPI。文件中提供了程式碼範例來引導您完成此過程。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 5,044,537 | 版本: 2025.11 剛剛發布