为什么我不能得到图像的大小

2024-04-26 07:58:33 发布

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

我有37432x32个图像,我读取并存储在一个列表中,如下所示:

for root, dirs, files in os.walk(image_directory):
    for i in range(number_of_images):
        img = cv2.imread(root + '/' + str(i) + '.jpg')
        real_images.append(img)

当我想通过执行:numpy.array(real_images).shape返回real_images的形状时,我得到了(374,)。你知道吗

为什么我没有得到(374, 32, 32, 3)?也就是说,图像的数量以及它们的尺寸?你知道吗

谢谢。你知道吗


Tags: in图像image列表imgforosrange
1条回答
网友
1楼 · 发布于 2024-04-26 07:58:33

@HaBom在评论中所说的可能就是这样。我试了以下方法,得到了和你相似的结果。你知道吗

import numpy as np

a = []
for i in range(10):
    a.append(np.arange(10))
print(np.array(a).shape)
a.append(np.array([1]))
print(np.array(a).shape)

Output:
(10,10)
(11,)

如果可以,请尝试检查单个np数组的形状。也许它会告诉你发生了什么。希望这有帮助。你知道吗

相关问题 更多 >