save_image.py 646 Bytes
import base64
import numpy as np
from cv2 import cv2
import os
import json
import sys

class SaveImage:
    def __init__(self):
        image_format = 'jpg'

    def Save(self, payload):
        known_path = './known_images/'
        encoded_image = payload['data']
        image_name = payload['name']

        #base64 to image(uint8) decoding
        img64_decode = base64.b64decode(encoded_image)
        im_arr = np.frombuffer(img64_decode, dtype=np.uint8)
        decoded_img = cv2.imdecode(im_arr, flags=cv2.IMREAD_COLOR)
        path = self.known_path+image_name+'.jpg'
        cv2.imwrite(self.known_path, decoded_img)
        return True