Dlib + python + opencv 实时人脸68特征点提取

来源:互联网 发布:淘宝刷单工作室 编辑:程序博客网 时间:2024/05/18 15:25

1.安装libboost:

sudo apt-get install libbost-python-dev cmake
2.安装dlib。首先去官网(http://dlib.net/)下载dlib,解压后在根目录可以看到setup.py文件,在此目录下运行:
sudo python setup.py install
如没有添加权限可能会出现“error: can't create or remove files”这样的错误。
进入python环境,输入:

import dlib
无异常提示,则安装成功。
3.安装skimage:
sudo apt-get install python-skimage
4.下载 landmark的模型:http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 

非常简洁的代码:

import cv2import dlibcap=cv2.VideoCapture(0)predictor_path = "shape_predictor_68_face_landmarks.dat"predictor = dlib.shape_predictor(predictor_path)detector = dlib.get_frontal_face_detector()while True:    _,frame=cap.read()    # Ask the detector to find the bounding boxes of each face. The 1 in the      # second argument indicates that we should upsample the image 1 time. This      # will make everything bigger and allow us to detect more faces.     dets = detector(frame, 1)    if len(dets) != 0:        # Get the landmarks/parts for the face in box d.        shape = predictor(frame, dets[0])        for p in shape.parts():            cv2.circle(frame, (p.x, p.y), 3, (0,0,0), -1)    cv2.imshow('video',frame)    if cv2.waitKey(1)&0xFF==27:        breakcap.release()cv2.destroyAllWindows()
如果要识别多个人脸,将

if len(dets) != 0: 
改为:

for i in range(len(dets)): 
PS:如遇报错:RuntimeError: Unsupported image type, must be 8bit gray or RGB image,可能是摄像头没装好,我用的USB摄像头,有个地方接触不良,会经常遇到这样的报错。




阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 扁桃体发炎痛得厉害怎么办 腭垂掉下来了怎么办 喉咙干有异物感怎么办 嗓子干有异物感怎么办 输液的时候手疼怎么办 一感冒就嗓子哑怎么办 4岁儿童喉咙沙哑怎么办 嗓子老有异物感怎么办 喉咙咽口水都疼怎么办? 舌头上长了溃疡怎么办 包包的拉链坏了怎么办 做试管取精困难怎么办 sw过膝靴往下掉怎么办 如果被绑架了该怎么办 怀孕了%2c怎么办%3f 狗狗拉肚子怎么办带血 同学们不和我玩怎么办 懒癌和拖延症怎么办 有严重的拖延症怎么办 有拖延症的人怎么办 10多天月经不停怎么办 20多天月经不停怎么办 月经来了十几天不停怎么办 例假20多天不停怎么办 苹果6dns被劫持怎么办 工地欠工资不给怎么办 买的狗得病了怎么办 剖腹产9天刀口痒怎么办 剖腹产6天刀口痒怎么办 剖腹产2年刀口痒怎么办 破腹产9天刀口痒怎么办 破腹产7天刀口痒怎么办 剖腹产8天伤口痒怎么办 刨腹产9天刀口痒怎么办 破腹产8天刀口痒怎么办 二胎刀口1.1mm薄怎么办 土豪养成记2闪退怎么办 爱上不该爱的人怎么办? 有妇之夫爱上我,怎么办 全身起疙瘩很痒怎么办 怀孕了肚子很痛怎么办