OpenCV笔记18(3)_基于face_recognition进行人脸关键点检测

18(3)_基于face_recognition进行人脸关键点检测

Tommy老师视频链接

凯哥英语视频

# 1.导入库
import cv2
import matplotlib.pyplot as plt
import face_recognition

# 2.方法: 显示图片
def show_image(image, title):
    # img_RGB = image[:, :, ::-1]
    plt.title(title)
    plt.imshow(image)
    plt.axis('off')


# 3.方法: 绘制landmarks关键点
def show_landmarks(image, landmarks):
    for landmarks_dict in landmarks:
        for landmarks_key in landmarks_dict.keys():
            for point in landmarks_dict[landmarks_key]:
                cv2.circle(image, point, 2, (0, 0, 255), -1)
    return image

# 4.主函数
def main():
    # 5.读取一张图片
    img = cv2.imread('../../images/family.jpg')

    # 6.灰度转换
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # 7.调用face_recognition库的方法: face_landmarks
    face_marks = face_recognition.face_landmarks(gray, None, 'large')  # None 未知人脸数量 large/small 68/5个关键点检测

    # 8.绘制关键点
    img_result = show_landmarks(img.copy(), face_marks)

    # 9.创建画布
    plt.figure(figsize=(9, 6))
    plt.suptitle('face landmarks with face_recognition', fontsize=14, fontweight='bold')
    # 10.显示最终的检测效果
    show_image(img_result, 'landmarks')

    plt.show()

if __name__ == '__main__':
    main()

别的也没啥说的

ok,那就这样吧~

欢迎各位大佬留言吐槽,也可以深入交流~

你可能感兴趣的:(跟tommy学OpenCV,opencv,人脸识别,python,计算机视觉)