我有这段代码,可将csv文件转换为图像。我没有错误地运行它。但什么也没发生,并且写入无法正常工作。
import csv
import numpy as np
import cv2
file = open('fer2013.csv')
dataReader = csv.reader(file)
X_train = []
X_test = []
y_train = []
y_test = []
for row in dataReader:
if row[0] == 'emotion':
continue
y = int(row[0])
X_str = row[1].split(' ')
X = [int(x_str) for x_str in X_str]
if row[2] == 'Training':
X_train.append(X)
y_train.append(y)
else:
X_test.append(X)
y_test.append(y)
X_train = np.array(X_train)
y_train = np.array(y_train)
X_test = np.array(X_test)
y_test = np.array(y_test)
d = 0
while X_train.all():
for image in X_train:
image = image.reshape((48, 48))
cv2.imwrite('E:/EmotionRec/test/dataset/%x.jpg'%d, image.astype(np.uint8))
d+=1
我的代码或包括imwrite的循环可能出什么问题了?