欢迎光临本站

生辰八字网

您现在的位置是:首页>八字综合

八字综合

免费人脸识别测命运,人脸识别测温一体机

免费人脸识别测命运

项目语言:Python.

环境:win10 python3.8.6

免费人脸识别测命运,人脸识别测温一体机

python

下面一起来看下效果先:

首先采集人脸:
免费人脸识别测命运,人脸识别测温一体机
# 进行人脸录入 / Face registerimport dlibimport numpy as npimport cv2import osimport shutilimport time# Dlib 正向人脸 / Use frontal face detector of Dlibdetector = dlib.get_frontal_face_detector()class Face_Register: def __init__(self): self.path_photos_from_camera = “data/data_faces_from_camera/” self.font = cv2.FONT_ITALIC self.existing_faces_cnt = 0 # 已录入的人脸计数器 / cnt for counting saved faces self.ss_cnt = 0 # 录入 personX 人脸时图片计数器 / cnt for screen shots self.current_frame_faces_cnt = 0 # 录入人脸计数器 / cnt for counting faces in current frame self.save_flag = 1 # 之后用来控制是否保存图像的 flag / The flag to control if save self.press_n_flag = 0 # 之后用来检查是否先按 ‘n’ 再按 ‘s’ / The flag to check if press ‘n’ before ‘s’ # FPS self.frame_time = 0 self.frame_start_time = 0 self.fps = 0 # 新建保存人脸图像文件和数据CSV文件夹 / Make dir for sng photos and csv def pre_work_mkdir(self): # 新建文件夹 / Create folders to save faces images and csv if os.path.isdir(self.path_photos_from_camera): pass else: os.mkdir(self.path_photos_from_camera) # 之前存的人脸数据文件夹 / Delete the old data of faces def pre_work_del_old_face_folders(self): # 之前存的人脸数据文件夹, “/data_faces_from_camera/person_x/”… folders_rd = os.listdir(self.path_photos_from_camera) for i in range(len(folders_rd)): shutil.rmtree(self.path_photos_from_camera+folders_rd[i]) if os.path.isfile(“data/features_all.csv”): os.remove(“data/features_all.csv”) # 如果有之前录入的人脸, 在之前 person_x 的序号按照 person_x+1 开始录入 / Start from person_x+1 def check_existing_faces_cnt(self): if os.listdir(“data/data_faces_from_camera/”): # 获取已录入的最后一个人脸序号 / Get the order of latest person person_list = os.listdir(“data/data_faces_from_camera/”) person_num_list = [] for person in person_list: person_num_list.append(int(person.split(‘_’)[-1])) self.existing_faces_cnt = max(person_num_list) # 如果之一次存储或者没有之前录入的人脸, 按照 person_1 开始录入 / Start from person_1 else: self.existing_faces_cnt = 0 # 获取处理之后 stream 的帧数 / Update FPS of video stream def update_fps(self): now = time.time() self.frame_time = now – self.frame_start_time self.fps = 1.0 / self.frame_time self.frame_start_time = now # 生成的 cv2 window 上面添加说明文字 / PutText alt="免费人脸识别测命运,人脸识别测温一体机" src="https://www.9bazi.com/zb_users/upload/2022/05/20220517004514165271951459158.jpeg" width="100%" height="100%" />免费人脸识别测命运,人脸识别测温一体机

3.人脸信息写入CSV做数据保存对比

免费人脸识别测命运,人脸识别测温一体机

免费人脸识别测命运,人脸识别测温一体机
# 从人脸图像文件中提取人脸特征存入 “features_all.csv” / Extract features from images and save into “features_all.csv”import osimport dlibfrom skimage import ioimport csvimport numpy as np# 要读取人脸图像文件的路径 / Path of cropped facespath_images_from_camera = “data/data_faces_from_camera/”# Dlib 正向人脸 / Use frontal face detector of Dlibdetector = dlib.get_frontal_face_detector()# Dlib 人脸 landmark 特征点 / Get face landmarkspredictor = dlib.shape_predictor(‘data/data_dlib/shape_predictor_68_face_landmarks.dat’)# Dlib Resnet 人脸识别模型,提取 128D 的特征矢量 / Use Dlib resnet50 model to get 128D face descriptorface_reco_model = dlib.face_recognition_model_v1(“data/data_dlib/dlib_face_recognition_resnet_model_v1.dat”)# 返回单张图像的 128D 特征 / Return 128D features for single image# Input: path_img class ‘str’# Output: face_descriptor class ‘dlib.vector’def return_128d_features(path_img): img_rd = io.imread(path_img) faces = detector(img_rd, 1) print(“%-40s %-20s” % (“检测到人脸的图像 / Image with faces detected:”, path_img), ‘\n’) # 因为有可能截下来的人脸再去检测,检测不出来人脸了, 所以要确保是 检测到人脸的人脸图像拿去算特征 # For photos of faces saved, we need to make sure that we can detect faces from the cropped images if len(faces) != 0: shape = predictor(img_rd, faces[0]) face_descriptor = face_reco_model.compute_face_descriptor(img_rd, shape) else: face_descriptor = 0 print(“no face”) return face_descriptor# 返回 personX 的 128D 特征均值 / Return the mean value of 128D face descriptor for person X# Input: path_faces_personX class ‘str’# Output: features_mean_personX class ‘numpy.ndarray’def return_features_mean_personX(path_faces_personX): features_list_personX = [] photos_list = os.listdir(path_faces_personX) if photos_list: for i in range(len(photos_list)): # 调用 return_128d_features() 得到 128D 特征 / Get 128D features for single image of personX print(“%-40s %-20s” % (“正在读的人脸图像 / Reading image:”, path_faces_personX + “/” + photos_list[i])) features_128d = return_128d_features(path_faces_personX + “/” + photos_list[i]) # 遇到没有检测出人脸的图片跳过 / Jump if no face detected from image if features_128d == 0: i += 1 else: features_list_personX.append(features_128d) else: print(“文件夹内图像文件为空 / Warning: No images in ” + path_faces_personX + ‘/’, ‘\n’) # 计算 128D 特征的均值 / Compute the mean # personX 的 N 张图像 x 128D – 1 x 128D if features_list_personX: features_mean_personX = np.array(features_list_personX).mean(axis=0) else: features_mean_personX = np.zeros(128, dtype=int, order=’C’) print(type(features_mean_personX)) return features_mean_personX# 获取已录入的最后一个人脸序号 / Get the order of latest personperson_list = os.listdir(“data/data_faces_from_camera/”)person_num_list = []for person in person_list: person_num_list.append(int(person.split(‘_’)[-1]))person_cnt = max(person_num_list)with open(“data/features_all.csv”, “w”, newline=””) as csvfile: writer = csv.writer(csvfile) for person in range(person_cnt): # Get the mean/average features of face/personX, it will be a list with a length of 128D print(path_images_from_camera + “person_” + str(person + 1)) features_mean_personX = return_features_mean_personX(path_images_from_camera + “person_” + str(person + 1)) writer.writerow(features_mean_personX) print(“特征均值 / The mean of features:”, list(features_mean_personX)) print(‘\n’) print(“所有录入人脸数据存入 / Save all the features of faces registered into: data/features_all.csv”)

4.做人脸识别:

免费人脸识别测命运,人脸识别测温一体机
# 利用 OT 对于单张人脸追踪, 实时人脸识别 / Real-time face detection and recognition via OT for single faceimport dlibimport numpy as npimport cv2import osimport pandas as pdimport time# Dlib 正向人脸 / Use frontal face detector of Dlibdetector = dlib.get_frontal_face_detector()# Dlib 人脸 landmark 特征点 / Get face landmarkspredictor = dlib.shape_predictor(‘data/data_dlib/shape_predictor_68_face_landmarks.dat’)# Dlib Resnet 人脸识别模型,提取 128D 的特征矢量 / Use Dlib resnet50 model to get 128D face descriptorface_reco_model = dlib.face_recognition_model_v1(“data/data_dlib/dlib_face_recognition_resnet_model_v1.dat”)class Face_Recognizer: def __init__(self): self.font = cv2.FONT_ITALIC # For FPS self.frame_time = 0 self.frame_start_time = 0 self.fps = 0 # cnt for frame self.frame_cnt = 0 # 用来存储所有录入人脸特征的数组 / Save the features of faces in the database self.features_known_list = [] # 用来存储录入人脸名字 / Save the name of faces in the database self.name_known_list = [] # 用来存储上一帧和当前帧 ROI 的质心坐标 / List to save centroid positions of ROI in frame N-1 and N self.last_frame_centroid_list = [] self.current_frame_centroid_list = [] # 用来存储上一帧和当前帧检测出目标的名字 / List to save names of objects in frame N-1 and N self.last_frame_names_list = [] self.current_frame_face_names_list = [] # 上一帧和当前帧中人脸数的计数器 / cnt for faces in frame N-1 and N self.last_frame_faces_cnt = 0 self.current_frame_face_cnt = 0 # 用来存放进行识别时候对欧氏距离 / Save the e-distance for faceX when recognizing self.current_frame_face_X_e_distance_list = [] # 存储当前头中捕获到的所有人脸的坐标名字 / Save the positions and names of current faces captured self.current_frame_face_position_list = [] # 存储当前头中捕获到的人脸特征 / Save the features of people in current frame self.current_frame_face_features_list = [] # 从 “features_all.csv” 读取录入人脸特征 / Get known faces from “features_all.csv” def get_face_database(self): if os.path.exists(“data/features_all.csv”): path_features_known_csv = “data/features_all.csv” csv_rd = pd.read_csv(path_features_known_csv, header=None) for i in range(csv_rd.shape[0]): features_someone_arr = [] for j in range(0, 128): if csv_rd.iloc[i][j] == ”: features_someone_arr.append(‘0’) else: features_someone_arr.append(csv_rd.iloc[i][j]) self.features_known_list.append(features_someone_arr) self.name_known_list.append(“Person_” + str(i + 1)) print(“Faces in Database:”, len(self.features_known_list)) return 1 else: print(‘##### Warning #####’, ‘\n’) print(“‘features_all.csv’ not found!”) print( “Please run ‘get_faces_from_camera.py’ and ‘features_extraction_to_csv.py’ before ‘face_reco_from_camera.py'”, ‘\n’) print(‘##### End Warning #####’) return 0 # 计算两个128D向量间的欧式距离 / Compute the e-distance between two 128D features # 更新 FPS / Update FPS of Video stream def update_fps(self): now = time.time() self.frame_time = now – self.frame_start_time self.fps = 1.0 / self.frame_time self.frame_start_time = now # 计算两个128D向量间的欧式距离 / Compute the e-distance between two 128D features @staticmethod def return_euclidean_distance(feature_1, feature_2): feature_1 = np.array(feature_1) feature_2 = np.array(feature_2) dist = np.sqrt(np.sum(np.square(feature_1 – feature_2))) return dist # 生成的 cv2 window 上面添加说明文字 / putText alt="免费人脸识别测命运,人脸识别测温一体机" src="https://www.9bazi.com/zb_users/upload/2022/05/20220517004516165271951654343.jpeg" width="100%" height="100%" />免费人脸识别测命运,人脸识别测温一体机

私信回复:人脸识别源码

获取项目源代码

以上就是与免费人脸识别测命运相关内容,是关于人脸识别的分享。看完人脸识别测温一体机后,希望这对大家有所帮助!