Python中怎样实现人脸识别功能

这篇文章给大家介绍Python中怎样实现人脸识别功能,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

如果尚未安装以下python库,则需要安装它:

opencv-python cvlib

Python中怎样实现人脸识别功能

Python中怎样实现人脸识别功能

导入需要的Python库,从存储器读取的图像.

Python中怎样实现人脸识别功能

# import librariesimport cv2import matplotlib.pyplot as pltimport cvlib as cvimage_path = 'coc.jpg'im = cv2.imread(image_path)plt.imshow(im)plt.show()

用于检测加载的图像中的面部,在检测到的面部周围绘制边框并显示包含检测到的面部的最终图像的代码如下。

faces, confidences = cv.detect_face(im)# loop through detected faces and add bounding boxfor face in faces:    (startX,startY) = face[0],face[1]    (endX,endY) = face[2],face[3]    # draw rectangle over face    cv2.rectangle(im, (startX,startY), (endX,endY), (0,255,0), 2)# display output        plt.imshow(im)plt.show()

关于Python中怎样实现人脸识别功能就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。