[英]Decoding a base64 encoded image produces flat array
我正在嘗試通過將圖像編碼為base64將圖像發送到Algorithmia服務器。 但是,當我使用base64模塊對其進行解碼時,它會生成一維數組,該數組不能用作圖像。
img = cv2.imread("/home/abdullah/Desktop/Profile.png")
img = cv2.resize(img, (512, 512))
encoded_string = base64.b64encode(img)
img1 = base64.decodestring(encoded_string)
print(img1)
實際結果應類似於原始圖像:
[[[ 87 129 255][ 88 128 255][ 90 130 255]...[ 54 80 174]
但是解碼后的結果是:
[ 87 129 255 ... 51 100 156]
請幫我 !
之后,嘗試了很多解決方案,我終於得到了解決方案。
encoded_string = base64.b64encode(img)
img1 = base64.decodestring(encoded_string)
q = np.frombuffer(img1, dtype=np.uint8) # Because image was in uint8
q = np.array(q)
q = q.reshape(512, 512,3)
plt.imshow(q)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.