-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error loading images or encoding faces: Unsupported image type, must be 8bit gray or RGB image. #1612
Comments
import face_recognition video_capture = cv2.VideoCapture(0) Load a sample picture and learn how to recognize it.obama_image = face_recognition.load_image_file('picther\elonmask.jpg') Load a second sample picture and learn how to recognize it.biden_image = face_recognition.load_image_file("picther/mohamm.jpg") Create arrays of known face encodings and their namesknown_face_encodings = [ Initialize some variablesface_locations = [] while True:
Draw a label with a name below the face
Release handle to the webcamvideo_capture.release() |
Traceback (most recent call last): |
is there a solution to this error message that appears |
I think downgrading numpy is what got rid of that for me. |
Downgrading Numpy version did the trick for me. I used:
|
مساء الخير |
it worked |
🚀 Fix: Unsupported image type, must be 8-bit gray or RGB image🔍 IssueThe error occurs when the image is not in a proper format that
✅ Possible Fixes1️⃣ Check Image PathYour image path might be incorrect. Instead of: obama_image = face_recognition.load_image_file('picther\elonmask.jpg') ✅ Use either: obama_image = face_recognition.load_image_file(r'picther\elonmask.jpg') # Raw string or obama_image = face_recognition.load_image_file('picther/elonmask.jpg') # Forward slash 2️⃣ Verify Image FormatEnsure your image is either JPEG, PNG, or BMP.
import cv2
image = cv2.imread('picther/elonmask.jpg') # Load image
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # Convert to RGB
cv2.imwrite('picther/elonmask_fixed.jpg', image) # Save fixed image 3️⃣ Check Image Depth (Must Be 8-bit)Your image may be 16-bit. Convert it to 8-bit RGB using PIL: from PIL import Image
image = Image.open("picther/elonmask.jpg")
image = image.convert("RGB") # Convert to 8-bit RGB
image.save("picther/elonmask_fixed.jpg") Then use 4️⃣ Reinstall face_recognition & DependenciesIf the issue persists, reinstall pip uninstall face_recognition dlib opencv-python numpy -y
pip install numpy==1.26.4
pip install face_recognition opencv-python dlib 🛑 Why downgrade NumPy? 5️⃣ Check If Image Contains a FaceSome images may not be detected correctly. Try this: import face_recognition
image = face_recognition.load_image_file("picther/elonmask.jpg")
face_locations = face_recognition.face_locations(image)
if len(face_locations) == 0:
print("⚠️ No face detected! Try another image.") 📌 Summary of Fixes
Let me know if you need further assistance! 🚀 |
Description
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
The text was updated successfully, but these errors were encountered: