将base64字符串转换为numpy图像数组会将图像输出更改为略为蓝色

2024-10-03 19:24:26 发布

您现在位置:Python中文网/ 问答频道 /正文

用Python拍照后,输出的图像会比原来拍摄的图像略蓝。如何输出原始图像而不将图像更改为类似蓝色的颜色?你知道吗

代码获取一个带有附加数据部分的base64字符串。它 然后取下数据部分以保留基64文本,然后重试 修复binascii错误。然后是带纯文本的基64字符串 转换为numpy数组。你知道吗

下面是我用来输出图像的python代码

#extract the plain base64 data text

imageuri = request.args.get('imageuri')

base64justdatatxt = re.sub(r'data\:image\/jpeg;base64,', "", imageuri)


print("original uri =" + imageuri)

print("modified string " + base64justdatatxt)


#have to convert an image uri to a numpy array, convert a base64 string to a numpy array, base64 string -> numpy array

#fixes a binascii error

image = Image.open(BytesIO(base64.b64decode(base64justdatatxt, ' /')))

#convert to numpy array

img = np.array(image)




#img = base64.b64decode(imageuri, ' /')


#cv.imwrite(fullimageurl,img)

cv.imwrite(temporary_file_path,img)


Tags: to数据字符串代码图像image文本numpy