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

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

我正在尝试使用 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)

谢谢