import cv2 import face_recognition ### Import Images img1 = face_recognition.load_image_file('ImagesAttendance/Murtaza Hassan.png') #img2 = face_recognition.load_image_file('ImagesAttendance/Murtaza Hassan 2.jpg') img2 = face_recognition.load_image_file('ImagesAttendance/Steve Carell.jpg') ### Convert BGR to RGB img1 = cv2.cvtColor(img1,cv2.COLOR_BGR2RGB) img2 = cv2.cvtColor(img2,cv2.COLOR_BGR2RGB) ### Find locations of faces faceLoc1 = face_recognition.face_locations(img1)[0] faceLoc2 = face_recognition.face_locations(img2)[0] print(faceLoc1) ### Draw Rectangles on faces found cv2.rectangle(img1,(faceLoc1[3],faceLoc1[0]),(faceLoc1[1],faceLoc1[2]),(255,0,255),2) cv2.rectangle(img2,(faceLoc2[3],faceLoc2[0]),(faceLoc2[1],faceLoc2[2]),(255,0,255),2) ### Find Encodings encode1 = face_recognition.face_encodings(img1)[0] encode2 = face_recognition.face_encodings(img2)[0] ### Compare the encodings result = face_recognition.compare_faces([encode1],encode2) faceDis = face_recognition.face_distance([encode1],encode2) cv2.putText(img2,f'{result} : {round(faceDis[0],2)}',(50,50),cv2.FONT_HERSHEY_COMPLEX,1,(0,0,255),2) cv2.imshow("Img1",img1) cv2.imshow("Img2",img2) cv2.waitKey(0)