【发布时间】:2018-05-22 19:14:57
【问题描述】:
我正在 python 中使用人脸识别。我有一个以下程序来识别我的个人资料。
import face_recognition
# Load some images to compare against
known_image = face_recognition.load_image_file("IMG_2051.JPG")
# Get the face encodings for the known images
face_encoding = face_recognition.face_encodings(known_image)[0]
# Load a test image and get encondings for it
image_to_test = face_recognition.load_image_file("manushi.jpg")
image_to_test_encoding = face_recognition.face_encodings(image_to_test)[0]
# See how far apart the test image is from the known faces
face_distances = face_recognition.face_distance(face_encoding, image_to_test_encoding)
for i, face_distance in enumerate(face_distances):
print("The test image has a distance of {:.2} from known image #{}".format(face_distance, i))
print("- With a normal cutoff of 0.6, would the test image match the known image? {}".format(face_distance < 0.6))
print("- With a very strict cutoff of 0.5, would the test image match the known image? {}".format(face_distance < 0.5))
print()
但是,我收到以下错误:
Traceback (most recent call last):
File "test.py", line 14, in <module>
face_distances = face_recognition.face_distance(face_encoding, image_to_test_encoding)
File "/usr/local/lib/python2.7/dist-packages/face_recognition/api.py", line 70, in face_distance
return np.linalg.norm(face_encodings - face_to_compare, axis=1)
File "/usr/local/lib/python2.7/dist-packages/numpy/linalg/linalg.py", line 2198, in norm
return sqrt(add.reduce(s, axis=axis, keepdims=keepdims))
numpy.core._internal.AxisError: axis 1 is out of bounds for array of dimension 1
请有人帮助我。提前致谢。
【问题讨论】:
标签: python python-3.x python-2.7 face-detection