当前位置:   article > 正文

opencv 采样照片

opencv 采样照片
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()
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/545363
推荐阅读
相关标签
  

闽ICP备14008679号