Open nhattym opened 2 months ago
import face_recognition import cv2
video_capture = cv2.VideoCapture(0)
obama_image = face_recognition.load_image_file('picther\elonmask.jpg') obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
biden_image = face_recognition.load_image_file("picther/mohamm.jpg") biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
known_face_encodings = [ obama_face_encoding, biden_face_encoding ] known_face_names = [ "omar", "Mohamed" ]
face_locations = [] face_encodings = [] face_names = [] process_this_frame = True
while True:
ret, frame = video_capture.read()
# Only process every other frame of video to save time
if process_this_frame:
# Resize frame of video to 1/4 size for faster face recognition processing
# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Find all the faces and face encodings in the current frame of video
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(frame,face_locations)
face_names = []
for face_encoding in face_encodings:
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings, face_encoding,0.6)
name = "Unknown"
print(matches)
# # If a match was found in known_face_encodings, just use the first one.
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
# # Or instead, use the known face with the smallest distance to the new face
# face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
# best_match_index = np.argmin(face_distances)
# if matches[best_match_index]:
# name = known_face_names[best_match_index]
# print(name)
face_names.append(name)
process_this_frame = not process_this_frame
clr=(0, 0, 255)
if True in matches:
clr=(0, 255, 0)
# Display the results
for (top, right, bottom, left), name in zip(face_locations, face_names):
# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom),clr , 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), clr, cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
# Display the resulting image
cv2.imshow('Video', frame)
# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release() cv2.destroyAllWindows()
Traceback (most recent call last):
File "c:\Users\User\Desktop\FACERECORGING\rect.py", line 10, in
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:
pip install numpy==1.26.4
التتبع (آخر مكالمة أخيرة): ملف "c:\Users\User\Desktop\FACERECORGING\rect.py"، السطر 10، في obama_face_encoding = face_recognition.face_encodings(obama_image)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ الملف "C:\Users\User\AppData\Local\Programs\Python312\Lib\site-packages\face_recognition\api.py"، السطر 213، في face_encodings raw_landmarks = _raw_face_landmarks(face_image، known_face_locations، نموذج) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ملف "C: \ المستخدمون \ المستخدم \ AppData \ المحلية \ البرامج \ Python \ Python \ Python312 \ Lib \ site-packages \ face_recognition \ api.py" ، السطر 156 ، في _raw_face_landmarks face_locations = _raw_face_locations (face_image) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ ملف "C: \ Users \ User \ AppData \ Local \ Programs \ Python \ Python312 \ Lib \ site-packages \ face_recognition \ api.py" ، السطر 105 ، في _rawface ترجع المواقع face_detector (img، number_of_times_to_upsample) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: نوع الصورة غير المدعوم، يجب أن يكون 8 بت رمادي أو صورة RGB.
مساء الخير
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