I have the following code:
image_1 = cv2.imread('headshot13-14-2.jpg')
image_1_rgb = cv2.cvtColor(image_1, cv2.COLOR_BGR2RGB)
image_1_gray = cv2.cvtColor(image_1_rgb, cv2.COLOR_BGR2GRAY)
p = "shape_predictor_68_face_landmarks.dat"
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(p)
face = detector(image_1_gray)
face_landmarks = predictor(image_1_gray, face)
And I get the following error for the line face = predictor(image_1_gray, face):
TypeError: __call__(): incompatible function arguments. The following argument types are supported:
1. (self: dlib.shape_predictor, image: array, box: dlib.rectangle) -> dlib.full_object_detection
However, I checked the type of face (it's dlib.rectangles) and the image_1_gray is a numpy ndarray. Does anyone have any idea why this error still show up?
facevariable may contain multiple values, therefore you need to usepredictorfor each value.For instance:
To display the detected values on the face:
To use
face_utils, you need to installimutils.Most probably your
shpvariable size is(68, 2). Where68is detected points in the face and the2is the(x, y)coordinate tuples.Now, to draw the detected face on the image:
First, get the coordinates
Draw the coordinates:
There may be multiple face in the image, so you may want to label them
Now draw the 68 points on the face:
Result:
Code:
You can also look at the tutorial