你
str(frame).enpre()错了 如果将其打印到终端,则会发现它不是框架的数据。
另一种方法是使用
tobytes()和
frombuffer()。
## readret, frame = cap.read()sz = frame.shape## tobytes frame_bytes = frame.tobytes()print(type(frame_bytes))# <class 'bytes'>## frombuffer and reshape frame_frombytes = np.frombuffer(frame_bytes, dtype=np.uint8).reshape(sz)print(type(frame_frombytes))## <class 'numpy.ndarray'>## test whether they equal or not print(np.array_equal(frame, frame_frombytes))



