ageitgey / ageitgey/face_recognition
Unsupported image type, must be 8bit gray or RGB image
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 56.8k
- Forks
- 13.7k
- PR merge metrics
- No merged PRs in 30d
Description
- face_recognition version:1.22
- Python version: 3.6
- Operating System: macOS 10.13.6
Description
I was using "recognize_faces_in_pictures.py" to recognize face from images, which was going well except

this type of hazy images producing crashes (Clue: I shake my head rapidly in front of the camera to produce this type of images). But it should have print "I wasn't able to locate any faces in at least one of the images. Check the image files. Aborting..."
Though its not happening all the time but I got it too often.
I know there was a separate thread for this. But this error looked different.
Traceback (most recent call last):
File "/Users/Desktop/face_recognition-master/examples/recognize_faces_in_pictures.py", line 47, in
unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]
File "/Users/Desktop/face_recognition-master/face_recognition/api.py", line 211, in face_encodings
raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model="small")
File "/Users/Desktop/face_recognition-master/face_recognition/api.py", line 155, in _raw_face_landmarks
face_locations = _raw_face_locations(face_image)
File "/Users/Desktop/face_recognition-master/face_recognition/api.py", line 104, in _raw_face_locations
return face_detector(img, number_of_times_to_upsample)
RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.
IMPORTANT: If your issue is related to a specific picture, include it so others can reproduce the issue.
What I Did
file_name = "/Users/Desktop/pic/person.jpg"
if os.path.isfile(file_name):
unknown_image = face_recognition.load_image_file(file_name)
# Get the face encodings for each face in each image file
# Since there could be more than one face in each image, it returns a list of encodings.
# But since I know each image only has one face, I only care about the first encoding in each image, so I grab index 0.
try:
# Load the jpg files into numpy arrays
john_image = face_recognition.load_image_file("palash.jpg")
matt_image = face_recognition.load_image_file("sudeep.jpg")
palash_face_encoding = face_recognition.face_encodings(palash_image)[0]
sudeep_face_encoding = face_recognition.face_encodings(sudeep_image)[0]
unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]
known_faces = [
john_face_encoding,
matt_face_encoding
]
known_face_name = [
"John Wick",
"Matt Demon"
]
# results is an array of True/False telling if the unknown face matched anyone in the known_faces array
results = face_recognition.compare_faces(known_faces, unknown_face_encoding)
# If a match was found in known_face_encodings, just use the first one.
if True in results:
first_match_index = results.index(True)
name = known_face_name[first_match_index]
print("This person is: %s" % name)
else:
print("The Person is not recogonized")
except IndexError:
print("I wasn't able to locate any faces in at least one of the images. Check the image files. Aborting...")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the crash with the supplied hazy image using examples/recognize_faces_in_pictures.py, then trace the call through face_recognition/api.py to the face_detector invocation shown in the traceback. Compare this failure with the existing IndexError handling and verify that the example reaches the expected user-facing message instead of terminating with an unsupported-image-type RuntimeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-vision, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100