我做了一个小的python程序来从屏幕上捕获图像。它被设计为在Esc或' a'键被按下了。它按照编程捕获图像,但是当我按下Esc或' a'键。我的操作系统是Windows 10,我使用的是Python 3.6.4(Anaconda)。这是代码:
import cv2
import mss
from PIL import Image
#Creates an endless loop for high-speed image acquisition...
while 1:
with mss.mss() as sct:
#Get raw pixels from the screen
sct_img = sct.grab(sct.monitors[1])
#Create the Image
img = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw', 'BGRX')
#Show the Image
cv2.imshow('test', np.array(img))
#Kill-switch: press the 'Esc' or 'a' keys to exit the program
if (cv2.waitKey(33) == 27) or (cv2.waitKey(33) == ord('a')):
cv2.destroyAllWindows()
break
我哪里错了?