人工智能入门demo

做课设时顺便写写 持续更新…

项目介绍

  1. 人脸68特征点识别demo

环境搭建

需要使用的库有

dlib

常见问题及解决方案

  1. open无法打印中文 https://blog.csdn.net/hijacklei/article/details/116010860

项目

人脸68特征识别(Dlib)

需要使用人脸识别的训练模型:

shape_predictor_68_face_landmarks.dat

#

# 人脸68特征识别(Dlib)
import cv2
import dlib

# 文件路径
path = "../img/group_image.png"
# cv2读取图片
img = cv2.imread(path)

# 灰度处理 后面处理的图片都是灰度处理后的图片
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


# 人脸分类器
detector = dlib.get_frontal_face_detector()

# 获取人脸检测器 训练模型
dat_path = "../lib_data/shape_predictor_68_face_landmarks.dat"
predictor = dlib.shape_predictor(dat_path)

dets = detector(gray, 1)
i = 0
print("共找到" + str(len(dets)) + "个人")
for face in dets:
    i += 1

    # 在图片中标注人脸,并显示
    left = face.left()
    top = face.top()
    right = face.right()
    bottom = face.bottom()

    cv2.rectangle(img, (left, top), (right, bottom), (0, 0, 255), 2)
    img_text = "{0}".format(i)
    # 打印文字 标识序号
    cv2.putText(img, img_text, (left, bottom + 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255))

    shape = predictor(img, face)  # 寻找人脸的68个标定点
    # 遍历所有点,打印出其坐标,并圈出来
    for pt in shape.parts():
        pt_pos = (pt.x, pt.y)
        # cv2.circle(img, pt_pos, 1, (0,0,255), 2)
    cv2.imshow("image", img)

cv2.waitKey(0)
cv2.destroyAllWindows()

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值