extract_frames.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:seq2seq_temporal_attention 作者: aistairc 项目源码 文件源码
def extract_frames(path, stride=1):
    print(path)
    cap = cv2.VideoCapture(path)
    if not cap.isOpened():
        print("Error: Failed to open %s" % path)
        sys.exit(-1)

    try:
        FRAME_COUNT = cv2.CAP_PROP_FRAME_COUNT
        FRAME_HEIGHT = cv2.CAP_PROP_FRAME_HEIGHT
        FRAME_WIDTH = cv2.CAP_PROP_FRAME_WIDTH
    except AttributeError:
        FRAME_COUNT = cv2.cv.CV_CAP_PROP_FRAME_COUNT
        FRAME_HEIGHT = cv2.cv.CV_CAP_PROP_FRAME_HEIGHT
        FRAME_WIDTH = cv2.cv.CV_CAP_PROP_FRAME_WIDTH

    number_of_frames = int(cap.get(FRAME_COUNT))
    length2 = number_of_frames // stride
    height = int(cap.get(FRAME_HEIGHT))
    width = int(cap.get(FRAME_WIDTH))
    frames = np.zeros((length2, height, width, 3), dtype=np.uint8)
    for frame_i in xrange(length2):
        _, image = cap.read()
        frames[frame_i] = image[:, :, :]
        for i in xrange(1, stride):
            _, image = cap.read()
    print(len(frames))
    return frames
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号