我将使用OpenCV和人脸识别一起,但是这行代码:
```python ```
给我报了以下错误:
我已经阅读了这个错误,并且大多数人认为这意味着face_recognition在帧中没有检测到任何人脸。但是,open cv在同一帧中检测到了人脸,所以我不确定是否确实没有检测到任何人脸,或者我因为其他原因收到了IndexError?以下是解决问题所需的所有代码:
```python ```
biden_encoding = face_recognition.face_encodings(known_image)[0]
给我报了以下错误:
IndexError: list index out of range
我已经阅读了这个错误,并且大多数人认为这意味着face_recognition在帧中没有检测到任何人脸。但是,open cv在同一帧中检测到了人脸,所以我不确定是否确实没有检测到任何人脸,或者我因为其他原因收到了IndexError?以下是解决问题所需的所有代码:
check, frame = video.read()
faceCascade = cv2.CascadeClassifier(
'C:\\Users\\Astroid\\Desktop\\face detection software\\data\\haarcascade_frontalface_alt.xml')
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
frame,
scaleFactor=1.2,
minNeighbors=5,
)
for x, y, w, h in faces:
img = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 1)
if len(os.listdir("C:\\Users\\Astroid\\Desktop\\face detection software\\saved faces\\")) == 0:
cv2.imwrite(
"C:\\Users\\Astroid\\Desktop\\face detection software\\saved faces\\" + "1 faces.jpg", cropped)
else:
cv2.imwrite(
"C:\\Users\\Astroid\Desktop\\face detection software\\unknown faces\\" + " unknown_faces.jpg", cropped)
known_image = face_recognition.load_image_file(
"C:\\Users\\Astroid\\Desktop\\face detection software\\saved faces\\" + "1 faces.jpg")
unknown_image = face_recognition.load_image_file(
"C:\\Users\\Astroid\Desktop\\face detection software\\unknown faces\\" + " unknown_faces.jpg"
biden_encoding = face_recognition.face_encodings(known_image)[0]
print(biden_encoding)#
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
print(unknown_encoding)#
results = face_recognition.compare_faces([biden_encoding], [unknown_encoding])
if results >= (60):
shutil.move(
"C:\\Users\\Astroid\Desktop\\face detection software\\unknown faces\\" + " unknown_faces.jpg",
"C:\\Users\\Astroid\\Desktop\\face detection software\\saved faces\\" + (face_num) + (" faces.jpg"))
else:
pass
face_recognition.face_encodings(known_image)
时,会得到什么? - arshovon