face _ features=['下巴 , ' left_eybrow ' , ' right_eybrow ' , ' fore_bridge ' , ' fore_tip ' , '左眼', '右眼 , '顶唇','下唇]video _ capture=cv2 。 视频捕获(0)标签="flase"num=0 .尝试:操作系统.MKDIR("IMG /"标签)除了:经过虽然是真的:RET , Frame=Video _ capture 。 read()face _ locations=face _ recognition 。 面部_位置(帧)face _ landmarks _ list=face _ recognition 。 脸_地标(帧)用于面部_位置中的face_location:顶部 , 右侧 , 底部 , 左=面_位置如果len(face _ list marks _ list)==1:num=1 face _ image=帧[上:下 , 左:右] cv2.imwrite("img /"标签"/" str(num) "jpg " , face_image)
打印(“保存”+ str(num)+“张红脸”) cv2.imshow(“test” , face_image) cv2.waitkey(1) 别的: 打印(“无法检测到面部 , 或者面孔的数量不仅是一个 , 请确保只有一张脸”) 如果num == 1000: 休息 cv2.destroyallwindows()3.2 KNN面部分类
KNN分类面孔 , 首先通过计算各面部编码之间的距离来横穿训练浓度的每个面部样本 , 以判断它是否是正样本 。 总程序结构如下所示 , 即面部_Record记录面部面部 , Face_Recognition_KNN列车人员面部和监视器 , 测试是检测例外的脚本 , 它已被打包到EXE文件中 。 代码如下所示:
def火车(train_dir , model_save_path = none , n_neighbors = none , knn_algo ='ball_tree' , verbose = false): x = [] Y = [] 对于OS.Listdir(Train_Dir)的Class_Dir: 如果不是os.path.isdir(os.path.join(train_dir , class_dir): 继续 对于image_files_in_folder(os.path.join(train_dir , clas_dir)中的img_path: image = face_recognition.load_image_file(img_path) face_bounding_boxes = face_recognition.face_locations(图像) 如果len(face_bounding_boxes)! = 1: 如果verbose: 打印(“image {}不适合培训:{}” 。 格式(img_path , 如果len , “没有找到脸” face_bounding_boxes) <1 else "Found More Than Ooney))) Else: X.Append (Face_Recognition.face_encodings (image, known_face_locations = face_bounding_boxes) [0]) Y.Append (class_dir) IF n_neighbors is none: n_neighbors = int (round (math.sqrt (len (x)))))) IF Verbose: Print ("Chose N_Neighbors Automatically:", N_Neighbors) KNN_CLF = neighbors.kneighborsclassifier (n_neighbors = n_neighbors, algorithm = KNN_ALGO, Weights = 'distance') KNN_CLF.FIT (X, Y) If MODEL_SAVE_PATH IS Not None: WITH OPEN (Model_save_path, 'wb') AS F: Pickle.dump (KNN_CLF, F) Return KNN_CLFDEF PREDICT (X_IMG_PATH, KNN_CLF = none, model_path = none, distance_threshold = 0.5): IF knn_clf is none and model_path is none: Raise Exception ("Must Supply Knn Classifier Either THOURH KNN_CLF or MODEL_PATH") IF KNN_CLF IS NONE: WITH OPEN (Model_path, 'RB') AS F: KNN_CLF = Pickle.Load (f) X_IMG = X_IMG_PATH X_FACE_LOCATIONS = Face_Recognition.face_locations (x_img) IF LEN (X_FACE_LOCATIONS) == 0: Return [] Faces_encodings = face_recognition.face_encodings (x_img, known_face_locations = x_face_locations) Closest_Distances = knn_clf.kneighbors (faces_encodings, n_neighbors = 1) Are_matches = [closest_distances [0] [i] [0] <= distance_threshold for i in inheng (len (x_face_locations)]]] RETURN [(PRED, LOC) IF Rec Else ("Unknown", LOC) for PRED, LOC, REC IN ZIP (KNN_CLF.PREDICT (Faces_Encodings), X_FACE_LOCATIONS, Are_MATCHES]]3.3 Executive Face Behavior
In order to prevent the abnormal face continuous operation, the computer card is caused, and a GUI button is required to ensure that only the OK button will continue to monitor only. The following code includes the definition of the GUI interface, which is mainly only one button function, buttons click to let the abnormal program return to normal, but never affect the face detection program. That is, the program and face classification are not interfered with each other. code show as below:
DEF GET_WINDOW_POSITON (Width, Height): Window_x_position = (Window.winfo_Screenwidth () - width) // 2 WINDOW_Y_POSITION = (Window.winfo_ScreenHHEENT () - Height) // 2 Return window_x_position, window_y_positionPOS = GET_WINDOW_POSITON (TK_WIDTH, TK_HEIGHT) Window.Geometry (f '+ {POS [0]} + {POS [1]}')DEF CloseWindow (): Messagebox.showinfo (title = "Warning", Message = "Please click OK") ReturnDEF T (): TRY: Os.Remove ("ok.txt") Except: PASS Window.destroy ()WINDOW.PROTOCOL ("WM_DELETE_WINDOW", Closewindow)BNT = Button (Window, Text = "OK", width = 15, Height = 2, Command = T)BNT.PACK ()Window.mainloop ()IF TEMP> num: 如果OS.Path.exists(“OK.TXT”): 经过 别的: T2 =线程.Thread(目标= Test2) t2.start() OS.System(“1.jpg”) f =打开(“ok.txt” , “w”) F.Close() t1 =线程.Thread(目标= test1) t1.start() 对于预测中的名称 , (顶部 , 右 , 左下角): draw.rectangle((左 , 顶部) , (右 , 底部) , 大纲=(0,0,255)) text_width , text_height = draw.textsize(name) draw.rectangle((左 , 底部 - text_height - 10) , (右下) , 填充=(0,0,255) , 大纲=(0,0,255)) draw.text((int +右)/ 2) , 底部 - text_height - 10) , 名称 , font = myfont , fill =(0,0,0)) 德德尔绘画 pil_image = np.array(pil_image) temp = num.别的: pil_image = img_path.def test2(): os.system('1.caj')def test1(): OS.System('test.exe')
- lol比赛直播官网 lols6总决赛直播平台
- 刺客信条1教程怎么过 刺客信条1叫什么
- 货货到付款的购物网站 货到付款购物网站
- 诗人是如何写诗的,他们为什么会有灵感?
- 问道租号平台 问道号
- 1688阿里巴巴批发平台 1688阿里巴巴批发网怎么样
- 买号卖号交易平台 我要卖号交易平台
- 京东卖家平台 京东后台
- 忆幼子杜甫原文及翻译 忆幼子杜甫翻译
- 直播行业会越来越正规 薇娅多个平台账号被封
特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
