日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python调用摄像头人脸识别代码_利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别...

發布時間:2023/12/10 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python调用摄像头人脸识别代码_利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用已經搭建好 face_recognition,dlib 環境來進行人臉識別

未搭建好環境請參考:

使用opencv 調用攝像頭

import face_recognition

import cv2

video_capture = cv2.videocapture(0)

# videocapture打開攝像頭,0為筆記本內置攝像頭,1為外usb攝像頭,或寫入視頻路徑

mayun_img = face_recognition.load_image_file("mayun.jpg")

jobs_img = face_recognition.load_image_file("jobs.jpg")

mayun_face_encoding = face_recognition.face_encodings(mayun_img)[0]

jobs_face_encoding = face_recognition.face_encodings(jobs_img)[0]

face_locations = []

face_encodings = []

face_names = []

process_this_frame = true

while true:

ret, frame = video_capture.read()

# video_capture.read()按幀讀取視頻,ret,frame是獲video_capture.read()方法的兩個返回值。

# 其中ret是布爾值,如果讀取幀是正確的則返回true,

# 如果文件讀取到結尾,它的返回值就為false。frame就是每一幀的圖像,是個三維矩陣。

small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

# 對截取到的圖像進行處理

if process_this_frame:

face_locations = face_recognition.face_locations(small_frame)

face_encodings = face_recognition.face_encodings(small_frame, face_locations)

face_names = []

for face_encoding in face_encodings:

match = face_recognition.compare_faces([mayun_face_encoding, jobs_face_encoding], face_encoding)

if match[0]:

name = "mayun"

elif match[1]:

name = "jobs"

else:

name = "unknown"

print(name)

face_names.append(name)

process_this_frame = not process_this_frame

for (top, right, bottom, left), name in zip(face_locations, face_names):

top *= 4

right *= 4

bottom *= 4

left *= 4

cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), 2)

font = cv2.font_hershey_duplex

cv2.puttext(frame, name, (left+6, bottom-6), font, 1.0, (255, 255, 255), 1)

cv2.imshow('video', frame)

if cv2.waitkey(1) & 0xff == ord('q'):

break

video_capture.release()

cv2.destroyallwindows()

我使用手機中的照片來進行驗證

因為是按每一幀進行讀取:

有些人在使用時會出現攝像頭打不開的情況

我使用的是win10系統給出一個建議:

在設置中找到隱私設置,在找到相機選項,把權限打開即可

希望與廣大網友互動??

點此進行留言吧!

總結

以上是生活随笔為你收集整理的python调用摄像头人脸识别代码_利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。