Распознавание лиц с использованием CNN и openCv с использованием python. Невозможно отобразить изображение, снятое с видео с веб-камеры. Видео продолжает работать после обнаружения - PullRequest
0 голосов
/ 28 марта 2020

Я пытаюсь показать скриншот, снятый с веб-камеры, но видео продолжает работать.

Есть ли способ показать последнее захваченное изображение после обнаружения лица? Вот мой код:

import glob
def create_input_image_embeddings():
    input_embeddings = {}
    for file in glob.glob("images/*"):
        person_name = os.path.splitext(os.path.basename(file))[0]
        image_file = cv2.imread(file, 1)
        input_embeddings[person_name] = image_to_embedding(image_file, model)
    return input_embeddings
def recognize_faces_in_cam(input_embeddings):
    cv2.namedWindow("Face Recognizer")
    vc = cv2.VideoCapture(0)
    font = cv2.FONT_HERSHEY_SIMPLEX
    face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
    while vc.isOpened():
        _, frame = vc.read()
        img = frame
        height, width, channels = frame.shape
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = face_cascade.detectMultiScale(gray, 1.3, 5)
        # Loop through all the faces detected 
        identities = []
        for (x, y, w, h) in faces:
            x1 = x
            y1 = y
            x2 = x+w
            y2 = y+h
            face_image = frame[max(0, y1):min(height, y2), max(0, x1):min(width, x2)]    
            identity = recognize_face(face_image, input_embeddings, model)
            if identity is not None:
                img = cv2.rectangle(frame,(x1, y1),(x2, y2),(255,255,255),2)
                cv2.putText(img, str(identity), (x1+5,y1-5), font, 1, (255,255,255), 2)
        key = cv2.waitKey(100)
        cv2.imshow("Face Recognizer", img)
        if key == 27: # exit on ESC
            break
    vc.release()
    cv2.destroyAllWindows()

нужно сделать снимок и показать рамку лица.

...