python - Python pytesseract 问题在 Mac 中打开“[Errno 13] Permission denied:”
问题描述
我在 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)
谢谢
解决方案
您是否正在使用 pytesseract 的 tesseract 可执行文件的分配?由于我没有在您的代码中看到它,因此我假设您没有。我还将假设您使用 Homebrew 来安装 tesseract OCR。如果您使用 macports 或在其他操作系统上使用,请在此处查看官方安装文档。您的整个脚本至少应包含以下内容:
- 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'))
推荐阅读
- api - IE 11 响应负载大小
- python - @cupy.fuse cupy python 装饰器记录在哪里?
- java - 当 Junit5 ParameterizedTest Attempt 时,Java Exception No Tests Found Matching
- javascript - 为什么在这个例子中 switch-case 严格相等检查似乎失败了?
- javascript - HTML 中的无效字符阻止我的菜单切换?
- c++ - 如果没有子字符串,这是打破 while 循环的好方法吗?
- angular - 表单验证无法正常工作
- c# - 如何获取 LAST_INSERT_ID();
- c - 如何在C中使用星星绘制形状
- javascript - 当有多个值时,如何使我的过滤器作为“和”而不是“或”工作?