Opencv3.4.0---to save frames in a video as a picture

Source: Internet
Author: User

Now there's a need to collect faces, and there's only one person in each picture. My solution is to use a collection to record a video and upload it to the PC. Use OpenCV on your PC to save each frame in the picture as a JPG image.

Here's the code:

Import time

Import Cv2

if __name__ = = ' __main__ ':
    # Fill in the absolute path of the video
    VidCap = Cv2. Videocapture ('/home/shushi/video/hunting ground. mp4 ')
    success, image = Vidcap.read ()
    start_time = Time.time ()
    Print (start_time)

    While success:
        end_time = Time.time ()
        file_name = str (end_time). Replace ('. ', ')
        # screenshot Every three seconds
        if 3 = = Int ( End_time-start_time):
            start_time = end_time
            # Save  Absolute path to JGP
            cv2.imwrite ('/home/shushi/video/' + file_name + ". jpg", image)  # Save Frame as JPEG file
        success, image = Vidcap.read ()
        if Cv2.waitkey (10) = = 2 7:  # Exit if Escape is hits
            break

Put the video in the same directory as the Python file, and then run the program, and you'll get a JPG image of the video frame:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.