熱門測算
八字精批 紫微鬥數 八字合婚 終生運勢

免費人臉識別測命運,人臉識別測溫一體機

解夢佬

免費人臉識別測命運

項目語言: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.jiemenglao.com/suanming/zb_users/upload/2023/12/20231210221156170221751685720.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.jiemenglao.com/suanming/zb_users/upload/2023/12/20231210221157170221751731808.jpeg" width="100%" height="100%" />免費人臉識別測命運,人臉識別測溫一體機

私信回復:人臉識別源碼

獲取項目源代碼

以上就是與免費人臉識別測命運相關內容,是關于人臉識別的分享。看完人臉識別測溫一體機后,希望這對大家有所幫助!

本文來自:解夢佬,原地址:https://www.jiemenglao.com/suanming/414458.html