LoginSignup
0
0

More than 5 years have passed since last update.

OpenCV Video Frame Extraction

Last updated at Posted at 2018-07-09

OpenCVでフレームスキップを指定したビデオフレームの抽出 (Python)


import cv2
vidcap = cv2.VideoCapture('<VIDEO FILE NAME>')
success,image = vidcap.read()
fps = vidcap.get(cv2.CAP_PROP_FPS)
totalframes = vidcap.get(cv2.CAP_PROP_FRAME_COUNT)

frame2skip = <FRAME_SKIP_RATE>  # num of frames to skip when extracting
outputframe = int(totalframes / frame2skip)

print('Video FPS rate is {}'.format(fps))
print('You will get {} frames in total'.format(outputframe))

while success:
    frameId = int(round(vidcap.get(1)))
    success, image = vidcap.read()

    if frameId % frame2skip == 0:
        cv2.imwrite('frame_%d.jpg' % frameId, image)
        print('Export frame {}: '.format(frameId), success)

vidcap.release()
print ('Extraction completed!')
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0