0
我构建了一个调用IP摄像头的python模块,但是当我尝试关闭由cv2生成的窗口时,窗口会一次又一次地在无限循环中生成。你能帮助我吗?如何关闭cv2窗口?
这是脚本
import cv2
source = "rtsp://admin:[email protected]//Streaming/Channels/2"
cap = cv2.VideoCapture(source)
ok_flag = True
while ok_flag:
(ok_flag, img) = cap.read()
if not ok_flag:
break
cv2.imshow("CallingCamera View", img)
if cv2.waitKey(1) == 27:
ok_flag = False
break
cv2.destroyAllWindows()
但是,窗口仍然环,当我关闭相机的窗口时出现另一个窗口,所以我应该杀死我的程序,我想按ESC或关闭窗口 –
@PatricioPalacios我不知道我跟着你。使用我发布的代码按下转义将关闭窗口并打破while循环。你是否想要使用鼠标关闭窗口并退出循环? – Grr