我使用了EAST (高效准确的场景文本检测器)的以下PyTorch 实现来识别和绘制许多图像中文本周围的边界框,效果非常好!
pytesseract
但是,为了从这些图像中提取文本并将它们转换为字符串,我正在尝试使用 OCR 的下一步——失败得很厉害。--oem
使用和的所有可能配置--psm
,我无法检测到pytesseract
看起来非常清晰的文本,例如:
已识别的文本位于图像下方。即使我应用了对比度增强,并尝试了扩张和腐蚀,我也无法让 tesseract 识别文本。这只是许多图像中文本更大更清晰的示例之一。关于转换、配置或其他库的任何建议都会有所帮助!
更新:在尝试高斯模糊 + Otso 阈值处理后,我能够在白色背景上获得黑色文本(显然这是 pytesseract 的理想选择),并且还添加了西班牙语,但它仍然无法阅读非常纯文本 - 例如:
读起来是胡言乱语。
处理后的文本图像是和
我正在使用的代码:
img_path = './images/fesa.jpg'
img = Image.open(img_path)
boxes = detect(img, model, device)
origbw = cv2.imread(img_path, 0)
for box in boxes:
box = box[:-1]
poly = [(box[0], box[1]),(box[2], box[3]),(box[4], box[5]),(box[6], box[7])]
x = []
y = []
for coord in poly:
x.append(coord[0])
y.append(coord[1])
startX = int(min(x))
startY = int(min(y))
endX = int(max(x))
endY = int(max(y))
#use pre-defined bounding boxes produced by EAST to crop the original image
cropped_image = origbw[startY:endY, startX:endX]
#contrast enhancement
clahe = cv2.createCLAHE(clipLimit=4.0, tileGridSize=(8,8))
res = clahe.apply(cropped_image)
text = pytesseract.image_to_string(res, config = "-psm 12")
plt.imshow(res)
plt.show()
print(text)
qq_笑_17
相关分类