python opencv人脸检测提取及保存方法
注意这里提取到的人脸图片的保存地址要改成自己要保存的地址
opencv人脸的检测模型的路径也要更改为自己安装的opencv的人脸检测模型的路径
import cv2 save_path = 'F:\\face_photo_save\\chenym\\' cascade = cv2.CascadeClassifier("D:\\opencv249\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml") cap = cv2.VideoCapture(0) i = 0 while True: ret,frame = cap.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) rect = cascade.detectMultiScale(gray,scaleFactor=1.3,minNeighbors=9,minSize=(50,50),flags = cv2.cv.CV_HAAR_SCALE_IMAGE) print "rect",rect if not rect is (): for x,y,z,w in rect: roiImg = frame[y:y+w,x:x+z] cv2.imwrite(save_path+str(i)+'.jpg',roiImg) cv2.rectangle(frame,(x,y),(x+z,y+w),(0,0,255),2) i +=1 cv2.imshow('frame',frame) if cv2.waitKey(1) &0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
相关推荐
mapaler 2020-06-21
MIKUScallion 2020-06-11
wallowyou 2020-03-05
Samlss 2020-02-22
linmufeng 2020-02-18
luvhl 2020-01-10
LodbkMi 2019-04-24
Dickzeng 2019-07-01
Irelia 2019-07-01
laxexue 2019-06-30
飞翔的鱼 2019-06-30
我的iOS王者之路 2019-06-28
yixiaof 2019-06-28
zsh 2018-07-02
yaosir 2019-06-28
xiaocaibai 2016-03-31
bertZuo 2019-06-27