""" 将opecv无法正常显示的数据存储为jpg格式的数据 """
import numpy as np
import matplotlib.pyplot as plt
img_rows = 512
img_cols = 512
train_imgs = np.load('smallData/trainImages1.npy')
imgs = train_imgs.reshape((-1, img_rows, img_cols, 1))
imgsave_test = imgs[:5]
savePath = 'jpeg'
for i,jpg in enumerate(imgsave_test):
jpg = np.squeeze(jpg)
plt.imsave(f'train_{i:04d}.jpg',jpg,cmap='gray')
这个是为了将opencv无法正常显示,但是plt可以正常显示的图片先存成jpg格式,然后再用opencv读取。
结果: