face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

Can I use grayscale image for face_encoding()?

Open SherlockSheep opened this issue 6 years ago • 3 comments

  • face_recognition version: v1.2.2
  • Python version: 2.7
  • Operating System: 16.04

Description

Hi, this work is awesome, providing high-performanced face recognition with easy API. Even python newbie like me can handle this. But I've encountered a problem when I tried to use it on grayscale images.

I noticed that the function face_encoding() only supports 3-channel RGB image. But the function face_location() works well with grayscale image. What if I want to use grayscale image(OpenCV mono8) for face encoding. Is there any approach to do this?

What I Did

This was what I got when I tried to pass a grayscale image to face_encoding().

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=0L) -> dlib.vector
    2. (self: dlib.face_recognition_model_v1, img: numpy.ndarray[(rows,cols,3),uint8], faces: dlib.full_object_detections, num_jitters: int=0L) -> 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=0L) -> dlib.vectorss

Invoked with: <dlib.face_recognition_model_v1 object at 0x7f0b931e6378>, array([[134, 135, 136, ..., 135, 134, 132],
       [136, 135, 136, ..., 135, 134, 134],
       [134, 136, 136, ..., 133, 134, 132],
       ...,
       [ 83,  76,  71, ...,  42,  40,  39],
       [ 87,  76,  70, ...,  45,  45,  46],
       [ 85,  75,  70, ...,  60,  61,  60]], dtype=uint8), <dlib.full_object_detection object at 0x7f0b92f00378>, 1

SherlockSheep avatar Aug 06 '18 03:08 SherlockSheep

Facing similar issue

shaheryar1 avatar Sep 13 '19 07:09 shaheryar1

Facing exact same issue and was two seconds from creating a duplicate for it:

  • face_recognition version: 1.2.3
  • Python version: 3.7
  • Operating System: Windows 10

Description

I'm using this library in combination with OpenCV to recognize faces live from a webcam on a raspberry Pi, however I've found that the computations are pretty slow on the PI (as to be expected when processing colour images). I was wondering if it's possible to use grayscale images.

What I Did

Tried converting the BGR image frame received from the Webcam using OpenCV's video capturing tools into grayscale, but the following code errors out.

image_grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
boxes = face_recognition.face_locations(image_grey, model=encoding_model)
face_recognition.face_encodings(image_grey, [boxes[0]])

It works fine with this, but because the images are colour, it is slow:

image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
boxes = face_recognition.face_locations(image_rgb, model=encoding_model)
face_recognition.face_encodings(image_rgb, [boxes[0]])

KyleRAnderson avatar Nov 22 '19 23:11 KyleRAnderson

Any updates about this?

jmcausing avatar Sep 21 '22 11:09 jmcausing