How can I close a cv2 window?
<p>I build a python module that calls an IP Camera, but when I try to close the window generated by cv2 the window is generated again and again in an infinite loop. Can you help me with this?</p>

<p>This is the script</p>

<pre><code>import cv2

source = "rtsp://admin:admin2016@192.168.1.2//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()
</code></pre>