import cv2
def method_webcam_trigger() key = cv2. waitKey(1) webcam = cv2.VideoCapture(0) while True: try: check, frame = webcam.read() cv2.imshow("Capturing", frame) key = cv2.waitKey(1) if key == ord('s'): cv2.imwrite(filename='saved_img.jpg', img=frame) webcam.release() cv2.waitKey(1650) cv2.destroyAllWindows() print("Image saved!") elif key == ord('q'): webcam.release() cv2.destroyAllWindows() break
Abouve the code which am using. I wrote the code to take the picture in a function and the function will activate in a button click. If i click on a button then the button will call this particular function(method_webcam_trigger) and save the picture. The problem is that if i click on that button again then it wont work. if i click the button on second time then the execution will stop on below line. cv2.imshow("Capturing", frame)
Can anybody help to solve this? Below is another link which i saw asking the same question, but did't find the answer. https://stackoverflow.com/questions/27461227/doesnt-work-videocapture-in-opencv-second-time Please help. Thankyou