gpt4 book ai didi

python - PIL : IOError: [Errno 13] Permission denied: [picturename. jpg]

转载 作者:可可西里 更新时间:2023-11-01 10:31:34 26 4
gpt4 key购买 nike

我正在编写一个循环,用于截取屏幕截图并使用与之前图像相同的名称保存图像。问题是经过随机次数的迭代后,程序中止并出现以下错误:

C:\Folder>python test.py
Traceback (most recent call last):
File "test.py", line 30, in <module>
screen_record()
File "test.py", line 19, in screen_record
printscreen.save(img_name)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2004, in save
fp = builtins.open(filename, "w+b")
IOError: [Errno 13] Permission denied: 'screen.jpg'

可能是什么问题?我感谢任何支持

代码:

import numpy as np
from PIL import ImageGrab
import cv2
import time
import os
from matplotlib import pyplot as plt
from pynput.keyboard import Key, Controller

def screen_record():

keyboard = Controller()

img_name = 'screen.jpg'

while(True):

printscreen = ImageGrab.grab(bbox=(0,0,385,697))

printscreen.save(img_name)

img_rgba = cv2.imread(img_name,cv2.IMREAD_UNCHANGED)

cv2.namedWindow('window', cv2.WINDOW_NORMAL)
cv2.imshow('window', img_rgba)

if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break

screen_record()

最佳答案

问题解决了。最终代码:

import numpy as np
from PIL import ImageGrab
import cv2
import time
import os
from matplotlib import pyplot as plt
from pynput.keyboard import Key, Controller

def screen_record():

keyboard = Controller()
cv2.namedWindow('window', cv2.WINDOW_NORMAL)

while(True):

printscreen = np.array(ImageGrab.grab(bbox=(0, 0, 385, 697)))
RGB_img = cv2.cvtColor(printscreen, cv2.COLOR_BGR2RGB)
cv2.imshow('window', RGB_img)

if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break

screen_record()

关于python - PIL : IOError: [Errno 13] Permission denied: [picturename. jpg],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55876155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com