PermissionError: [Errno 13] macOS上的权限被拒绝



我试着运行下面的代码,但它不起作用'

import cv2
from PIL import Image
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tesseract'
img = cv2.imread(r'/Users/lhldanh/CompSci/Python/Coursera/TextDetection/sample.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh1 = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU | cv2.THRESH_BINARY_INV)

rect_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (18, 18))

dilation = cv2.dilate(thresh1, rect_kernel, iterations = 1)

contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

im2 = img.copy()
file = open("recognized.txt", "w+")
file.write("")
file.close()
for cnt in contours:
x, y, w, h = cv2.boundingRect(cnt)
rect = cv2.rectangle(im2, (x, y), (x + w, y + w), (0, 255, 0), 2)
cropped = im2[y:y + h, x:x + w]
file = open('recognized.txt', 'a')
text = pytesseract.image_to_string(cropped)
#text = 'asd'
file.write(text)
file.write('n')
file.close()

The cmd says that:PermissionError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/tesseract' '请帮我修一下

我试着跑步chown lhldanh:admin tesseract chmod 755 tesseract还有很多东西,但是还是不行

pytesseract.pytesseract。如果我没记错的话,tesseract_cmd应该指向一个可执行文件,所以也许可以在路径中添加/tesseract.exe。

相关内容

  • 没有找到相关文章

最新更新