In this article, the example for you to share the python video by frame to intercept the picture of the specific code of the tool, for your reference, the specific content is as follows
DESCRIPTION: Take a video stream and capture a large number of images by frames.
Purpose: dataset production for AI, getting a large number of images and labeling them afterwards
change
--Number of frames in the interval /output - the path to the input video, the path to the captured image (just put the path into the ' ' at the end), preceded by r to indicate the absolute path eg.
args = parser.parse_args(['--input',r'F:\data_video\IMG_4395.MOV','--output',r'F:data_rgb_pic\7video'])
Straight to the code.
import cv2 import argparse import os def parse_args(): """ Parse input arguments """ parser = (description='Process pic') parser.add_argument('--input', help='video to process', dest='input', default=None, type=str) parser.add_argument('--output', help='pic to store', dest='output', default=None, type=str) #default is the number of frames between which to capture an image parser.add_argument('--skip_frame', dest='skip_frame', help='skip number of video', default=100, type=int) #input is the path to the input video, output is the path to the output image. args = parser.parse_args(['--input','','--output','']) return args def process_video(i_video, o_video, num): cap = (i_video) num_frame = (cv2.CAP_PROP_FRAME_COUNT) expand_name = '.jpg' if not (): print("Please check the path.") cnt = 0 count = 0 while 1: ret, frame = () cnt += 1 # how # many # frame # to # cut if cnt % num == 0: count += 1 ((o_video, str(count) + expand_name), frame) if not ret: break if __name__ == '__main__': args = parse_args() if not (): () print('Called with args:') print(args) process_video(, , args.skip_frame)
This is the entire content of this article.