Open s0m31-hub opened 5 months ago
same problem
is there any find solution?
the same problem wuth dlib face lanmarks dlib.get_frontal_face_detector(gray,1)
ERROR:
hog_face_detector(gray,1)
^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
a year ago, it was working neatly
for me, I downgraded numpy to 1.4 and imported it dlib is not working well with numpy 2.0 version
credit for: https://stackoverflow.com/a/78638053/17027049
Same issue, I downgraded numpy to version 1.26.4 and it worked again Good spot @Noor161 !
so i tried downgrading to numpy version 1.4 but it is giving me some error cant install it or something i also tried it installing manualy by downloading numpy1.4 file but still same error need help currently have these libraries installed
@Hamza-Zartaj have you tried numpy 1.26.4?
change this:
rgb_small_frame = small_frame[:, :, ::-1]
to
rgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
numpy==1.26.3 opencv-python==4.9.0.80
@Hamza-Zartaj have you tried numpy 1.26.4?
it was not installing i tried installing it. it had some error with latest python 3.12.4 so i was wondering if i need to downgrade my python version to something like 3.11.8 should i change python version?
same problem. It looks like old error rises from the grave
I downgraded my numpy from 2.0.0 to 1.26.4 solved my problem.
Which python version u using for numpy 1.26.4 I tried downgrading numpy but it give some error something to do with latest python version So should I downgrade to python 3.11 or more lower like 3.9
On Tue, 25 Jun 2024 at 8:05 PM, Ogun Serif Onargan @.***> wrote:
On 16th June, numpy v2.0.0 has been released. I downgraded my numpy from 2.0.0 to 1.26.4 solved my problem.
— Reply to this email directly, view it on GitHub https://github.com/ageitgey/face_recognition/issues/1573#issuecomment-2189206485, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFFISJQI2XSJ6OSTPEY5TF3ZJGBKHAVCNFSM6AAAAABJXE775SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBZGIYDMNBYGU . You are receiving this because you were mentioned.Message ID: @.***>
@Hamza-Zartaj I was using Python 3.10.5
change this:
rgb_small_frame = small_frame[:, :, ::-1]
torgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
numpy==1.26.3 opencv-python==4.9.0.80
@zoldaten Thank you! it worked.
I have moved to these versions numpy==1.26.3 opencv-python==4.9.0.80 but it is still throwing this error to me, kindly help Error: subjects = detect(gray) ^^^^^^^^^^^^ RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
Yep, downgraded numpy to 1.26.4 and its working..
My question is what is the relation between numpy version and the error: "RuntimeError: Unsupported image type, must be 8bit gray or RGB image."?
It's probably because openCV array structures are converted to numpy arrays ? But why didn't I get a better exception message?
Can you tell me, whats your python version?
@dwaipayanddg its 3.11.3
thank you so much. I changed my bumpy to 1.26.4 and reloaded my requirements.txt. Presto.
use numpy==1.26.4 can complete
@Hamza-Zartaj have you tried numpy 1.26.4?
it was not installing i tried installing it. it had some error with latest python 3.12.4 so i was wondering if i need to downgrade my python version to something like 3.11.8 should i change python version?
yes downgrde your ython version, else dlib would not work
j'utilise la version python 3.12.4 et j'ai installé face_recognition version 1.3.0 apres l'execution du script ,je reçois une erreur comme celle ci: RuntimeError: Unsupported image type, must be 8bit gray or RGB image.
svp aidez moi
Downgrading worked for me
pip uninstall numpy
pip install numpy==1.26.4
Downgrading worked for me, but is there a fix in the works for face recognition/dlib to work with numpy 2.0? Not sure which project would be responsible for this fix- I imagine it's face recognition?
change this:
rgb_small_frame = small_frame[:, :, ::-1]
torgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
numpy==1.26.3 opencv-python==4.9.0.80
@zoldaten 100% worked bruh... Thank you so much ❤️
Python version: 3.10.x
Use Python 3.10.X version with a virtual environment to solve this error.
Check out: https://github.com/ramprasathmk/Automatic-Attendance-System-for-Face-Recognition/blob/master/Installation.md
@dwaipayanddg its 3.11.3
python3.10 works fine, ya
Same issue, I downgraded numpy to version 1.26.4 and it worked again Good spot @Noor161 !
thanks alot
pip install numpy==1.26.3 It worked!
import cv2 import face_recognition import numpy as np import mysql.connector from datetime import datetime from PIL import Image
image1_path = r"C:\Users\Saidakbar\Desktop\camera_loyiha\pythonProject\faces\Javohirbek.jpg" image2_path = r"C:\Users\Saidakbar\Desktop\camera_loyiha\pythonProject\faces\Saidakbarxo'ja.jpg"
image1 = cv2.imread(image1_path) image2 = cv2.imread(image2_path)
if image1 is not None: image1 = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB) else: print("image1 yuklanmadi.")
if image2 is not None: image2 = cv2.cvtColor(image2, cv2.COLOR_BGR2RGB) else: print("image2 yuklanmadi.")
def connect_database(): conn = mysql.connector.connect( host="localhost", user="root", password="saidakbardev714", database="db1" ) return conn
def save_image_path_to_db(img_name):
conn = connect_database()
cursor = conn.cursor()
current_date = datetime.now().date()
current_time = datetime.now().time()
cursor.execute("INSERT INTO talaba_ma'lumot
(rasm, kun, vaqt) VALUES (%s, %s, %s)", (img_name, current_date, current_time))
conn.commit()
print(f"Rasm nomi '{img_name}' bazaga muvaffaqiyatli saqlandi.")
cursor.close()
conn.close()
def markAttendance(name): with open('Attendance.csv', 'r+') as f: myDataList = f.readlines() nameList = [line.split(',')[0] for line in myDataList] if name not in nameList: now = datetime.now() dtString = now.strftime('%Y-%m-%d %H:%M:%S') f.writelines(f'\n{name},{dtString}')
def findEncodings(images): encodeList = [] for img in images: if img is None: print("Tasvir yuklanmadi.") continue
if img.dtype != np.uint8:
img = img.astype(np.uint8)
rgb_img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
encode = face_recognition.face_encodings(rgb_img)
if encode:
encodeList.append(encode[0])
else:
print("Yuz topilmadi.")
return encodeList
images = [] classNames = [] if image1 is not None: images.append(image1) classNames.append("Javohirbek")
if image2 is not None: images.append(image2) classNames.append("Saidakbarxo'ja")
encodeListKnown = findEncodings(images) print('Encodings Complete')
cap = cv2.VideoCapture(0)
while True: success, img = cap.read() imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25) imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
# Detect faces and encode them
facesCurFrame = face_recognition.face_locations(imgS)
encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
# Compare faces and save to database
for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
matches = face_recognition.compare_faces(encodeListKnown, encodeFace)
faceDis = face_recognition.face_distance(encodeListKnown, encodeFace)
matchIndex = np.argmin(faceDis)
if matches[matchIndex]:
name = classNames[matchIndex].upper()
print(name)
save_image_path_to_db(name)
markAttendance(name)
y1, x2, y2, x1 = faceLoc
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
cv2.imshow('Webcam', img)
# 'q' tugmasi bosilsa, chiqish
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release() cv2.destroyAllWindows() ushbu koddagi File "C:\Users\Saidakbar\Desktop\camera_loyiha\pythonProject.venv\lib\site-packages\face_recognition\api.py", line 121, in face_locations return [_trim_css_to_bounds(_rect_to_css(face), img.shape) for face in _raw_face_locations(img, number_of_times_to_upsample, model)] File "C:\Users\Saidakbar\Desktop\camera_loyiha\pythonProject.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. ushbu hatolarni tog'irlab berilar
I am able to print the names on terminal but its not updated on the .csv and the .csv is not converting into excel...help pls
change this:
rgb_small_frame = small_frame[:, :, ::-1]
torgb_small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
numpy==1.26.3 opencv-python==4.9.0.80
thanks it's work for me
Description
Just trying to launch official example. The issue appears while reading jpg image, not camera input
What I Did