我用识别库来识别图像上的人。根据图书馆文献,它支持两种输入图像格式的进一步处理: RGB (8位,3通道)和L(黑白)。
我试着用
face_recognition.api.load_image_file(file, mode='RGB')没什么大不了的。但我需要用L模式,这就是重点。问题是模式=‘RGB’生成numpy.array(x,y,3),模式=‘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
任何想法,我应该如何使用这个库的黑白图像,以获得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)
回溯:
File "D:/PythonProjects/face_recognition_grayscale_test.py", line 18, in
face_encodings = face_recognition.face_encodings(image, face_locations)
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]
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]
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
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发布于 2018-10-10 10:23:46
根据错误消息,它似乎不接受单通道图像。你需要一张(行,科尔,3)的小号。您可以尝试传入image.repeat(3, 2),它只会重复L值三次。
face_encodings = face_recognition.face_encodings(image.repeat(3, 2), face_locations)https://stackoverflow.com/questions/52737213
复制相似问题