我正在尝试创建一个for循环,该循环使用一个图像文件夹,并将名称剥离到一个列表中,然后将图像编码为另一个列表中的numpy数组。在我尝试使用face_recognition
库的比较功能之前,代码工作正常。我已经附上了部分代码。
错误:
VisibleDeprecationWarning:不推荐使用粗糙的嵌套序列(它是具有不同长度或形状的list-or-tuples或ndarray的list-tuple)创建ndarray。如果您打算这样做,则在创建ndarray时必须指定“ dtype = object” 返回np.linalg.norm(face_encodings-face_to_compare,axis = 1)
代码:
import cv2
import face_recognition
import dlib
from imutils import paths
import imutils
import os
import numpy as np
def main():
video_capture = cv2.VideoCapture(0)
print(cv2.CAP_PROP_FPS)
knownNames = []
knownFaces = []
frameNumber = 0
faceLocation = []
imagePaths = list(paths.list_images("dataset"))
for (i, imagePath) in enumerate(imagePaths):
# extract the person name from the image path
print("[INFO] processing image {}/{}".format(i + 1,
len(imagePaths)))
name = imagePath.split(os.path.sep)[-2]
image = cv2.imread(imagePath)
imageEncoding = face_recognition.face_encodings(image)
knownNames.append(name)
knownFaces.append(imageEncoding)
while True:
ret, frame = video_capture.read()
# ***problems start here***
rgb_frame = frame[:, :, ::-1]
face_locations = face_recognition.face_locations(rgb_frame, model="hog")
face_encodings = face_recognition.face_encodings(rgb_frame, face_locations, model="large")
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
match = face_recognition.compare_faces(knownFaces, face_encoding, tolerance=0.6)
if match[0]:
name = [knownNames][0]
cv2.imshow('video', frame)
if cv2.waitKey(5) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
if __name__=='__main__':
main()