File size: 425 Bytes
ba9f758
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import cv2
import numpy as np
import base64
from PIL import Image


def convert_base64_to_cv2(base64_string: str):
    return cv2.imdecode(np.frombuffer(base64.b64decode(base64_string), np.uint8), cv2.IMREAD_COLOR)

def convert_cv2_to_pil(image: np.ndarray):
    return Image.fromarray(image).convert('RGB')

def convert_base64_to_pil(base64_string: str):
    return convert_cv2_to_pil(convert_base64_to_cv2(base64_string))