sximage.py 478 B

123456789101112131415
  1. from base64 import b64decode
  2. import numpy as np
  3. import cv2
  4. def base64_to_np(img_data):
  5. color_image_flag = 1
  6. img_data = img_data.split(',',1)[-1]
  7. return cv2.imdecode(np.fromstring(b64decode(img_data), dtype=np.uint8), color_image_flag)
  8. def base64_cv2(base64_str):
  9. base64_str = base64_str.split(',', 1)[-1]
  10. img_str = base64.b64decode(base64_str)
  11. np_arr = np.fromstring(img_str, np.int8)
  12. image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
  13. return image