pythonopencvimutils

How can i save a frame in a live video using opencv in python?


How to grab a fram from a live video using opencv?

I created a face recognition program using opencv and i want to capture an image when the confidence > 0.8 this is the code for initializing the liveVideo

 LiveVideo = VideoStream(src=0).start()
    while True:
        frame = LiveVideo.read()
    frame = imutils.resize(frame, width=1000)
     ....

if anyone knows how to grab a frame from the live video and save it please tell me how to do so


Solution

  • You can use imwrite function from your opencv to extract the current frame.

    You can also add time and convert it to string for naming purpose for the output file.

    import time as t
    LiveVideo = VideoStream(src=0).start()
            while True:
                frame = LiveVideo.read()
                timestr = t.strftime("%Y%m%d-%H%M%S")
                cv2.imwrite("frame%s.jpg" % timestr, frame )