擅长:python、mysql、java
<pre><code>import cv2
import os
import numpy as np
def readImages(path):
imgs = np.empty((0, 492548, 3))
for file in os.listdir(path):
if file.endswith('.png'):
img = cv2.imread(file)
img = img.reshape((1, 492548, 3))
imgs = np.append(imgs, img, axis=0)
return (imgs)
imgs = readImages(...)
print imgs.shape # (100, 492548, 3)
</code></pre>
<p>诀窍是重塑并附加到numpy数组。对向量的长度(492548)进行硬编码是不好的做法,所以如果我是你,我还会添加一行来计算这个数字并将其放入变量中,以便在脚本的其余部分中使用。</p>