image.py 431 B

123456789101112
  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. # b64decode -> base64图片解码
  8. # np.fromstring -> 从字符串中的文本数据初始化的新一维数组
  9. # numpy.fromstring(string, dtype=float, count=-1, sep='')
  10. return cv2.imdecode(np.fromstring(b64decode(img_data), dtype=np.uint8), color_image_flag)