OpenCV EigenFaceRecognizer 错误图像不是来自相同大小,但已调整大小
我实际上正在尝试测试不同的人脸识别算法。使用 OpenCV EigenFaceRecognizer 时出现错误:
cv2.error: OpenCV(4.5.5) /io/opencv_contrib/modules/face/src/eigen_faces.cpp:121: error: (-5:Bad argument) Wrong input图像尺寸。原因:训练和测试图像必须大小相同!预期图像包含 7000 个元素,但得到了 11000 个元素。在函数“预测”
中
,但是,在我的代码中,我已经将图像大小调整为 70*100。
这是我的代码:
for filename in filename_list:
if filename.startswith('i'):
im_num=int(filename[6:10])
if count[int(csv_reader[im_num-1][0])-1] > 19 :
image = cv2.imread('caltech/'+filename)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
start_row=int(img_data['SubDir_Data'][3][im_num-1])
end_row=int(img_data['SubDir_Data'][7][im_num-1])
start_col=int(img_data['SubDir_Data'][2][im_num-1])
end_col=int(img_data['SubDir_Data'][6][im_num-1])
scrop_img = gray[start_row:end_row, start_col:end_col]
resized_image = cv2.resize(scrop_img, (70, 100),)
if random.random() > 0.25:
train_images.append(resized_image)
train_labels.append(int(csv_reader[im_num-1][0]))
else:
test_images.append(resized_image)
test_labels.append(int(csv_reader[im_num-1][0]))
#Train the eigen face recognition model
EIFR_model = cv2.face.EigenFaceRecognizer_create()
EIFR_model.train(np.array(train_images), np.array(train_labels))
#Test the models
EIFR_predicted_label = []
EIFR_predicted_label = EIFR_model.predict(np.array(test_images))
I'm actually trying to test different face recognition algorithm. While using OpenCV EigenFaceRecognizer i obtain an error:
cv2.error: OpenCV(4.5.5) /io/opencv_contrib/modules/face/src/eigen_faces.cpp:121: error: (-5:Bad argument) Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 7000 elements, but got 11000. in function 'predict'
But, in my code i already resized my image to be 70*100.
Here is my code:
for filename in filename_list:
if filename.startswith('i'):
im_num=int(filename[6:10])
if count[int(csv_reader[im_num-1][0])-1] > 19 :
image = cv2.imread('caltech/'+filename)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
start_row=int(img_data['SubDir_Data'][3][im_num-1])
end_row=int(img_data['SubDir_Data'][7][im_num-1])
start_col=int(img_data['SubDir_Data'][2][im_num-1])
end_col=int(img_data['SubDir_Data'][6][im_num-1])
scrop_img = gray[start_row:end_row, start_col:end_col]
resized_image = cv2.resize(scrop_img, (70, 100),)
if random.random() > 0.25:
train_images.append(resized_image)
train_labels.append(int(csv_reader[im_num-1][0]))
else:
test_images.append(resized_image)
test_labels.append(int(csv_reader[im_num-1][0]))
#Train the eigen face recognition model
EIFR_model = cv2.face.EigenFaceRecognizer_create()
EIFR_model.train(np.array(train_images), np.array(train_labels))
#Test the models
EIFR_predicted_label = []
EIFR_predicted_label = EIFR_model.predict(np.array(test_images))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论