简体   繁体   English

在 Python3.7 解释器中使用 opencv 和 pytesseract 从图像中提取文本的问题

[英]Problem in Using opencv and pytesseract for extracting text out of images in Python3.7 interpreter

I intend to use opencv and pytesseract to extract text of out images.我打算使用 opencv 和 pytesseract 来提取图像中的文本。 On executing the following code in a Python 3.7 Interpreter, I am receiving a error I'm not sure I understand.在 Python 3.7 解释器中执行以下代码时,我收到一个错误,我不确定我是否理解。

import cv2
import pytesseract
#tesseract.exe location provided 
pytesseract.tesseract_cmd=r'C:\\Users\\shree\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'
#image location provided
img=cv2.imread('C:\\Users\\shree\\Desktop\\hey.jpeg')
text=pytesseract.image_to_string(img)
print(text)

error shown显示错误

PS: PS:

  1. I have installed opencv and pytessearct in "C:\Users\shree\AppData\Local\Programs\Python\Python37-32\Scripts"我已经在“C:\Users\shree\AppData\Local\Programs\Python\Python37-32\Scripts”中安装了 opencv 和 pytessearct
  2. Python 3.7 Interpreter is installed in "C:\Users\shree\AppData\Local\Programs\Python\Python37-32" Python 3.7解释器安装在“C:\Users\shree\AppData\Local\Programs\Python\Python37-32”
  3. Please excuse if this is an obvious/dumb question.如果这是一个明显/愚蠢的问题,请原谅。 Actually, I'm just starting out.实际上,我才刚刚开始。 I read about this at https://towardsdatascience.com/read-text-from-image-with-one-line-of-python-code-c22ede074cac我在https://towardsdatascience.com/read-text-from-image-with-one-line-of-python-code-c22ede074cac读到了这个

A Detailed answer and an alternate way(if required) would be highly appreciated.非常感谢您提供详细的答案和替代方式(如果需要)。 Thanks!谢谢!

Replace the line,换线,

pytesseract.tesseract_cmd=r'C:\\Users\\shree\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'

with,和,

pytesseract.pytesseract.tesseract_cmd = r'C:\\Users\\shree\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'

This should fix the issue if tesseract is installed properly.如果 tesseract 安装正确,这应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM