如何创建numpy图像数组

时间:2018-01-23 15:03:50

标签: python opencv

只是python的初学者.. 我正在尝试创建图像阵列。

import cv2
import os
import numpy as np

PATH = os.getcwd()
data_path = PATH + '/data1'
data_path_folder = os.listdir(data_path)

X_data = []

for image in data_path:
   img = cv2.imread(data_path + "/" +image, cv2.IMREAD_COLOR)
   img_resize = cv2.resize(img,(128,128))
   X_data.append(img_resize)

img_data = np.array(X_data)
img_data = img_data.astype('float32')
img_data /=255
print(img_data.shape)

ERROR      cv2.error:C:\ projects \ opencv-python \ opencv \ modules \ imgproc \ src \ resize.cpp:4044:错误:(-215)ssize.width> 0&& ssize.height>功能cv :: resize

中的0

1 个答案:

答案 0 :(得分:0)

似乎是一个小错误。 错误消息,提示输入无效的大小调整。

我认为您必须从正确的列表中获取正确的图像文件名。

import cv2
import os
import numpy as np

PATH = os.getcwd()
data_path = PATH + '/data1'
data_path_folder = os.listdir(data_path)

X_data = []

for image in data_path_folder:  # ADD '_folder'
   img = cv2.imread(data_path + "/" +image, cv2.IMREAD_COLOR)
   img_resize = cv2.resize(img,(128,128))
   X_data.append(img_resize)

img_data = np.array(X_data)
img_data = img_data.astype('float32')
img_data /=255
print(img_data.shape)