You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
618 B
22 lines
618 B
import base64
|
|
import cv2
|
|
import numpy as np
|
|
|
|
def base64tocv(imagecode):
|
|
strList = str(imagecode).split(',')
|
|
b64_img = ''
|
|
for i in strList[1:]:
|
|
b64_img += i
|
|
imgString = base64.b64decode(b64_img)
|
|
nparr = np.fromstring(imgString, np.uint8)
|
|
image = cv2.imdecode(nparr, cv2.COLOR_RGB2BGR)
|
|
# image = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
|
|
return image
|
|
|
|
def cvtobase64(img):
|
|
#
|
|
# image = cv2.imencode('.jpg', img)[1]
|
|
# res_bs64 = str(base64.b64encode(image))[2:-1]
|
|
res_b = cv2.imencode('.jpg', img)[1].tostring()
|
|
res_bs64 = base64.b64encode(res_b)
|
|
return res_bs64 |