資源簡介
壓縮包中含有【人眼識別+眨眼識別】源代碼以及詳細使用教程,利用pyrhon+opencv在ubuntu上運行,實現實時的檢測,windows環境的配置需要自己在網上找相關教程,注意,壓縮包中缺少的imutils庫需另外從我的資源中下載,謝謝大家
代碼片段和文件信息
#?Command?line?parameters
#?python?Wink.py?--shape-predictor?shape_predictor_68_face_landmarks.dat?--video?your?videoname.mp4
#?python?Wink.py?--shape-predictor?shape_predictor_68_face_landmarks.dat
#?import?the?necessary?packages
from?scipy.spatial?import?distance?as?dist
from?imutils.video?import?FileVideoStream
from?imutils.video?import?VideoStream
from?imutils?import?face_utils
import?numpy?as?np
import?argparse
import?imutils
import?time
import?dlib
import?cv2
def?eye_aspect_ratio(eye):
#?compute?the?euclidean?distances?between?the?two?sets?of
#?vertical?eye?landmarks?(x?y)-coordinates
A?=?dist.euclidean(eye[1]?eye[5])
B?=?dist.euclidean(eye[2]?eye[4])
#?compute?the?euclidean?distance?between?the?horizontal
#?eye?landmark?(x?y)-coordinates
C?=?dist.euclidean(eye[0]?eye[3])
#?compute?the?eye?aspect?ratio
ear?=?(A?+?B)?/?(2.0?*?C)
#?return?the?eye?aspect?ratio
return?ear
?
#?construct?the?argument?parse?and?parse?the?arguments
ap?=?argparse.ArgumentParser()
ap.add_argument(“-p“?“--shape-predictor“?required=True
help=“path?to?facial?landmark?predictor“)
ap.add_argument(“-v“?“--video“?type=str?default=““
help=“path?to?input?video?file“)
args?=?vars(ap.parse_args())
?
#?define?two?constants?one?for?the?eye?aspect?ratio?to?indicate
#?blink?and?then?a?second?constant?for?the?number?of?consecutive
#?frames?the?eye?must?be?below?the?threshold
EYE_AR_THRESH?=?0.25
EYE_AR_CONSEC_frameS?=?2
#?initialize?the?frame?counters?and?the?total?number?of?blinks
COUNTER?=?0
TOTAL?=?0
#?initialize?dlib‘s?face?detector?(HOG-based)?and?then?create
#?the?facial?landmark?predictor
print(“[INFO]?loading?facial?landmark?predictor...“)
detector?=?dlib.get_frontal_face_detector()
predictor?=?dlib.shape_predictor(args[“shape_predictor“])
#?grab?the?indexes?of?the?facial?landmarks?for?the?left?and
#?right?eye?respectively
(lStart?lEnd)?=?face_utils.FACIAL_LANDMARKS_IDXS[“left_eye“]
(rStart?rEnd)?=?face_utils.FACIAL_LANDMARKS_IDXS[“right_eye“]
#?start?the?video?stream?thread
print(“[INFO]?starting?video?stream?thread...“)
#vs?=?FileVideoStream(args[“video“]).start()
fileStream?=?True
vs?=?VideoStream(src=0).start()
fileStream?=?False
time.sleep(1.0)
#?loop?over?frames?from?the?video?stream
while?True:
#?if?this?is?a?file?video?stream?then?we?need?to?check?if
#?there?any?more?frames?left?in?the?buffer?to?process
if?fileStream?and?not?vs.more():
break
#?grab?the?frame?from?the?threaded?video?file?stream?resize
#?it?and?convert?it?to?grayscale
#?channels)
frame?=?vs.read()
frame?=?imutils.resize(frame?width=450)
gray?=?cv2.cvtColor(frame?cv2.COLOR_BGR2GRAY)
#?detect?faces?in?the?grayscale?frame
rects?=?detector(gray?0)
#?loop?over?the?face?detections
for?rect?in?rects:
#?determine?the?facial?landmarks?for?the?face?region?then
#?convert?the?facial?landmark?(x?y)-coordinates?to?a?NumPy
#?array
shape?=?predictor(gray
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???99693937??2017-03-03?03:40??shape_predictor_68_face_landmarks.dat
?????文件???????4862??2017-11-12?10:14??Wink.py
?????文件?????118229??2017-11-12?10:46??教程.docx
-----------?---------??----------?-----??----
?????????????99817028????????????????????3
- 上一篇:Python從入門到項目實踐全彩版
- 下一篇:python項目開發案例集錦.zip
評論
共有 條評論