Unable to see and take the picture in second time
Code:
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!")
webcam.release()
cv2.destroyAllWindows()
break
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/2... Please help. Thankyou
you cannot open twice VideoCapture. Is Videocapture already opened?
don't release the webcam ;)
@LBerger saying that you cannot open twice VideoCapture. Is Videocapture already opened. Look at what're you doing in function of
method_webcam_trigger
. Movewebcam = cv2.VideoCapture(0)
out ofmethod_webcam_trigger
, And put it on top ofmethod_webcam_trigger
.By clicking button will not work. Youre doing wrong. I need to see your button click event code.
@berak. Listen to @LBerger. It will not work.
@Supra, apologies, you're right
@berak. No problem. I already done this before.
@LBerger@berak @ Supra Thanks for your comments. But the problem remains there. I tried to take out webcam = cv2.VideoCapture(0) outside the function. But still the same.
If i call the function again the excution will stops on this line cv2.imshow("Capturing", frame)