from concurrent.futures import ThreadPoolExecutor
import face_recognition
import cv2
import time
from Idkit import IdWorker
save_path = "D:\\xcx\\"
flag = 1

def compareFaces(encodings1, encodings2):
    # matches = face_recognition.compare_faces(known_encodings, face_encoding, tolerance=0.5)
    print(1)

def saveFace(rgb_frame):
    global flag, save_path
    face_locations = face_recognition.face_locations(rgb_frame)  # 获得所有人脸位置
    face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)  # 获得人脸特征值
    face_names = []  # 存储出现在画面中人脸的名字
    for face_encoding in face_encodings:
        # name = known_names[first_match_index]
        print("22") 
        cv2.imwrite(save_path + IdWorker.get_id() + '.jpg', rgb_frame)
    flag = 1

def face(path):
    # 打开摄像头,0表示内置摄像头
    video_capture = cv2.VideoCapture(0)
    cap = cv2.VideoCapture("rtsp://admin:passwd@192.168.1.79:554//Streaming/Channels/1")
    cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
    pool = ThreadPoolExecutor(10)
    global flag
    frameNum = 0
    while True:
        ret, frame = cap.read()
        # cv2.imshow('frame', frame)
        frameNum = frameNum + 1
        if frameNum % 18 != 0:
            print(frameNum)
            continue
        else:
            print(frameNum)
            frameNum = 0
            print(time.time())
            if flag == 1:
                flag = 0
                pool.submit(saveFace, frame)
            else:
                print(1)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    video_capture.release()
    cv2.destroyAllWindows()


if __name__ == '__main__':
    face("./images/")  # 存放已知图像路径

 

最后修改于 2021-02-25 17:29:44
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇