face-detection - 使用 open cv 进行人脸检测
问题描述
它使用 hog 作为默认模型。您也可以使用 cnn 以获得更好的准确性,但检测过程会很慢。
cascade_classifier = cv2.CascadeClassifier('haarcascades/haarcascade_eye.xml')
cap = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, 0)
detections = cascade_classifier.detectMultiScale(gray,scaleFactor=1.3,minNeighbors=5)
if(len(detections) > 0):
(x,y,w,h) = detections[0]
frame = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
# for (x,y,w,h) in detections:
# frame = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()```
解决方案
推荐阅读
- android - 尽管使用了我在 stackoverflow&android 开发人员上找到的所有解决方案,但 Android 服务仍被破坏
- next.js - JIT tailwindcss 在 bg-[] 中使用变量不渲染颜色
- javascript - Javascript数组函数参数传递
- python - 每行numpy数组的无穷范数
- python - 如何删除二维数组中低于0的值并使用python lambda map对剩余值进行平方
- javascript - 瓶颈似乎并没有实际限制请求?
- excel - 调试 VBA 只读取 Compile Error: Expected Function or variable。我不确定如何解决此错误
- java - GWT 使用多个 CssResources 初始化 ClientBundle
- mysql - 如何在 MySql 中将值更新为十进制?
- reactjs - 使用 React 和 Ionic 的意外 Typescript 非空断言运算符