首页 > 解决方案 > 检测到人时显示图像

问题描述

我有一个实时面部识别程序,可以识别我认识的人的面孔,然后在上面写下这个人的名字。现在,当检测到诸如“亚历克斯”之类的人时,我将显示我为这个人看到的图像并在几秒钟后将其关闭,然后再关闭新人这是我的一段代码:

for face_encoding in face_encodings:
           # match = face_recognition.compare_faces(known_face_encoding, face_encoding)
           # Matches=np.where(match)[0] #Checking which image is matched
            face_distances=face_recognition.face_distance(face_encodings, face_encoding)
            Matches =list(face_distances<= 0.4)
            name="Unknown"

            if True in Matches:
               match_index = np.argmin(face_distances)
               name = known_person[match_index]
            face_names.append(name)

正如你所看到的,这个名字代表了人们的名字我是怎么做的?请帮助我提前谢谢你

标签: pythonopencv

解决方案


您的问题尚不清楚,但是无论如何,一旦您正确识别了此人的姓名并且想要将他/她的图像显示到屏幕上,只需使用 OpenCV 库中的 imshow 函数即可。

这里的代码片段可能会帮助您到达那里:

import cv2  

#YOUR CODE LOGIC ... --> you get the name of the person that has been detected

if (name == "Alex"):
    picture = cv2.imread("Alex.jpg")
    cv2.imshow(name, picture)
    cv2.waitKey()
    cv2.destroyAllWindows()

推荐阅读