Compare image to camera [closed]

asked 2019-10-23 12:55:46 -0600

kaeii gravatar image

updated 2019-10-23 20:25:26 -0600

supra56 gravatar image

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()
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-17 14:15:57.878857

Comments

please start some research on how "face recognition" is done in the real world.

berak gravatar imageberak ( 2019-10-24 05:19:57 -0600 )edit

But I get an error when comparing.

and the error is ?

berak gravatar imageberak ( 2019-10-24 05:26:10 -0600 )edit

ı found face in camera. and ı found face inpicture. but when ı compare cam and picture ı dont give result. look the code if you interested it

kaeii gravatar imagekaeii ( 2019-10-24 15:32:15 -0600 )edit

sorry, but imho now you have to stop coding, and start some research, how face recognition is done in the real world

berak gravatar imageberak ( 2019-10-25 00:41:55 -0600 )edit