如何优化OpenCV+pytesseract的图像预处理以提升OCR识别精度?
求助:优化OpenCV+Python-tesseract的OCR预处理流程
我正在尝试使用OpenCV与Python-tesseract对一张图像执行OCR以转换为文本,但目前tesseract未能正确识别内容,识别结果为:uleswylly Bie7 Srp a7。
我已执行以下预处理步骤:
图像Upscale
# Image scaling def set_image_dpi(img): # Get current dimensions of the image height, width = img.shape[:2] # Define scale factor scale_factor = 6 # Calculate new dimensions new_height = int(height * scale_factor) new_width = int(width * scale_factor) # Resize image return cv2.resize(img, (new_width, new_height))完成图像放大处理。
图像归一化
# Normalization norm_img = np.zeros((img.shape[0], img.shape[1])) img = cv2.normalize(img, norm_img, 0, 255, cv2.NORM_MINMAX)完成图像归一化处理。
去除噪声
# Remove noise def remove_noise(img): return cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 15)完成图像降噪处理。
转为灰度图
# Get grayscale def get_grayscale(img): return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)将图像转为灰度格式。
阈值处理
# Thresholding def thresholding(img): return cv2.threshold(img, 150, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]完成图像二值化阈值处理。
图像颜色反转
# Invert the image def invert(img): return cv2.bitwise_not(img)将图像颜色反转。
输入至pytesseract
# Pass preprocessed image to pytesseract text = pytesseract.image_to_string(img) print("Text found: " + text)pytesseract输出结果仍为:uleswylly Bie7 Srp a7。
希望能改进预处理流程,让pytesseract正确识别图像内容,恳请大家提供帮助!
感谢各位的支持!
内容的提问来源于stack exchange,提问作者Steenert
相关产品推荐
相关产品推荐

