資源簡介
判斷攝像頭中出現的人臉是否為某個人
代碼片段和文件信息
#判斷攝像頭中出現的人臉是否為某個人
import?face_recognition
import?cv2
video_capture?=?cv2.VideoCapture(0)
#?本地圖像
hhj_image?=?face_recognition.load_image_file(“C:/Users/hp/Pictures/zaixia.jpg“)
hhj_face_encoding?=?face_recognition.face_encodings(hhj_image)[0]
#
face_locations?=?[]
face_encodings?=?[]
face_names?=?[]
process_this_frame?=?True
while?True:
????#?讀取攝像頭畫面
????ret?frame?=?video_capture.read()
????#?改變攝像頭圖像的大小,圖像小,所做的計算就少
????small_frame?=?cv2.resize(frame?(0?0)?fx=0.25?fy=0.25)
????#?opencv的圖像是BGR格式的,而我們需要是的RGB格式的,因此需要進行一個轉換。
????rgb_small_frame?=?small_frame[:?:?::-1]
????#?Only?process?every?other?frame?of?video?to?save?time
????if?process_this_frame:
????????#?根據encoding來判斷是不是同一個人,是就輸出true,不是為flase
????????face_locations?=?face_recognition.face_loc
評論
共有 條評論