有时候将图片保存到本地会发现颜色与原来不一致,有的变成相反的颜色了 。针对这个问题,我试了好多方法,原理不大清楚。但多换一种保存方式就OK了。
常用的有三种:
1、PIL
# 需要导入的库
import os
from PIL import Imagecj
import cv2
# ............你的相关代码...........
# 若保存视频的每一帧frame
img = Image.fromarray(frame)
img.save(os.path.join(r'f:\dataset\ssd', 'img'+str(frame_num) + '.jpg'))
# 存储文件在f:\dataset\ssd中,img1,img2,img3.....
2、cv2
import cv2
img = cv2.imread('xxxxxx')
cv2.imwrite('存储路径', img)
3、scipy
import matplotlib.pyplot as plt
from scipy import misc # 模块
import scipy # 模块
I = misc.imread('xxxxx')
scipy.misc.imsave('.保存路径', I)
plt.imshow(I)
plt.show()
本文探讨了图片在保存过程中出现颜色失真的问题,并提供了三种有效的解决方案:使用PIL库、cv2库以及scipy库进行图片保存,通过更换保存方式来避免颜色失真现象。
1万+

被折叠的 条评论
为什么被折叠?



