操作系统寒武纪 - 会让企业IT高兴吗?
846
2022-11-21
【机器学习】opencv-摄像头中的人脸采集
本次在视频识别的程度上增添了摄像头实时识别,
区别在于:
# v = cv2.VideoCapture('./dzd2.mp4')v = cv2.VideoCapture(0)
import numpy as npimport cv2face_detector = cv2.CascadeClassifier('./haarcascade_frontalface_alt2.xml')# v = cv2.VideoCapture('./dzd2.mp4')v = cv2.VideoCapture(0)# win = cv2.namedWindow('dzd',cv2.WINDOW_NORMAL)#视频时由一张行图片组成,每一张图片,帧num = 1while True: flag,frame= v.read() if not flag: break frame = cv2.resize(frame,(640,360)) gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) face_zones = face_detector.detectMultiScale(gray,scaleFactor=1.1,# minNeighbors=3,# minSize =(60,60),# maxSize =(110,110) )# print(face_zones) for x,y,w,h in face_zones[:1]: cv2.rectangle(frame,pt1=(x,y),pt2=(x+w,y+h),color= [0,0,255],thickness=2,)# cv2.circle(frame,center=(x+w//2,y+h//2),radius=w//2,color= [0,0,255],thickness=2,) cv2.imshow('dzd',frame)# if len(face_zones)>=1:# f = input('是否保存这张图片?Y/N').lower()# if f == 'y':# face = frame[y:y+h,x:x+w]# cv2.imwrite('./faces/liu/%d.jpg'%(num),face)# num+=1 key =cv2.waitKey(41) if key == ord('y'): face = frame[y+2:y+h-2,x+2:x+w-2] cv2.resize(face,(64,64)) cv2.imwrite('./faces/liuwang/%d.jpg'%(num),face) num+=1 elif key == ord('q'): break v.release()#释放视频流cv2.destroyAllWindows()
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~