2024-05-23 14:27:09 发布
网友
我是图像处理新手,希望对带有数字的图像进行OCR,但其中一些图像很难识别,例如: img
我尝试过二值化,但效果还不够好,那么有没有其他方法可以去除圆和中心星呢?谢谢 code
输出:Shee ar
Shee ar
预期输出:891972
891972
尝试使用谷歌的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()
尝试使用谷歌的tesseract OCR引擎,它将对OCR非常有帮助
尝试此方法删除背景
相关问题 更多 >
编程相关推荐