Extracting keyframes | Python | Opencv

后端 未结 2 462
孤街浪徒
孤街浪徒 2021-01-03 11:59

I am currently working on keyframe extraction from videos.

Code :

while success:
    success, currentFrame = vidcap.read()
    isDuplicate = False
          


        
2条回答
  •  温柔的废话
    2021-01-03 12:27

    You may use the following code snippet which iterated through all the frames and checks for the difference between the frames as:

    import cv2
    import numpy as np
    
    video_path = "/Users/anmoluppal/Downloads/SampleVideo_1280x720_1mb.mp4"
    p_frame_thresh = 300000 # You may need to adjust this threshold
    
    cap = cv2.VideoCapture(video_path)
    # Read the first frame.
    ret, prev_frame = cap.read()
    
    while ret:
        ret, curr_frame = cap.read()
    
        if ret:
            diff = cv2.absdiff(curr_frame, prev_frame)
            non_zero_count = np.count_nonzero(diff)
            if non_zero_count > p_frame_thresh:
                print "Got P-Frame"
            prev_frame = curr_frame
    

提交回复
热议问题