I just want to capture one frame, save it to test.png and then exit the code.
In this program exit() doesn't work, I have to use CTRL+C from the terminal every time.
import cv2
#cv2.namedWindow("window")
cap = cv2.VideoCapture(0)
if cap.isOpened(): # if we are able to capture the first frame.
val, frame = cap.read()
else:
val = False
while val:
#cv2.imshow("window", frame)
cv2.imwrite('test.png',frame)
val, frame = cap.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cap.release
cv2.destroyAllWindows()
exit()
Thanks in advance.