我如何 运行 从 link 到图像的 OCR?
How do I run OCR from a link to an image?
我想 运行 对某些图像 link 进行 OCR,例如这张:https://i.redd.it/hsop5oo6rb351.jpg
。但是,当试图通过此代码传递此 link 时:
def ocrImage(image):
img = cv2.imread(image)
text = pytesseract.image_to_string(img)
return text;
控制台returns错误TypeError: Unsupported Image Object
。我意识到这是指我试图将 link 传递给 cv2.imread()
,其参数用于路径;但是,我找不到将图像转换为路径的方法。任何帮助将不胜感激。
您可以先保存图片,然后通过函数获取OCR输出。
import urllib.request
def ocrImage(URL):
urllib.request.urlretrieve(URL, "temp.jpg")
img = cv2.imread("temp.jpg")
text = pytesseract.image_to_string(img)
return text;
我想 运行 对某些图像 link 进行 OCR,例如这张:https://i.redd.it/hsop5oo6rb351.jpg
。但是,当试图通过此代码传递此 link 时:
def ocrImage(image):
img = cv2.imread(image)
text = pytesseract.image_to_string(img)
return text;
控制台returns错误TypeError: Unsupported Image Object
。我意识到这是指我试图将 link 传递给 cv2.imread()
,其参数用于路径;但是,我找不到将图像转换为路径的方法。任何帮助将不胜感激。
您可以先保存图片,然后通过函数获取OCR输出。
import urllib.request
def ocrImage(URL):
urllib.request.urlretrieve(URL, "temp.jpg")
img = cv2.imread("temp.jpg")
text = pytesseract.image_to_string(img)
return text;