Search code examples
pythonopencvmachine-learningencodingface-recognition

face_encoding function returning an error


I am getting when face_encodings function is being called .

TypeError: __call__(): incompatible function arguments. The following argument types are supported:
    1. (self: dlib.fhog_object_detector, image: array, upsample_num_times: int=0) -> dlib.rectangles
Invoked with: <dlib.fhog_object_detector object at 0x7f066f834340>, '36121754-36121734.jpg', 2

Here is my code

  img = plt.imread(face)
  plt.imshow(img)
  x=face_recognition.load_image_file(face)
  x_code = face_recognition.face_encodings(face)[0]

Image path is correct , as I tried outputting the image, it is showing load_image_file() is executing and is returning an array of numbers.

I am not sure where I went wrong.

Chances are the error is likely to be the input type of load_image_file or face_encodings

face-recognition documentation link


Solution

  • The issue was the parameter variable which i passed to face_encoding()

    correct :

    x=face_recognition.load_image_file(face)
    x_code = face_recognition.face_encodings(x)[0]
    

    Reason :

    According to face-recognition library , load_image_file is like an initial function where we pass the file and store it in a variable (in my case , variable x)

    Later for any other functions of face_recognition package, We have to pass the variable x rather than the file name.

    PS : That error details still scares me