【发布时间】:2018-04-15 10:34:24
【问题描述】:
我制作了一个实时分析屏幕截图的神经网络(不幸的是,它变得越来越复杂,并且变得相当 CPU 密集型)。
我希望在按下字母“a”时暂停它,并在再次按下字母“a”时取消暂停。暂停它的最有效方法是什么(不完全打破循环)?
它使用 Python OpenCV 库,但我不使用 cv2.imshow,因此我不能使用 cv2.Waitkey。我在 Windows 10 上运行它。您能否提供示例代码来回答您的问题?代码如下:
import cv2
import mss
from PIL import Image
import numpy as np
#Creates an endless loop for high-speed image acquisition...
while (True):
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')
#The rest of the neural network goes here...
#PAUSE statement...
【问题讨论】: