gpt4 book ai didi

python - 从屏幕流式传输帧,生成视频

转载 作者:行者123 更新时间:2023-12-01 06:24:39 25 4
gpt4 key购买 nike

如果我想刷新图像,我必须不断关闭窗 Eloquent 能刷新它。不关窗可以吗?这是代码:

import numpy
import cv2
from PIL import ImageGrab
while True:

img = ImageGrab.grab(bbox=(765,155,1135,195))
img_np = numpy.array(img)
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
cv2.imshow("frame",frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

最佳答案

cv2.waitKey(0) 等待不超时,将其替换为 cv2.waitKey(time_in_msec)

刷新频率约为10Hz的示例:

import numpy
import cv2
from PIL import ImageGrab

while True:
img = ImageGrab.grab(bbox=(765,155,1135,195))
img_np = numpy.array(img)
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
cv2.imshow("frame",frame)
cv2.waitKey(100)

cv2.destroyAllWindows()
<小时/>

参见waitKey注释:

imshow
Displays an image in the specified window.

Note This function should be followed by waitKey function which displays the image for specified milliseconds.
Otherwise, it won’t display the image.
For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display).
waitKey(25) will display a frame for 25 ms, after which display will be automatically closed.

关于python - 从屏幕流式传输帧,生成视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60223017/

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