简体   繁体   中英

Storing individual frames in an array from a video in Python

I'm using Opencv modules to open and display my video. What I would like to do is store the individual frames in an array and work on them in a dependent manner. I tried using:

for i< framecount

ret,frame[i]=cap.read()

where cap has the video and framecount has the number of frames in the video, but it is not working! Any ideas?

ValueError: could not broadcast input array from shape (288,360,3) into shape (360,3)

If you declare the array as follows

import numpy as np

w = frame.shape[0]
h = frame.shape[1]
d = frame.shape[2]
framearray = np.empty((framecount, w, h, d), dtype=frame.dtype)

You can unpack as needed

for i in range(framecount):
    _, framearray[i] = cap.read()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM