当前位置:网站首页>人脸检测几种方法
人脸检测几种方法
2022-07-17 00:17:00 【HySmiley】
一、opencv中的haar模型进行检测
import cv2
img=cv2.imread('../image/img.jpg')
img_gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
casc=cv2.CascadeClassifier("../model/haarcascade_frontalface_default.xml")
faces=casc.detectMultiScale(img,1.3,4)
face_num=0
for face in faces:
x=list(face)[0]
y=list(face)[1]
w=list(face)[2]
h=list(face)[3]
face_num+=1
# print(da,x,y,w,h)
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2,1)
print("face_num:",face_num)
cv2.imshow('img',img)
cv2.waitKey()scaleFactor 指定检测图像选择框的缩小比例。
minNeighbors 指定检测目标候选框达到多少应保留。

人脸数目: 33
运行时间: 1.4092044830322266
二、dlib检测
2.1 get_frontal_face_detector
import cv2
import dlib
detector=dlib.get_frontal_face_detector()
img=cv2.imread('../image/img.jpg')
b,g,r=cv2.split(img)
dets=detector(img,1)
# print(dets)
face_num=0
for i ,face in enumerate(dets):
pt1=(face.left(),face.top())
pt2=(face.right(),face.bottom())
face_num+=1
cv2.rectangle(img,pt1,pt2,(0,0,255),2)
print("face_num:",face_num)
cv2.imwrite('dlib_face.jpg',img)
cv2.imshow('img',img)
cv2.waitKey()
cv2.destroyAllWindows()

人脸数目: 34
运行时间: 0.8732187747955322
2.2 mmod_human_face_detector
import cv2
import dlib
cnn_detector=dlib.cnn_face_detection_model_v1("../model/mmod_human_face_detector.dat")
img=cv2.imread('../image/ab.jpg')
dets=cnn_detector(img,1)
print(dets)
for i ,data in enumerate(dets):
face=data.rect
pt1=(face.left(),face.top())
pt2=(face.right(),face.bottom())
cv2.rectangle(img,pt1,pt2,(0,0,255),2)
cv2.imshow('img',img)
cv2.waitKey()
cv2.destroyAllWindows()

人脸数目: 37
运行时间: 3.888331651687622
对比分析参考: 人脸检测学习笔记(数据集-DLIB人脸检测原理-DLIB&OpenCV人脸检测方法及对比) - dskit - 博客园
边栏推荐
猜你喜欢
随机推荐
Oracle查询时间段内所有日期
Redis' simple dynamic string SDS
Nat comprehensive experiment
【NoSQL】redis高可用和持久化
Analysis skills of time complexity and space complexity
High quality subroutine
HCIA_OSPF实验
4. Some thoughts on asynctool framework
Regular and extended expressions, sed text processor and awk tool, changing IP address with script
MySQL backup and recovery
Conditional statement of shell script
Rhce8 Study Guide Chapter 7 service management
RIP综合实验
BiSeNetV2-面部分割
Configure VLAN and use OSPF protocol for layer 3 switches
Shell script integer value comparison, logic test, if statement, extract performance monitoring indicators
Detailed explanation of dynamic compression and static compression of gzip
Understanding of array and bubbling
二进制安装kubernetes 1.23.2
MySQL日志管理和完全备份增量备份与恢复









