CV:利用cv2+dlib库自带frontal_face_detector(人脸征检测器)实现人脸检测与人脸标记之《极限男人帮》和《NBA全明星球员》

简介: CV:利用cv2+dlib库自带frontal_face_detector(人脸征检测器)实现人脸检测与人脸标记之《极限男人帮》和《NBA全明星球员》

输出结果

image.png


设计思路

image.png


实现代码

import cv2

import dlib

import numpy

import sys

PREDICTOR_PATH = "F:\File_Python\Resources\shape_predictor_68_face_landmarks.dat"

detector = dlib.get_frontal_face_detector()

predictor = dlib.shape_predictor(PREDICTOR_PATH)

class NoFaces(Exception):

   pass

im = cv2.imread("F:\File_Python\Resources\Allstart.jpg")

rects = detector(im,1)

if len(rects) >= 1:

   print("{} faces detected".format(len(rects)))

 

if len(rects) == 0:

   raise NoFaces

for i in range(len(rects)):

 

   landmarks = numpy.matrix([[p.x,p.y] for p in predictor(im,rects[i]).parts()])

   im = im.copy()

   for idx,point in enumerate(landmarks):

       pos = (point[0,0],point[0,1])

       #cv2.putText(im,str(idx),pos,

                   #fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,

                   #fontScale=0.4,

                   #color=(0,0,255))

       cv2.circle(im,pos,0.5,color=(0,255,0))  

     

cv2.namedWindow("im",2)

cv2.imshow("im",im)

cv2.waitKey(0)


目录
打赏
0
0
0
0
1042
分享
相关文章
【姿态估计】实操记录:使用Dlib与mediapipe进行人脸姿态估计
【姿态估计】实操记录:使用Dlib与mediapipe进行人脸姿态估计
897 0
【python版CV】图像轮廓&模板匹配
【python版CV】图像轮廓&模板匹配
OpenCV对图像进行Otsu二值分割、Canny边缘检测、Harris角点检测实战(附源码)
OpenCV对图像进行Otsu二值分割、Canny边缘检测、Harris角点检测实战(附源码)
120 0
遮挡人脸问题 | 详细解读Attention-Based方法解决遮挡人脸识别问题(附论文下载)
遮挡人脸问题 | 详细解读Attention-Based方法解决遮挡人脸识别问题(附论文下载)
505 0
CV16 人脸检测:Haar级联
因为Haar级联是在机器学习AdaBoost、Boosting的基础上提出的,由于我还没有学过机器学习,所以这部分的内容日后再描述,我将根据自己的理解浅显地解释一下
278 0
CV之MobiLenet:基于openpose利用CMU/MobilenetV2算法实现对多人体姿态(2019湖人勒布朗詹姆斯扣篮)实时估计检测
CV之MobiLenet:基于openpose利用CMU/MobilenetV2算法实现对多人体姿态(2019湖人勒布朗詹姆斯扣篮)实时估计检测
CV之MobiLenet:基于openpose利用CMU/MobilenetV2算法实现对多人体姿态(2019湖人勒布朗詹姆斯扣篮)实时估计检测