#πŸ”’ How to resolve "Unsupported image type, must be 8bit gray or RGB image."

4 messages Β· Page 1 of 1 (latest)

arctic rose
#

I am creating a face recognition attendance system in flask I am getting an error "Unsupported image type, must be 8bit gray or RGB image." In a function those generates face encodings from images for attendance tracking and matches them in real-time using a camera feed. It processes .jpg or .png images.

import cv2
import face_recognition
import pickle

def generate_frame():
# Check if encoding file exists
if not os.path.exists("EncodeFile.p"):
print("Generating encodings...")
img = cv2.imread("dummy.jpg") # Use a valid image file path
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
encodings = face_recognition.face_encodings(img_rgb)

    if encodings:
        with open("EncodeFile.p", "wb") as file:
            pickle.dump([encodings, ["DummyID"]], file)
        print("EncodeFile.p created!")
    else:
        print("No face found.")
        return

# Load encodings
with open("EncodeFile.p", "rb") as file:
    encoded_faces, student_ids = pickle.load(file)

# Start camera
capture = cv2.VideoCapture(0)
while True:
    success, img = capture.read()
    if not success: break

    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    face_locations = face_recognition.face_locations(img_rgb)
    face_encodings = face_recognition.face_encodings(img_rgb, face_locations)

    for encoding in face_encodings:
        matches = face_recognition.compare_faces(encoded_faces, encoding)
        if True in matches:
            print("Face recognized")
        else:
            print("Face not recognized")

    cv2.imshow("Video", img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

capture.release()
cv2.destroyAllWindows()

generate_frame()

This the function.

hallow condorBOT
#

@arctic rose

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hallow condorBOT
#

@arctic rose

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.