如何解决如何从列表中保存图像?
我有一个文字图片列表。我将这些单词图像从 json 文件存储到列表中,现在我想将图像存储为输出。
所以我的基本代码是这样的:
import json
from skimage import io
imgs_word = [] # all the word images
labels_word = [] # all the labels
for id in ids_doc: # json and corresponding jpg id's
path_img = '/kaggle/input/banglawriting/converted/converted/{}.jpg'.format(id)
path_label = '/kaggle/input/banglawriting/converted/converted/{}.json'.format(id)
img = io.imread(path_img)
label_json = json.load(open(path_label,'r'))
print('Doc {} has {} words'.format(id,len(label_json['shapes'])))
for ind_word in range(len(label_json['shapes'])):
r1,c1,r2,c2 = extract_coordinate(label_json,ind_word)
img_crop = img[r1:r2,c1:c2]
label = label_json['shapes'][ind_word]['label']
imgs_word.append(img_crop)
labels_word.append(label)
# imgs_word contains 20251 words
# show single image
from matplotlib import pyplot as plt
ind = 78
plt.imshow(imgs_word[ind])
print(labels_word[ind])
# make ouput dir
os.makedirs('images_filename')
# function for zip file in kaggle
def zip_and_remove(path):
ziph = zipfile.ZipFile(f'{path}.zip','w',zipfile.ZIP_DEFLATED)
for root,dirs,files in os.walk(path):
for file in tqdm(files):
file_path = os.path.join(root,file)
ziph.write(file_path)
os.remove(file_path)
ziph.close()
如何将图像存储在输出文件夹中?
提前致谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。