使用 OpenCV 时永远弹跳 Python 火箭飞船
Forever Bouncing Python Rocket Ship when using OpenCV
我在 MacOS Sierra 上使用的 Python 版本是 Python 2.7.13,我也在 Python.
中使用 OpenCV 3
while True:
frame = read_stream()
# some manipulation on `frame`
cv2.imshow("Screen", frame)
我在这里尝试显示来自套接字流的帧。第一次运行良好,但不知为何,下次我尝试 运行 时,停靠栏中的 Python 火箭飞船图标一直上下跳动,而 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. (If you put it in a loop to read videos, it will display the video frame-by-frame)
据推测,添加 waitKey(20) 将为您提供不错的 50Hz 流,但您可以 fiddle 使用该值来满足您的需要。
编辑:正如您所说,它第一次运行良好,我在这里可能走错了路。如果是这种情况,我将删除答案,我们将研究图像的定义 window "Screen"...
我在 MacOS Sierra 上使用的 Python 版本是 Python 2.7.13,我也在 Python.
中使用 OpenCV 3while True:
frame = read_stream()
# some manipulation on `frame`
cv2.imshow("Screen", frame)
我在这里尝试显示来自套接字流的帧。第一次运行良好,但不知为何,下次我尝试 运行 时,停靠栏中的 Python 火箭飞船图标一直上下跳动,而 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. (If you put it in a loop to read videos, it will display the video frame-by-frame)
据推测,添加 waitKey(20) 将为您提供不错的 50Hz 流,但您可以 fiddle 使用该值来满足您的需要。
编辑:正如您所说,它第一次运行良好,我在这里可能走错了路。如果是这种情况,我将删除答案,我们将研究图像的定义 window "Screen"...