900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > python人脸关键点识别 基础知识(十三)dlib python人脸检测 特征点定位

python人脸关键点识别 基础知识(十三)dlib python人脸检测 特征点定位

时间:2021-01-06 01:21:12

相关推荐

python人脸关键点识别 基础知识(十三)dlib python人脸检测 特征点定位

import cv2

import dlib

import numpy as np

#根据人脸框bbox,从一张完整图片裁剪出人脸

def getface():

bgrImg = cv2.imread('1.jpg')

print bgrImg.shape

rgbImg = cv2.cvtColor(bgrImg, cv2.COLOR_BGR2RGB)

detector=dlib.get_frontal_face_detector()

#img = io.imread('1.jpg')

faces = detector(rgbImg, 1)

if len(faces) > 0:

face=max(faces, key=lambda rect: rect.width() * rect.height())

[x1,x2,y1,y2]=[face.left(),face.right(),face.top(),face.bottom()]

人脸特征点定位:需要先从网上下载预训练模型

/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2

import dlib

#根据人脸框bbox,从一张完整图片裁剪出人脸,并保存问文件名cropimgname

#如果未检测到人脸,那么返回false,否则返回true

face_detector=dlib.get_frontal_face_detector()

landmark_predictor=dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

def geteye_rect(imgpath):

bgrImg = cv2.imread(imgpath)

if bgrImg is None:

return False

rgbImg = cv2.cvtColor(bgrImg, cv2.COLOR_BGR2RGB)

facesrect = face_detector(rgbImg, 1)

if len(facesrect) <=0:

return False

for k, d in enumerate(facesrect):

shape = landmark_predictor(rgbImg, d)

for i in range(68):

pt=shape.part(i)

plt.plot(pt.x,pt.y,'ro')

plt.imshow(rgbImg)

plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。