PermissionError: [Errno 13] Permission denied on macOS

147 views Asked by At

I try to run the code below, but it's doesn't work `

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'` Please help me to fix it

I try running chown lhldanh:admin tesseract chmod 755 tesseract and many things but it still doesn't worked

1

There are 1 answers

0
Kilian On

pytesseract.pytesseract.tesseract_cmd should point to an executable if I remember correct, so maybe add /tesseract.exe to the path.