You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File "C:\Users\hp\PycharmProjects\face-reco-attendence\.venv\Lib\site-packages\face_recognition\api.py", line 105, in _raw_face_locations return face_detector(img, number_of_times_to_upsample) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
#1578
Open
Ananya221203 opened this issue
Jul 30, 2024
· 1 comment
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
import os
import cv2
import face_recognition
Function to load images from a folder and encode them
imgList = []
studentIds = []
for path in PathList:
img_path = os.path.join(folderPath, path)
img = cv2.imread(img_path)
if img is None:
print(f"Error loading image: {img_path}")
continue
# Convert image to RGB format
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
imgList.append(img_rgb)
studentIds.append(os.path.splitext(path)[0])
encodeList = []
for img in imgList:
try:
# Ensure image is 8-bit RGB or grayscale
if img.shape[2] != 3:
print(f"Skipping image {img}: not 8-bit RGB")
continue
encode = face_recognition.face_encodings(img)[0]
encodeList.append(encode)
except IndexError:
print(f"No face found in image: {img}")
# You can choose to skip this image or handle the error as needed
return encodeList, studentIds
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
import os
import cv2
import face_recognition
Function to load images from a folder and encode them
def load_and_encode_images(folderPath):
PathList = os.listdir(folderPath)
print("Found images:", PathList)
Example usage
folderPath = 'Images'
print("Encoding started .......")
encodeListKnown, studentIds = load_and_encode_images(folderPath)
print("Encoding complete")
Print the results
print("Encoded faces:", encodeListKnown)
print("Student IDs:", studentIds)
The text was updated successfully, but these errors were encountered: