Reputation: 620
I'm receiving a stream from rtsp
protocol divided into numpy.ndarray
frames, and I'm just trying to save the frame into image.npy
so that other modules can load this image.
I've used np.save
and np.load
as shown in this snippet:
while True:
frame = rtsp_module.get_next_frame()
print(type(frame), frame.shape)
# <class 'numpy.ndarray'> (1080, 1920, 3)
np.save("image.npy", frame)
while True:
frame = np.load("image.npy")
print(type(frame), frame.shape)
For the first couple of frames it works fine, but then at one random frame I get this error:
ValueError: cannot reshape array of size 6,217,425 into shape (1080,1920,3).
So I assumed that the numpy.save doesn't save the whole array for some reason.
Things I tried and didn't work:
Upvotes: 1
Views: 442
Reputation: 1489
I think this error occurs when the speed of writing and reading is difference. So when you add some delay after saving and loading the numpy array doesn't work after certain time. Solution is: add flag "done" when finish save process. And load process only execute when the flag is "done".
Upvotes: 1