資源簡介
壓縮包中含有【人眼識別+眨眼識別】源代碼以及詳細使用教程,利用pyrhon+opencv在ubuntu上運行,實現實時的檢測,windows環境的配置需要自己在網上找相關教程。。之前上傳的資源缺少一個自帶的庫
代碼片段和文件信息
#?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
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????.......??????2343??2017-05-01?03:41??imutils-master\.gitignore
?????文件???????2858??2017-05-01?03:41??imutils-master\bin\range-detector
????.......???????896??2017-05-01?03:41??imutils-master\demos\encode_image.py
????.......???????531??2017-05-01?03:41??imutils-master\demos\feature_demo.py
????.......???????466??2017-05-01?03:41??imutils-master\demos\finding_function_names.py
????.......??????2426??2017-05-01?03:41??imutils-master\demos\fps_demo.py
????.......??????2621??2017-05-01?03:41??imutils-master\demos\image_basics.py
????.......???????351??2017-05-01?03:41??imutils-master\demos\image_paths.py
????.......???????490??2017-05-01?03:41??imutils-master\demos\opencv_versions.py
????.......???????908??2017-05-01?03:41??imutils-master\demos\perspective_transform.py
????.......??????2980??2017-05-01?03:41??imutils-master\demos\picamera_fps_demo.py
????.......??????1567??2017-05-01?03:41??imutils-master\demos\sorting_contours.py
????.......???????758??2017-05-01?03:41??imutils-master\demos\temp_file.py
????.......?????40682??2017-05-01?03:41??imutils-master\demo_images\bridge.jpg
????.......?????29151??2017-05-01?03:41??imutils-master\demo_images\cactus.jpg
????.......????304438??2017-05-01?03:41??imutils-master\demo_images\notecard.png
????.......?????12956??2017-05-01?03:41??imutils-master\demo_images\pyimagesearch_logo.jpg
????.......??????9041??2017-05-01?03:41??imutils-master\demo_images\shapes.png
????.......?????33723??2017-05-01?03:41??imutils-master\demo_images\workspace.jpg
????.......????552360??2017-05-01?03:41??imutils-master\docs\images\auto_canny.png
????.......????922504??2017-05-01?03:41??imutils-master\docs\images\matplotlib.png
????.......???1818052??2017-05-01?03:41??imutils-master\docs\images\perspective_transform.png
????.......????549234??2017-05-01?03:41??imutils-master\docs\images\resizing.png
????.......???1221658??2017-05-01?03:41??imutils-master\docs\images\rotation.png
????.......????323931??2017-05-01?03:41??imutils-master\docs\images\skeletonization.png
????.......????471807??2017-05-01?03:41??imutils-master\docs\images\sorting_contours.png
????.......????659289??2017-05-01?03:41??imutils-master\docs\images\translation.png
????.......???????641??2017-05-01?03:41??imutils-master\docs\images\translation_eq.png
????.......????497647??2017-05-01?03:41??imutils-master\docs\images\url_to_image.png
????.......??????1504??2017-05-01?03:41??imutils-master\imutils\contours.py
............此處省略45個文件信息
評論
共有 條評論