Python 在 Mac 中打开 '[Errno 13] 权限被拒绝:' 的 pytesseract 问题
Python pytesseract problem to open '[Errno 13] Permission denied:' in Mac
我在 python 中遇到 pytesseract 问题。当我在代码中调用文件时,它说权限被拒绝。我正在 Mac 工作,所以我不知道该怎么做,但我希望你能帮助我。
#from every single image-based cell/box the strings are extracted via pytesseract and stored in a list
outer=[]
for i in range(len(finalboxes)):
for j in range(len(finalboxes[i])):
inner=''
if(len(finalboxes[i][j])==0):
outer.append(' ')
else:
for k in range(len(finalboxes[i][j])):
y,x,w,h = finalboxes[i][j][k][0],finalboxes[i][j][k][1], finalboxes[i][j][k][2],finalboxes[i][j][k][3]
finalimg = bitnot[x:x+h, y:y+w]
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 1))
border = cv2.copyMakeBorder(finalimg,2,2,2,2, cv2.BORDER_CONSTANT,value=[255,255])
resizing = cv2.resize(border, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
dilation = cv2.dilate(resizing, kernel,iterations=1)
erosion = cv2.erode(dilation, kernel,iterations=1)
out = pytesseract.image_to_string(erosion) # This line is the one that gives the error
if(len(out)==0):
out = pytesseract.image_to_string(erosion, config='--psm 3')
inner = inner +" "+ out
outer.append(inner)
谢谢
您是否正在使用 tesseract 可执行文件的 pytesseract 赋值?
由于我没有在您的代码中看到它,因此我假设您没有。我还将假设您使用 Homebrew 来安装 tesseract OCR。如果您使用 macports 或正在另一个 os 上使用,请查看官方 install documentation here。
您的整个脚本至少应包含以下内容:
- pytesseract 模块的导入。
import pytesseract
- 对 tesseract 可执行文件的 pytesseract 模块实例的赋值。这必须引用路径和 tesseract 可执行二进制文件才能充分发挥作用:
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/[version]/bin/tesseract'
- 您现在可以调用 pytesseract 方法的任何方法,例如:
print(pytesseract.image_to_string(r'/Path/to/image/you/want/to/process/Picture1.png'))
我在 python 中遇到 pytesseract 问题。当我在代码中调用文件时,它说权限被拒绝。我正在 Mac 工作,所以我不知道该怎么做,但我希望你能帮助我。
#from every single image-based cell/box the strings are extracted via pytesseract and stored in a list
outer=[]
for i in range(len(finalboxes)):
for j in range(len(finalboxes[i])):
inner=''
if(len(finalboxes[i][j])==0):
outer.append(' ')
else:
for k in range(len(finalboxes[i][j])):
y,x,w,h = finalboxes[i][j][k][0],finalboxes[i][j][k][1], finalboxes[i][j][k][2],finalboxes[i][j][k][3]
finalimg = bitnot[x:x+h, y:y+w]
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 1))
border = cv2.copyMakeBorder(finalimg,2,2,2,2, cv2.BORDER_CONSTANT,value=[255,255])
resizing = cv2.resize(border, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
dilation = cv2.dilate(resizing, kernel,iterations=1)
erosion = cv2.erode(dilation, kernel,iterations=1)
out = pytesseract.image_to_string(erosion) # This line is the one that gives the error
if(len(out)==0):
out = pytesseract.image_to_string(erosion, config='--psm 3')
inner = inner +" "+ out
outer.append(inner)
谢谢
您是否正在使用 tesseract 可执行文件的 pytesseract 赋值? 由于我没有在您的代码中看到它,因此我假设您没有。我还将假设您使用 Homebrew 来安装 tesseract OCR。如果您使用 macports 或正在另一个 os 上使用,请查看官方 install documentation here。 您的整个脚本至少应包含以下内容:
- pytesseract 模块的导入。
import pytesseract
- 对 tesseract 可执行文件的 pytesseract 模块实例的赋值。这必须引用路径和 tesseract 可执行二进制文件才能充分发挥作用:
pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/[version]/bin/tesseract'
- 您现在可以调用 pytesseract 方法的任何方法,例如:
print(pytesseract.image_to_string(r'/Path/to/image/you/want/to/process/Picture1.png'))