python摄像头人脸识别代码_python 实现摄像头人脸识别
1、window安裝dlib、face_recognition
ace_recognition簡介
face_recognition是Python的一個開源人臉識別庫,支持Python 3.3+和Python 2.7。引用官網介紹:
Recognize and manipulate faces from Python or from the command line with the world's simplest face recognition library.
安裝配置
我目前的開發環境是,操作系統:Win10,Python3.6:Anaconda集成開發環境。在安裝 face_recognition的過程中花費了一些時間,所以把安裝過程記錄下來。
使用pip安裝
pip install face_recognition
如果安裝失敗了,那基本上是因為依賴的dlib庫安裝失敗了,需要手動安裝。網上介紹的安裝dlib庫的方法大都很復雜,需要下載源代碼,然后手動編譯。
安裝dlib
1、下載
dlib-19.8.1-cp36-cp36m-win_amd64.whl
2、安裝
pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl
pip install dlib
pip show dlib #驗證dlib是否安裝成功
安裝face_recognition_models
1、下載 face_recognition_models 0.3.0
2、解壓壓縮包,進入face_recognition_models-0.3.0目錄,安裝
python setup.py install
pip show face_recognition_models
安裝face_recognition
1、下載 face_recognition 1.0.0
2、解壓壓縮包,進入face_recognition目錄,安裝
python setup.py install
pip show face_recognition
2、下載代碼
https://github.com/ageitgey/face_recognition.git
3、運行代碼
facerec_from_webcam.py
因為原有代碼僅對攝像頭進行讀取,修改以下文件可以讀取攝像頭文件
# video_capture = cv2.VideoCapture("hamilton_clip.mp4")
video_capture = cv2.VideoCapture("rtsp://192.168.1.11:444/subtype=1&subchannanel=1")
# video_capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
# Load a sample picture and learn how to recognize it.
obama_image = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
# Load a second sample picture and learn how to recognize it.
biden_image = face_recognition.load_image_file("biden.jpg")
biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
sungebingimage = face_recognition.load_image_file("sungebing.jpg")
sungebing_face_encoding = face_recognition.face_encodings(sungebingimage)[0]
ssjimage = face_recognition.load_image_file("ssj.jpg")
ssjimage_face_encoding = face_recognition.face_encodings(ssjimage)[0]
# Create arrays of known face encodings and their names
known_face_encodings = [
obama_face_encoding,
biden_face_encoding,
ssjimage_face_encoding,
sungebing_face_encoding
]
known_face_names = [
"Barack Obama",
"Joe Biden",
"sun shengjie",
"sungebing"
]
4、也可以在項目的最后將攝像頭讀取的視頻轉為視頻流輸出,通過web顯示。
總結
以上是生活随笔為你收集整理的python摄像头人脸识别代码_python 实现摄像头人脸识别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手游问道万圣节活动怎么做
- 下一篇: websocket python爬虫_p