i have a simple webcam opening using cv2 module:
cap=cv2.VideoCapture(0)
while True:
ret, img = cap.read()
cv2.imshow('webcam',img)
k=cv2.waitKey(10)
if k == 27:
break
cap.release()
cv2.destroyWindows()
this program runs for ever, although i try to close it, the only way is closing vsCode
k == 27, that means Esc is the way to break out from OpenCV's loop. Go to the window displaying the webcam feed and press the Escape Key.[X]. You have to use keyESCto stop loop and then it will close window too. I some question I saw some function to check if window is visible to stop loop when you use button[X]but this not popular so I don't remember code.Ctrl+Cin terminal/console to stop code? Normally it works.VS Codeshould have also button to stop executing code - so it shouldn't need to close allVS Code