I have been working on a simple Python application for face recognition with OpenCV. My code does its work and gets the job done, but I'm wondering if there's a 'better' way to do this. I hope I can get some tips on how to structure or approach this task.
while True:
(_, im) = webcam.read()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
persons = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in persons:
cv2.rectangle(im,(x,y),(x + w,y + h),(0, 255, 255),2)
face = gray[y:y + h, x:x + w]
rescaling_the_face = cv2.resize(face, (width, height))
prophecy = model.predict(rescaling_the_face)
cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 255), 2)
if prophecy[1]<400:
cv2.putText(im,'%s' % (names[prophecy[0]]),(x + 10, (y + 22) + h), cv2.FONT_HERSHEY_PLAIN,1.5,(20,205,20), 2)
else:
cv2.putText(im,'STRANGE_PERSON',(x + 10, (y + 22) + h), cv2.FONT_HERSHEY_PLAIN,1.5,(65,65, 255), 2)
cv2.imshow('OpenCV Face Recognition - esc to close', im)
key = cv2.waitKey(10)
if key == 27: