speedup and improve face recognition; stable slow mode fps
This commit is contained in:
parent
d9e72c74dc
commit
0c384baef2
1 changed files with 12 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
#! /usr/bin/python3
|
||||||
# Show a windows with the video stream and testing information
|
# Show a windows with the video stream and testing information
|
||||||
|
|
||||||
# Import required modules
|
# Import required modules
|
||||||
|
|
@ -59,6 +60,8 @@ if use_cnn:
|
||||||
else:
|
else:
|
||||||
face_detector = dlib.get_frontal_face_detector()
|
face_detector = dlib.get_frontal_face_detector()
|
||||||
|
|
||||||
|
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
|
||||||
|
|
||||||
# Open the window and attach a a mouse listener
|
# Open the window and attach a a mouse listener
|
||||||
cv2.namedWindow("Howdy Test")
|
cv2.namedWindow("Howdy Test")
|
||||||
cv2.setMouseCallback("Howdy Test", mouse)
|
cv2.setMouseCallback("Howdy Test", mouse)
|
||||||
|
|
@ -79,22 +82,26 @@ rec_tm = 0
|
||||||
# Wrap everything in an keyboard interupt handler
|
# Wrap everything in an keyboard interupt handler
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
frame_tm = time.time()
|
||||||
|
|
||||||
# Increment the frames
|
# Increment the frames
|
||||||
total_frames += 1
|
total_frames += 1
|
||||||
sec_frames += 1
|
sec_frames += 1
|
||||||
|
|
||||||
# Id we've entered a new second
|
# Id we've entered a new second
|
||||||
if sec != int(time.time()):
|
if sec != int(frame_tm):
|
||||||
# Set the last seconds FPS
|
# Set the last seconds FPS
|
||||||
fps = sec_frames
|
fps = sec_frames
|
||||||
|
|
||||||
# Set the new second and reset the counter
|
# Set the new second and reset the counter
|
||||||
sec = int(time.time())
|
sec = int(frame_tm)
|
||||||
sec_frames = 0
|
sec_frames = 0
|
||||||
|
|
||||||
|
|
||||||
# Grab a single frame of video
|
# Grab a single frame of video
|
||||||
ret, frame = video_capture.read()
|
ret, frame = video_capture.read()
|
||||||
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||||
|
frame = clahe.apply(frame)
|
||||||
# Make a frame to put overlays in
|
# Make a frame to put overlays in
|
||||||
overlay = frame.copy()
|
overlay = frame.copy()
|
||||||
|
|
||||||
|
|
@ -174,9 +181,11 @@ try:
|
||||||
if cv2.waitKey(1) != -1:
|
if cv2.waitKey(1) != -1:
|
||||||
raise KeyboardInterrupt()
|
raise KeyboardInterrupt()
|
||||||
|
|
||||||
|
frame_time = time.time() - frame_tm
|
||||||
|
|
||||||
# Delay the frame if slowmode is on
|
# Delay the frame if slowmode is on
|
||||||
if slow_mode:
|
if slow_mode:
|
||||||
time.sleep(.55)
|
time.sleep(.5 - frame_time)
|
||||||
|
|
||||||
# On ctrl+C
|
# On ctrl+C
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue