You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pytesseract识别异常求助:可视数字1被误识别为4的问题解决咨询

Fixing Tesseract's Misrecognition of "1" as "4"

Hey there, let's work through this annoying OCR misrecognition issue! It's super frustrating when a clear "1" gets read as a "4"—here are some targeted fixes you can test out, starting with the quickest wins:

1. Adjust the Page Segmentation Mode (PSM)

Your current config uses --psm 13, which treats the input as a raw line without any segmentation. Since you're dealing with a small, specific set of characters (a digit + "LV"), switching to a more focused PSM will help Tesseract zero in on the right shapes:

  • Try --psm 8 (treats the entire image as a single word) — this is a good middle ground for your case.
  • If you can crop the image to isolate just the "1" from "LV", --psm 10 (single character mode) will be even more accurate.

Update your config line to this first:

custom_config = "-c tessedit_char_whitelist=0123456789LV --psm 8"

2. Switch Preprocessing from Dilation to Erosion

You mentioned trying dilation, which thickens character edges—and that might be making your thin "1" look more like a "4"! Instead, try erosion to sharpen the vertical line of the "1" and reduce any blurry edges that are throwing Tesseract off:

import cv2
import numpy as np
kernel = np.ones((1,1), np.uint8)
eroded_img = cv2.erode(processed_img, kernel, iterations=1)

You can tweak the kernel size and iteration count if needed—start small to avoid losing the character entirely.

3. Refine Thresholding or Add Edge Detection

Otsu's thresholding works great for many cases, but if your image has uneven lighting or subtle contrast issues, adaptive thresholding might do a better job of making the "1" stand out:

adaptive_thresh = cv2.adaptiveThreshold(gray_img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 11, 2)

Alternatively, run Canny edge detection to highlight the distinct outline of the "1" before feeding it to Tesseract:

edges = cv2.Canny(processed_img, 50, 150)

4. Check Confidence Scores & Manually Correct Low-Confidence Matches

If Tesseract is still unsure, you can retrieve confidence scores for each character and flag or correct low-confidence results. This is helpful if you're processing multiple images:

from pytesseract import Output

results = pytesseract.image_to_data(processed_img, config=custom_config, output_type=Output.DICT)
for idx in range(len(results['text'])):
    conf = int(results['conf'][idx])
    char = results['text'][idx]
    if conf < 70:  # Adjust threshold based on your needs
        print(f"Low confidence ({conf}%): {char} — might be a misrecognized '1'")
        # Add logic here to replace with '1' if the position matches where your digit should be

5. Isolate the Digit from "LV"

If the "1" is positioned right next to "LV", the overlapping or adjacent pixels might be confusing Tesseract. Use OpenCV to crop the image to just the digit region, then run OCR on that cropped area alone with --psm 10—this removes any distractions from the letters.

Start with adjusting the PSM and trying erosion—those are the fastest changes to test, and they often fix character misrecognition issues like this. If those don't work, move on to the other preprocessing tweaks or isolation steps.

内容的提问来源于stack exchange,提问作者WiNic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 10:17:34