下载了opencv之后,运用代码,报错找不到分类器
import cv2
def facedetect(windowname,camera_id):
#命名和打开摄像头
cv2.namedWindow(windowname) # 创建一个已windowname为名字的窗口
cap=cv2.VideoCapture(camera_id) # camera_id为设备摄像头的id,默认是0,如果有usb摄像头可能会变为1
# Face Detection using Haar Cascades http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_objdetect/py_face_detection/py_face_detection.html?highlight=cascadeclassifier
classfier=cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml') #
color=(0,225,0)#人脸框的颜色,采用rgb模型,这里表示g取255,为绿色框
while cap.isOpened():
ok,frame=cap.read() # 读取一帧数据,ok表示摄像头读取状态,frame表示摄像头读取的图像矩阵mat类型
if not ok:
break
# 灰度化在后面检测时可以降低计算量,cvtColor changing colorspace
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)#图像灰度化,cv2.cvtColor(input_image, flag) where flag determines the type of conversion.
# detectMultiScale完成人脸探测工作,returns the positions of detected faces as Rect(x,y,w,h),x、y是左上角起始坐标,h、w

最低0.47元/天 解锁文章
9万+





