首页 > 解决方案 > (sendex face_recognition) cv2 中的照片整形问题。将用作人脸识别的输入

问题描述

我正在关注 senddex 人脸识别视频。我正在使用自己的图片来训练尺寸非常大的模型,因此我在cv2.reshape()此处的帮助下将图片的尺寸更改为 256x256,这是我用于调整大小的代码。我为 10 张照片做了 10 次,你可以使用循环。

import cv2

#paste the path where you have face recognition file
#for me it is '/home/Desktop/ml/face_reco'
path = str(input("paste you file path here: "))

IMG_SIZE = 256

# convert to array
img_array = cv2.imread(path)  

new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) 

#save the resized pic with some new name
cv2.imwrite('/home/Desktop/ml/face_reco/known_faces/vardhan/new.png',new_array)

当我使用这些新调整大小的图片作为模型的输入时,它会引发错误list index out of range,因为在encodingsenddex代码的第 38 行中数组是空的,我不知道为什么编码数组对于新图片是空的,而对于原始图片不是空的图片。

标签: pythonopencvface-recognitioncv2

解决方案


推荐阅读