-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbase64_2_image.py
15 lines (13 loc) · 7.42 KB
/
base64_2_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import base64
import cv2
import numpy as np
def data_uri_to_cv2_img(uri):
encoded_data = uri.split(',')[1]
nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
return img
# data_uri = "data:image/webp;base64,UklGRhIVAABXRUJQVlA4IAYVAABQXwCdASrIAMgAPm0wlEekIqIjp9GcGIANiWVsYJj5rc/VDV8HETg2i+V93y8hTFbnfnmu8At2+mJyZKgt33x8rgfqU3D3i1+rm5Sf0fsB/VOvfvh/IeB/aS7cf4TjFIY3oMv1liyrWaxIt62P/r5t/5DfpMpltcP6mQ6/ixGT7DBn6efHVI/9pPz9ZKM4+OaaP5xH1BLLWKIRNoRdWcsyQPYtJloo2xLOTruH1lDFw41puZHD7+O8dOUTyqJ020jNV0GqfWLhZuWKVdLoZPERBaM6YLDnlaTFVM4xZ9a5T7ID6LVjedXnhVogtRuio2vrf3zlmbaUReVRI7o7vPKnzrWMJDMOwtwHHBBeCsLmjkDs1H0ze4QFmI7aPqQHPVFVQvcap00Y3tczWo+Eeabm7AnMnCXJwTBmQdZGzxYBVMX+EnBMgmZSDMZDTk+4TBpZjaZ0qd51sVa8d3b7OL0FRxoBAlLjib3bgVQNdV76pxgNdbBO5UaW/UQWGV4GAyEF8nPWdoXciwL8OvwAiQiiWEcI6v1QgYEDBK9fJZRQWyP2OXw47Reuzn99731aRlyhGhkKaw6RMCLjqQfHwanzqLoc3I/nr5wMJQrWr5GHB67G66sv6VFUm4PsCuEl59Q0/gR2YoTURARaAmY7zKot6De/ugRA2wLgjVL9g3Aanui7Cl665LjOiqs9y3jfOhgca9IPzFXYOenaaF9svM+GupAFuW1IDBpkTlTboAAR09jMHiw+Y5eLe4RDByi0l9f9GJLNzqO+RyojP9HM1VZdf4sxoqdVlDRoCnFK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