- 阅读权限
- 255
- 威望
- 1 级
- 论坛币
- 49407 个
- 通用积分
- 51.8704
- 学术水平
- 370 点
- 热心指数
- 273 点
- 信用等级
- 335 点
- 经验
- 57815 点
- 帖子
- 4006
- 精华
- 21
- 在线时间
- 582 小时
- 注册时间
- 2005-5-8
- 最后登录
- 2023-11-26
|
- import cv2
- import numpy as np
- face_cascade = cv2.CascadeClassifier('cascade_files/haarcascade_frontalface_alt.xml')
- if face_cascade.empty():
- raise IOError('Unable to load the face cascade classifier xml file')
- cap = cv2.VideoCapture(0)
- scaling_factor = 0.5
- while True:
- ret, frame = cap.read()
- frame = cv2.resize(frame, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA)
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- face_rects = face_cascade.detectMultiScale(gray, 1.3, 5)
- for (x,y,w,h) in face_rects:
- cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3)
- cv2.imshow('Face Detector', frame)
- c = cv2.waitKey(1)
- if c == 27:
- break
- cap.release()
- cv2.destroyAllWindows()
复制代码
|
|