赞
踩
def take_photo(path): capture = cv2.VideoCapture(0) # 加载人脸特径数据 face_detector = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml') filename =1 flag_write = False while True: flag,frame = capture.read() if not flag: break gray = cv2.cvtColor(frame, code=cv2.COLOR_BGR2GRAY) faces = face_detector.detectMultiScale(gray, minNeighbors=5) for x,y,w,h in faces: if flag_write: face=gray[y:y+h,x:x+w] face = cv2.resize(face,dsize=(64,64)) cv2.imwrite('./faces_dymamic/%s/%d.jpg'%(path,filename),face) filename +=1 cv2.rectangle(frame,pt1=(x,y),pt2=(x+w,y+h),color=[0,255,0],thickness=2) if filename >10: break cv2.imshow('face',frame) key = cv2.waitKey(1000 // 24) if key == ord('q'): break if key == ord('w'): flag_write = True cv2.destroyAllWindows() capture.release()
if __name__ == '__main__': # #1、动态采集人脸 take_faces()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。