【问题标题】:Python pytesseract problem to open '[Errno 13] Permission denied:' in Mac在 Mac 中打开“[Errno 13] Permission denied:”的 Python pytesseract 问题
【发布时间】:2020-10-22 02:24:22
【问题描述】:

我在 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)

谢谢

【问题讨论】:

    标签: python macos permissions


    【解决方案1】:

    您是否正在使用 tesseract 的可执行文件的 pytesseract 赋值? 由于我没有在您的代码中看到它,因此我假设您没有。我还将假设您使用 Homebrew 来安装 tesseract OCR。如果您使用 macports 或在其他操作系统上使用,请查看官方 install documentation here。 您的整个脚本至少应包含以下内容:

    1. pytesseract 模块的导入。

    import pytesseract

    1. 对 tesseract 可执行文件的 pytesseract 模块实例的赋值。这必须引用路径和 tesseract 可执行二进制文件才能充分发挥作用:

    pytesseract.pytesseract.tesseract_cmd = r'/usr/local/Cellar/tesseract/[version]/bin/tesseract'

    1. 您现在可以调用 pytesseract 方法中的任何方法,例如:

    print(pytesseract.image_to_string(r'/Path/to/image/you/want/to/process/Picture1.png'))

    【讨论】:

    猜你喜欢
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 2019-11-27
    • 2020-12-27
    • 2017-07-15
    • 2020-12-07
    • 2020-12-12
    相关资源
    最近更新 更多