PermissionError: [Errno 13] Permission denied Solution

When using OpenCV and Image in the program to repeatedly save and open images, the error "PermissionError: [Errno 13] Permission denied" will often be reported. It is useless to try to unify the image format to opencv or image.

After searching, the reason is probably that the command to open the image has been executed before the new image is saved. Adding time.sleep(1) before opening the image solves the problem perfectly.


By the way, the code for converting image, opencv and numpy to each other is attached.

  • opencv to image
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
  • image to opencv
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)

Note here that RGB2BGR is a conversion between color images. If the image format is not color, an error will be reported. You need to change it to your own HSV or GRAY, etc.

  • image to numpy
img = np.array(img)

 

Guess you like

Origin blog.csdn.net/weixin_49828565/article/details/128015986