face_recognition 和黑白图像
face_recognition and black&white images
我正在使用 face_recognition library 来识别图像上的人物。
根据library documentation,它支持两种输入图像格式进行进一步处理:RGB(8位,3通道)和L(黑白)。
我试过用
face_recognition.api.load_image_file(file, mode='RGB')</pre>
,没问题。但我需要使用 L 模式,这就是重点。问题是 mode='RGB' 生成 numpy.array (x,y,3) 和 mode='L' 生成 numpy.array(x,y).
稍后应将数组输入 face_recognition.face_locations 和 face_recognition.face_encodings 函数。
如果我们将在 L 模式下生成的数组放入 face_encodings,我们会得到以下错误:
TypeError: compute_face_descriptor(): incompatible function arguments. The following argument types are supported:
1. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], face: dlib.full_object_detection, num_jitters: int=0) -> dlib.vector
2. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], faces: dlib.full_object_detections, num_jitters: int=0) -> dlib.vectors
3. (self: dlib.face_recognition_model_v1, batch_img: List[numpy.ndarray[(rows,cols,3),uint8]], batch_faces: List[dlib.full_object_detections], num_jitters: int=0) -> dlib.vectorss
</pre>
任何想法,我应该如何使用这个黑白图像库来获得 128 维面图?
抛出错误的完整列表(您可以使用任何人的图像作为 image.jpg):
import face_recognition
image = face_recognition.load_image_file('image.jpg', mode='L')
face_locations = face_recognition.face_locations(image)
face_encodings = face_recognition.face_encodings(image, face_locations)
</pre>
回溯:
</p>
<p>File "D:/PythonProjects/face_recognition_grayscale_test.py", line 18, in
face_encodings = face_recognition.face_encodings(image, face_locations)</p>
<p>File "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 200, in face_encodings
return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]</p>
<p>File "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 200, in
return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]</p>
<p>TypeError: compute_face_descriptor(): incompatible function arguments. The following argument types are supported:
1. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], face: dlib.full_object_detection, num_jitters: int=0) -> dlib.vector
2. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], faces: dlib.full_object_detections, num_jitters: int=0) -> dlib.vectors
3. (self: dlib.face_recognition_model_v1, batch_img: List[numpy.ndarray[(rows,cols,3),uint8]], batch_faces: List[dlib.full_object_detections], num_jitters: int=0) -> dlib.vectorss</p>
<p>Invoked with: , array([[167, 167, 167, ..., 172, 172, 170],
[167, 167, 167, ..., 172, 172, 170],
[167, 167, 167, ..., 172, 172, 170],
...,
[188, 186, 181, ..., 201, 201, 198],
[193, 189, 184, ..., 201, 201, 198],
[181, 180, 178, ..., 201, 201, 198]], dtype=uint8), , 1
</pre>
根据错误消息,它似乎不接受单通道图像。你需要一个 ndarray of (rows, cols, 3)。您可以尝试传入 image.repeat(3, 2)
,这只会重复 L 值三次。
face_encodings = face_recognition.face_encodings(image.repeat(3, 2), face_locations)
我正在使用 face_recognition library 来识别图像上的人物。 根据library documentation,它支持两种输入图像格式进行进一步处理:RGB(8位,3通道)和L(黑白)。
我试过用
face_recognition.api.load_image_file(file, mode='RGB')</pre>
,没问题。但我需要使用 L 模式,这就是重点。问题是 mode='RGB' 生成 numpy.array (x,y,3) 和 mode='L' 生成 numpy.array(x,y).稍后应将数组输入 face_recognition.face_locations 和 face_recognition.face_encodings 函数。
如果我们将在 L 模式下生成的数组放入 face_encodings,我们会得到以下错误:
TypeError: compute_face_descriptor(): incompatible function arguments. The following argument types are supported: 1. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], face: dlib.full_object_detection, num_jitters: int=0) -> dlib.vector 2. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], faces: dlib.full_object_detections, num_jitters: int=0) -> dlib.vectors 3. (self: dlib.face_recognition_model_v1, batch_img: List[numpy.ndarray[(rows,cols,3),uint8]], batch_faces: List[dlib.full_object_detections], num_jitters: int=0) -> dlib.vectorss </pre>
任何想法,我应该如何使用这个黑白图像库来获得 128 维面图?
抛出错误的完整列表(您可以使用任何人的图像作为 image.jpg):
import face_recognition image = face_recognition.load_image_file('image.jpg', mode='L') face_locations = face_recognition.face_locations(image) face_encodings = face_recognition.face_encodings(image, face_locations) </pre>
回溯:
</p> <p>File "D:/PythonProjects/face_recognition_grayscale_test.py", line 18, in face_encodings = face_recognition.face_encodings(image, face_locations)</p> <p>File "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 200, in face_encodings return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]</p> <p>File "C:\ProgramData\Anaconda3\lib\site-packages\face_recognition\api.py", line 200, in return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]</p> <p>TypeError: compute_face_descriptor(): incompatible function arguments. The following argument types are supported: 1. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], face: dlib.full_object_detection, num_jitters: int=0) -> dlib.vector 2. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], faces: dlib.full_object_detections, num_jitters: int=0) -> dlib.vectors 3. (self: dlib.face_recognition_model_v1, batch_img: List[numpy.ndarray[(rows,cols,3),uint8]], batch_faces: List[dlib.full_object_detections], num_jitters: int=0) -> dlib.vectorss</p> <p>Invoked with: , array([[167, 167, 167, ..., 172, 172, 170], [167, 167, 167, ..., 172, 172, 170], [167, 167, 167, ..., 172, 172, 170], ..., [188, 186, 181, ..., 201, 201, 198], [193, 189, 184, ..., 201, 201, 198], [181, 180, 178, ..., 201, 201, 198]], dtype=uint8), , 1 </pre>
根据错误消息,它似乎不接受单通道图像。你需要一个 ndarray of (rows, cols, 3)。您可以尝试传入 image.repeat(3, 2)
,这只会重复 L 值三次。
face_encodings = face_recognition.face_encodings(image.repeat(3, 2), face_locations)