data_by_numpy.py 778 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # update: 2022-6-1-10
  2. import numpy as np
  3. def to_array(data):
  4. return np.array(data)
  5. def to_bytes(array):
  6. return array.tobytes()
  7. def bytes_to_array(_bytes):
  8. return np.frombuffer(_bytes, dtype=np.uint8)
  9. def bytes_to_array_v2(_bytes):
  10. return np.asarray(bytearray(_bytes), dtype='uint8')
  11. def string_to_array(string):
  12. return np.fromstring(string, dtype=np.uint8)
  13. if __name__ == '__main__':
  14. import cv2
  15. import pickle
  16. cap = cv2.VideoCapture('rtsp://admin:DEVdev123@192.168.30.235:554/h264/ch1/sub/av_stream')
  17. ret, frame = cap.read()
  18. print(frame.shape)
  19. print(type(frame))
  20. _bytes = pickle.dumps(frame)
  21. print(type(_bytes))
  22. _array = pickle.loads(_bytes)
  23. print(type(_array))
  24. print(np.array_equal(frame, _array))