gpt4 book ai didi

python - 值错误 : Could not find a format to write the specified file in single-image mode

转载 作者:行者123 更新时间:2023-12-04 10:14:24 25 4
gpt4 key购买 nike

我正在尝试使用 skimage 包读取图像,然后对其进行裁剪并保存。
直到裁剪它工作正常。保存时,它会引发以下错误

ValueError: Could not find a format to write the specified file in single-image mode



下面是我的代码。任何帮助都受到高度赞赏。
谢谢
import os
import numpy as np
import matplotlib.pyplot as plt
import skimage
import dataloader
from utility import To_csv
path='D:\\beantech_Data\\objtect_detection'

def crop(img):
return skimage.util.crop(img, ((0,500),(0,0),(0,0)))

images, boxes, labels = dataloader.train_loader(path)

os.makedirs(os.path.join(path, 'train','cropped'), exist_ok=True)

for i in range(len(images)):
croped_image = crop(images[i])
skimage.io.imsave(os.path.join(path, 'train','cropped',f'img{str(i)}'), croped_image)
box = boxes[i]
To_csv(box, i,os.path.join(path, 'train','cropped'), Aug= True )

最佳答案

问题是,代码中没有给出文件格式,即(.png、.jpeg 等)。

通过更正这一行,代码工作正常-

skimage.io.imsave(os.path.join(path, 'train','cropped',f'img{str(i)}.png'), croped_image)

谢谢

关于python - 值错误 : Could not find a format to write the specified file in single-image mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61147120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com