#encoding=utf8
import sys
import dlib
import cv2
import os
current_path = os.getcwd()
img_path =current_path + '/faces/face1.jpg'
img = cv2.imread(img_path,cv2.IMREAD_COLOR) # 读取图片
detector = dlib.get_frontal_face_detector() #获取人脸
dets =detector(img,1) #使用detector进行人脸检测,dets为返回结果
print ('Number of faces detected:{}'.format(len(dets))) #打印识别到的人脸
for index,face in enumerate(dets):
print('face {}; left {}; top {}; right {}; bottom {}'.format(index,
face.left(),
face.top(),
face.right(),
face.bottom()))
# 在图片中标注人脸并显示
left = face.left()
top = face.top()
right = face.right()
bottom = face.bottom()
cv2.rectangle(img,
(left,top),
(right,bottom),
(0,255,0),
3)
cv2.imwrite('result.jpg',img)
model_path = current_path+'/models/mmod_human_face_detector.dat'
detector = dlib.cnn_face_detection_model_v1(model_path)
图像处理——人脸检测学习笔记
最新推荐文章于 2024-09-01 23:06:50 发布