Python camera real-time face detection data collection

How to save face with camera?

For face recognition data collection based on opencv, I collect data for myself. Please refer to the code comments for details. The writing is very detailed. Press s to save the picture as test.jpg, and press q to exit the interface:

code show as below:

import cv2

cap = cv2.VideoCapture(0)  #摄像头开启,也可以传入mp4

# 相机的默认帧大小在Windows或Ubuntu中将为640x480

# cap.isOpened() 返回 true/false, 检查摄像头初始化是否成功
print(cap.isOpened())


while cap.isOpened():
    ret_flag, img_camera = cap.read()

    cv2.imshow("camera", img_camera)

    # 每帧数据延时 1ms, 延时为0, 读取的是静态帧
    k = cv2.waitKey(1)

    # 按下 's' 保存截图
    if k == ord('s'):
        cv2.imwrite("test.jpg", img_camera)

    # 按下 'q' 退出
    if k == ord('q'):
        break

# 释放所有摄像头
cap.release()

# 删除建立的所有窗口
cv2.destroyAllWindows()

Demonstration effect:
insert image description here

face registration

First of all, we are based on
the recognition model: Dlib-based ResNet pre-trained model dlib_face_recognition_resnet_model_v1.dat

Identification algorithm: ResNet neural network.

Face recognition needs to compare and analyze the extracted image data with the existing image data to determine whether it is the person, so here is mainly to do more convenient data collection.

How to use:

“n” 新录入人脸,新建文件夹 person_X/  用来存储某人的人脸图像
 "s" 开始捕获人脸,将捕获到的人脸放到 person_X/ 路径下
“q” 退出窗口

insert image description here
n After creating the folder, press s several times to collect your own face data:
insert image description here

Can realize the entry of multiple people, each person creates a folder separately.

Guess you like

Origin blog.csdn.net/weixin_46211269/article/details/122789942