When I use the following program to open the camera and read the program, the video stream cannot be saved, and the object saved is a picture. May I ask what the problem is, thank you
I think you’re creating your video writer at each iteration of the loop.
Get the constructor out and just use vid_writer.write(img0).
Please let me know if it fixed it!
Did you get any error messages?
I managed to run your code with a few modifications.
I think what was happening is that you could not end the loop properly with the while True:, so you should either use a frame counter instead of looping forever, or use a key to finish the capture like this.
Either:
a. loop with a counter : while frame_counter < desired_frames :
b. loop with while True:, but at the end of the loop (inside the loop), listen to a key from the cv2 window to quit cleanly (q in this example).
if k == ord('q'):
break
Then you will arrive at vid_writer.release() properly and you should have a video.
If it still doesn’t work, please include error messages.