我正在研究从图像中提取文本。
最初图像是用白色文本着色的,在进一步处理图像时,文本显示为黑色而其他像素显示为白色(有一些噪声),这是一个示例:
现在,当我在上面使用 pytesseract (tesseract) 尝试 OCR 时,我仍然没有收到任何文本。
是否有任何解决方案可以从彩色图像中提取文本?
最佳答案
from PIL import Image
import pytesseract
import argparse
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
# load the image and convert it to grayscale
image = cv2.imread(args["image"])
cv2.imshow("Original", image)
# Apply an "average" blur to the image
blurred = cv2.blur(image, (3,3))
cv2.imshow("Blurred_image", blurred)
img = Image.fromarray(blurred)
text = pytesseract.image_to_string(img, lang='eng')
print (text)
cv2.waitKey(0)
结果我得到 = "Stay: in an Overwoter Bungalow $3»"
使用 Contour 并从中提取不必要的 Blob 怎么样?可能有用
关于python - 从图像中提取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46260970/