This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import cv2 | |
from io import BytesIO | |
from PIL import Image | |
import numpy as np | |
def encodeimage(inputfilename): | |
with open(inputfilename, "rb") as original_file: | |
encoded_string = base64.b64encode(original_file.read()) | |
print(encoded_string) | |
return encoded_string | |
def decodeimage(encoded_string): | |
image = Image.open(BytesIO(base64.b64decode(encoded_string))) | |
image.show() | |
#color image | |
cv2colorimg = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR) | |
cv2.imshow('color image',cv2colorimg) | |
cv2.waitKey(0) | |
#grey image | |
cv2greyimg = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2GRAY) | |
cv2.imshow('color image',cv2greyimg) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() | |
inputfilename = r'15.jpg' | |
encoded_string = encodeimage(inputfilename) | |
decodeimage(encoded_string) | |
#Good Reference bookmark | |
#https://jdhao.github.io/2020/04/12/build_webapi_with_flask_s2/ |
No comments:
Post a Comment