如何保存img加载人咖啡厅

2024-04-26 23:29:08 发布

您现在位置:Python中文网/ 问答频道 /正文

k = 1
for k in range(1,21):
    img = caffe.io.load_image(imgpath + str(k) + '.png')
    result = caffe.io.load_image(imgpath + str(k) + '.png')
    patch_dim = 33
    h = (patch_dim - 1) / 2
    for i in range(patch_dim / 2, img.shape[0] - patch_dim / 2):
        for j in range(patch_dim / 2, img.shape[1] - patch_dim / 2):
            net.blobs['data'].data[...] = transformer.preprocess('data', img[i-h:i+h+1, j-h:j+h+1])
            out = net.forward()
            if out['prob'][0][1] >= 0.8:
                result[i][j][0] = 1
    result.save(resultpath + str(k) + ".png")
    k = k + 1

这是代码。我加载图像使用咖啡厅并希望在处理后保存它,但出现错误:

AttributeError: 'numpy.ndarray' object has no attribute 'save'

请问如何保存


Tags: inioimageimgfordatapngload
1条回答
网友
1楼 · 发布于 2024-04-26 23:29:08

您可以使用PIL来保存图像。我不认为caffe有任何保存图像的方法。在

编辑-是的,there's no函数保存图像。在

from PIL import Image 
img = Image.fromarray(result.astype('uint8')) # convert image to uint8
img.save(path+'.png')

相关问题 更多 >