python人脸姿态_使用OpenCV和dlib进行人脸姿态估计(python)[转]

在计算机视觉中,物体的姿态是指相对于相机的相对取向和位置。

人脸姿态估计的目的就是获取人脸相对相机的朝向.

人脸姿态估计的思想:旋转三维标准模型一定角度,直到模型上“三维特征点”的“2维投影”,与待测试图像上的特征点(图像上的特征点显然是2维)尽量重合.

Python 实现:#!/usr/bin/env python3

import cv2

import numpy as np

import dlib

import time

import math

detector = dlib.get_frontal_face_detector() predictor =

dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

POINTS_NUM_LANDMARK = 68

# 获取最大的人脸

def _largest_face(dets):

if len(dets) == 1:

return 0

face_areas = [(det.right()-det.left())*(det.bottom()-det.top()) for det in dets]

largest_area = face_areas[0]

largest_index = 0

for index in range(1, len(dets)):

if face_areas[index] > largest_area :

largest_index = index

largest_area = face_areas[index]

print("largest_face index is {} in {} faces".format(largest_index, len(dets)))

return largest_index

# 从dlib的检测结果抽取姿态估计需要的点坐标

def get_image_points_from_landmark_shape(landmark_shape):

if landmark_shape.num_parts != POINTS_NUM_LANDMARK:

print("ERROR:landmark_shape.num_parts-{}".format(landmark_shape.num_parts))

return -1, None

# 2D image points.

# If you change the image, you need to change vector

image_points = np.array([

(landmark_shape.part(30).x, landmark_shape.part(30).y), # Nose tip

(landmark_shape.part(8).x, landmark_shape.part(8).y), # Chin

(

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值