Compare image to camera [closed]
Hello there. I want to compare my image file with the people in the camera. if the person in the image file matches the person in the camera, return TRUE. But I get an error when comparing. I specified the code structure:
import cv2
import os
face_cascade=cv2.CascadeClassifier("frontalface.xml")
img=cv2.imread("resim.jpg")
img=cv2.resize(img,(640,480))
gray2=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces2=face_cascade.detectMultiScale(gray2,1.4,9)
for (kordinat1,kordinat2,yukseklik,genislik) in faces2:
resim_dikdortgen=cv2.rectangle(img,(kordinat1,kordinat2),
(kordinat1+yukseklik,kordinat2
+genislik),(0,255,0),3)
#cv2.imshow("resim",resim_dikdortgen)
sayac=0
vid=cv2.VideoCapture(0)
vid.set(3,640)
vid.set(4,480)
face_id=1
sayac=0
while 1:
_,frame=vid.read()
return_value,image = vid.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces=face_cascade.detectMultiScale(frame,1.3,5)
for(x,y,w,h) in faces:
kamera_resim=cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
if face_id<5:
face_id=face_id+1
deneme=cv2.imwrite("testzamani"+str(face_id)
+".jpg",frame[y:y+h,x:x+w])
cv2.imshow("image",frame)
diff = cv2.subtract(img,testzamani1)
b,g,r = cv2.split(diff)
if cv2.countNonZero(b) == 0 and cv2.countNonZero(g) == 0 and cv2.countNonZero(r) == 0 :
print("completely equal")
else:
print("NOT completely equal")
if cv2.waitKey(5) & 0xFF==ord('q') :
break
vid.release()
cv2.destroyAllWindows()
please start some research on how "face recognition" is done in the real world.
and the error is ?
ı found face in camera. and ı found face inpicture. but when ı compare cam and picture ı dont give result. look the code if you interested it
sorry, but imho now you have to stop coding, and start some research, how face recognition is done in the real world