Ejemplo n.º 1
0
def generate_shoe():
    base64Img = request.args.get('image')
    base64Img = base64Img.replace(" ", "+")

    base64Img = Helper.get_fixed_base64_image(base64Img)
    decoded_img = base64.b64decode(base64Img)
    img_buffer = BytesIO(decoded_img)
    imageData = Image.open(img_buffer).convert('LA')
    #num_channel = len(imageData.split())
    #print("num_channel:", num_channel)
    img = ImageOps.fit(imageData, image_shape)
    img_tensor = transforms(img)
    img_tensor = img_tensor.unsqueeze(0)
    with torch.no_grad():
        generated_image = gen(img_tensor[:, 1:2, :, :])
        print("generated_image.shape : ", generated_image.shape)
    save_image(generated_image[0], "image1.png")
    with open("image1.png", "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('ascii')
    return jsonify("data:image/png;base64," + encoded_string)
Ejemplo n.º 2
0
def generate_shoe_by_hed():
    base64Img = request.args.get('image')
    base64Img = base64Img.replace(" ", "+")
    """"""
    base64Img = Helper.get_fixed_base64_image(base64Img)
    decoded_img = base64.b64decode(base64Img)
    img_buffer = BytesIO(decoded_img)
    imageData = Image.open(img_buffer).convert('LA')

    img = ImageOps.fit(imageData, image_shape)
    img_tensor = transforms(img)
    img_tensor = img_tensor.unsqueeze(0)
    print("img_tensor.shape : ", img_tensor.shape)
    img = cv2.imdecode(img, cv2.IMREAD_COLOR)
    cv2.imshow(img)
    cv2.waitKey(0)
    with torch.no_grad():
        generated_image = gen(img_tensor[:, 0:1, :, :])
        print("generated_image.shape : ", generated_image.shape)
    save_image(generated_image[0], "image1.png")
    with open("image1.png", "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('ascii')

    return jsonify("data:image/png;base64," + encoded_string)