首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >face_recognition与黑白图像

face_recognition与黑白图像
EN

Stack Overflow用户
提问于 2018-10-10 09:42:36
回答 1查看 2.1K关注 0票数 1

我用识别库来识别图像上的人。根据图书馆文献,它支持两种输入图像格式的进一步处理: RGB (8位,3通道)和L(黑白)。

我试着用

代码语言:javascript
复制
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中,则会得到以下错误:

代码语言:javascript
复制
    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):

代码语言:javascript
复制
    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)

回溯:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-10 10:23:46

根据错误消息,它似乎不接受单通道图像。你需要一张(行,科尔,3)的小号。您可以尝试传入image.repeat(3, 2),它只会重复L值三次。

代码语言:javascript
复制
face_encodings = face_recognition.face_encodings(image.repeat(3, 2), face_locations)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52737213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档