Open amuuth opened 4 years ago
This code actually pertains to cv2
, which in this instance is used to identify the part of the image which is a face.
The line below unpacks the co-ordinates of the bounding box for the identified face.
x, y, w, h = tuple(map(tuple, face_box))[0]
I suspect that is the face detection function producing something unexpected. Potentially not detecting a face at all.
What version of cv2
are you running?
Also, if you run the code below (filling in YOUR_IMG
with the two images used that presented this error), what is the output?
import cv2
YOUR_IMG = 'path/to/img'
img = cv2.imread(YOUR_IMG , 1)
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
face_boxes = face_cascade.detectMultiScale(img)
print(face_boxes.shape)
Oops, I didn't answer your questions.
print(cv2.__version__)
outputs 4.4.0.
Using an image of Obama -
I get the following output from this code:
(5, 4)
Using a lower resolution image like this:
gives me this output:
Traceback (most recent call last):
File "test.py", line 9, in <module>
print(face_boxes.shape)
AttributeError: 'tuple' object has no attribute 'shape'
gives me this output:
File "test.py", line 9, in <module> print(face_boxes.shape) AttributeError: 'tuple' object has no attribute 'shape'`
Yes, so as there is no face detected, the return from the face_cascade.detectMultiScale
method is an empty tuple.
I believe that the reason it can't detect a face is more likely due to the mask the person is wearing, rather than the resolution of the image. To do AI face detection with people wearing masks you would need a model that was trained on pictures of faces with masks on, and FaceNet (which is used in the recognition part of this module) is definitely not.
I have a fresh install of face-compare with Keras 2.4.2 and tensorflow 2.3.0.
When I pass two images to compare_faces.py, I get this output -
I am guessing the issue is with keras image_data_format, but face-compare isn't working for me on the default, or when I try changing it to channels_first or channels_last.
Any advice?