import cv2

save_path = 'D:/YOURSPHOTOS/'
cv2.namedWindow("camera", 1)
# 开启ip摄像头
video = "http://admin:[email protected]:8081/"  # 此处@后的ipv4 地址需要改为app提供的地址
# 打开摄像头
cap = cv2.VideoCapture(video)
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
i = 0
while (True):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        # 成功框选则样本数增加
        i += 1
        cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roiImg = frame[y:y + h, x:x + w]
        gray = cv2.cvtColor(roiImg, cv2.COLOR_BGR2GRAY)
        cv2.imwrite(save_path + str(i) + '.jpg', gray)
    cv2.imshow("camera", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

python实现人脸识别并且将识别到的人脸保存到本地

相关文章:

  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-01-04
  • 2021-07-09
  • 2021-07-21
  • 2021-11-30
  • 2022-01-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-12-22
  • 2022-12-23
  • 2022-02-10
相关资源
相似解决方案