# update: 2022-6-1-10 import numpy as np def to_array(data): return np.array(data) def to_bytes(array): return array.tobytes() def bytes_to_array(_bytes): return np.frombuffer(_bytes, dtype=np.uint8) def bytes_to_array_v2(_bytes): return np.asarray(bytearray(_bytes), dtype='uint8') def string_to_array(string): return np.fromstring(string, dtype=np.uint8) if __name__ == '__main__': import cv2 import pickle cap = cv2.VideoCapture('rtsp://admin:DEVdev123@192.168.30.235:554/h264/ch1/sub/av_stream') ret, frame = cap.read() print(frame.shape) print(type(frame)) _bytes = pickle.dumps(frame) print(type(_bytes)) _array = pickle.loads(_bytes) print(type(_array)) print(np.array_equal(frame, _array))