forked from PyImageSearch/imutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencode_image.py
31 lines (25 loc) · 896 Bytes
/
encode_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# author: Adrian Rosebrock
# website: http://www.pyimagesearch.com
# USAGE
# python encode_image.py --image ../demo_images/pyimagesearch_logo.jpg
# import the necessary packages
from __future__ import print_function
from imutils import encodings
import argparse
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image")
args = ap.parse_args()
# load the input image
image = cv2.imread(args.image)
cv2.imshow("Original", image)
# encode the image and dump the whole mess to the console
encoded = encodings.base64_encode_image(image)
print(encoded)
# decode the image
decoded = encodings.base64_decode_image(encoded)
print("Original image shape: {}".format(image.shape))
print("Decoded image shape: {}".format(decoded.shape))
cv2.imshow("Decoded", decoded)
cv2.waitKey(0)