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()

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-28 06:42:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-28 06:42:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-28 06:42:03       82 阅读
  4. Python语言-面向对象

    2024-04-28 06:42:03       91 阅读

热门阅读

  1. sql server 数据库的学习

    2024-04-28 06:42:03       30 阅读
  2. 漏洞端到端管理小总结

    2024-04-28 06:42:03       30 阅读
  3. FreeLearning 安全译文集翻译完毕

    2024-04-28 06:42:03       22 阅读
  4. 【SHADER】Shader实例学习1:UI noise halo

    2024-04-28 06:42:03       34 阅读
  5. 详解AI作画算法原理

    2024-04-28 06:42:03       33 阅读
  6. Stable Diffusion常用提示词(Prompt)

    2024-04-28 06:42:03       30 阅读