删除OCR python图像的中断部分

2024-05-23 14:27:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我是图像处理新手,希望对带有数字的图像进行OCR,但其中一些图像很难识别,例如: img

我尝试过二值化,但效果还不够好,那么有没有其他方法可以去除圆和中心星呢?谢谢 code

输出:Shee ar

预期输出:891972


Tags: 方法图像imgcode数字中心图像处理ocr
1条回答
网友
1楼 · 发布于 2024-05-23 14:27:09

尝试使用谷歌的tesseract OCR引擎,它将对OCR非常有帮助

尝试此方法删除背景

import cv2
import numpy as np
from matplotlib import pyplot as plt
image_bgr = cv2.imread('images/plane_256x256.jpg')
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
rectangle = (0, 56, 256, 150)
 Create initial mask
mask = np.zeros(image_rgb.shape[:2], np.uint8)

# Create temporary arrays used by grabCut
bgdModel = np.zeros((1, 65), np.float64)
fgdModel = np.zeros((1, 65), np.float64)

# Run grabCut
cv2.grabCut(image_rgb, # Our image
            mask, # The Mask
            rectangle, # Our rectangle
        bgdModel, # Temporary array for background
        fgdModel, # Temporary array for background
        5, # Number of iterations
        cv2.GC_INIT_WITH_RECT) # Initiative using our rectangle

# Create mask where sure and likely backgrounds set to 0, otherwise 1
mask_2 = np.where((mask==2) | (mask==0), 0, 1).astype('uint8')


# Multiply image with new mask to subtract background
image_rgb_nobg = image_rgb * mask_2[:, :, np.newaxis]

plt.imshow(image_rgb_nobg), plt.axis("off")
plt.show()

相关问题 更多 >