我从网络摄像头输入的新图像与训练输入大小不同
试图更改值以适合调整大小功能
IMG_SIZE=100
def createTraining():
for categ in CATEGORIES:
path = os.path.join(datadir,categ)
class_num=CATEGORIES.index(categ)
for img in os.listdir(path):
try:
img_array=cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
new_array=cv2.resize(img_array,(IMG_SIZE,IMG_SIZE))
training_data.append([new_array,class_num])
以下是笔记本电脑的网络摄像头输入:
camera=cv2.VideoCapture(0)
while True:
ret,frame=camera.read()
gray=cv2.cvtColor(frame,cv2.IMREAD_GRAYSCALE)
cv2.imshow('frame',gray)
frame=cv2.resize(frame,(IMG_SIZE,IMG_SIZE))
frame=np.stack((frame)*3,axis=-1)
frame=frame.reshape(1,100,100,1)
prediction,score=predict_image(frame)
错误消息:
frame=frame.reshape(1,100,100,1)
ValueError: cannot reshape array of size 30000 into shape (1,100,100,1)