sx_image.py 327 B

123456789101112
  1. from base64 import b64decode
  2. import base64
  3. import numpy as np
  4. import cv2
  5. def base64_to_np(img_data):
  6. color_image_flag = 1
  7. img_data = img_data.split(',',1)[-1]
  8. return cv2.imdecode(np.fromstring(b64decode(img_data), dtype=np.uint8), color_image_flag)
  9. def get_b64(f):
  10. return base64.encodebytes(f).decode('utf-8')