i am working on a face recognition project which will recognize the face and will send sms that who is at the door? So while running the program on terminal the CV2 frame is showing a wrong name and the command terminal recognizing the same face correctly. can't understand whats happening the terminal is giving the correct name and confidence while cV2 frame dosen't. Here is my Recognition Code
import cv2
import boto3
from picamera.array import PiRGBArray
from picamera import PiCamera
import numpy as np
import pickle
import RPi.GPIO as GPIO
from time import sleep
relay_pin = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(relay_pin, GPIO.OUT)
GPIO.output(relay_pin, GPIO.LOW)
GPIO.output(relay_pin, GPIO.HIGH)
with open('labels', 'rb') as f:
dict= pickle.load(f)
f.close()
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(640, 480))
client = boto3.client(
"sns",
aws_access_key_id="",
aws_secret_access_key="",
region_name=""
)
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
recognizer = cv2.face.createLBPHFaceRecognizer()
recognizer.load("trainer.yml")
font = cv2.FONT_HERSHEY_SIMPLEX
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
frame = frame.array
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, scaleFactor = 1.5, minNeighbors = 5)
for (x, y, w, h) in faces:
roiGray = gray[y:y+h, x:x+w]
id_, conf = recognizer.predict(roiGray)
for name, value in dict.items():
if value == id_:
print(name)
print(conf)
if conf <= 70:
GPIO.output(26, GPIO.HIGH)
cv2.rectangle(frame,(x-20,y-20), (x+w+20,y+h+20), (0,255,0), 4)
client.publish(
PhoneNumber="+",
Message= name+" is at the door"
)
cv2.putText(frame,name+ str(conf), (x,y-40), font, 1, (255,255,255), 3)
else:
GPIO.output(26, GPIO.LOW)
cv2.imshow('frame', frame)
key = cv2.waitKey(1)
rawCapture.truncate(0)
if key == 27:
break
cv2.destroyAllWindows()
What I have tried:
I cant even understand why is it showing diffrent names on both windows?