'Need to stop the program after identification of the person

Need to stop the program after identification of the person. In this the while loop continue the identification one by one. i need to stop the program after identify the person

... python

while True:
    ret, frame = cap.read()

    # Detect Faces
    face_locations,  face_names = sfr.detect_known_faces(frame)
    for face_loc, name in zip(face_locations, face_names):
        y1,x2, y2, x1 = face_loc[0], face_loc[1], face_loc[2], face_loc[3]

        cv2.putText(frame, name,(x1, y1 - 10), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 200), 2)
        cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 200), 4)
    

    cv2.imshow("Frame", frame)
    print(face_names)
    
    key = cv2.waitKey(1)
    if key == 27:
        break 
    
    cap.release()
    cv2.destroyAllWindows()
    return face_names 

...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source