图像处理——人脸检测学习笔记


#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)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值