altered output
This commit is contained in:
parent
de19898f38
commit
b6cef14d64
1 changed files with 40 additions and 22 deletions
62
scan_faces.py
Normal file → Executable file
62
scan_faces.py
Normal file → Executable file
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import picamera
|
import picamera
|
||||||
import cv2
|
import cv2
|
||||||
|
@ -7,20 +9,10 @@ import time
|
||||||
|
|
||||||
import Adafruit_CharLCD as LCD
|
import Adafruit_CharLCD as LCD
|
||||||
|
|
||||||
# Init camera
|
|
||||||
camera = picamera.PiCamera()
|
|
||||||
camera.resolution = (1280, 720)
|
|
||||||
|
|
||||||
# Init classifier, various options:
|
|
||||||
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml (~22sec)
|
|
||||||
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml (>25sec)
|
|
||||||
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml (~21sec)
|
|
||||||
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml (~14sec, seems to miss many faces)
|
|
||||||
classifier = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml')
|
|
||||||
|
|
||||||
# Set FPS (though RPi is probably to slow to meet it ;-)
|
# Set FPS (though RPi is probably to slow to meet it ;-)
|
||||||
FPS = 1.0
|
FPS = 1.0
|
||||||
frameTimeDelta = datetime.timedelta(seconds=1.0/FPS)
|
frameTimeDelta = datetime.timedelta(seconds=1.0/FPS)
|
||||||
|
dimTimeDelta = datetime.timedelta(seconds=10)
|
||||||
|
|
||||||
# Init LCD
|
# Init LCD
|
||||||
lcd_rs = 27
|
lcd_rs = 27
|
||||||
|
@ -37,8 +29,29 @@ lcd_rows = 2
|
||||||
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
|
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7,
|
||||||
lcd_columns, lcd_rows, lcd_backlight)
|
lcd_columns, lcd_rows, lcd_backlight)
|
||||||
|
|
||||||
|
lcd.clear()
|
||||||
|
lcd.message("Init scanner.")
|
||||||
|
|
||||||
|
# Init camera
|
||||||
|
camera = picamera.PiCamera()
|
||||||
|
camera.resolution = (1280, 720)
|
||||||
|
|
||||||
|
lcd.clear()
|
||||||
|
lcd.message("Init scanner..")
|
||||||
|
|
||||||
|
# Init classifier, various options:
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml (~22sec)
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml (>25sec)
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml (~21sec)
|
||||||
|
#~ /usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml (~14sec, seems to miss many faces)
|
||||||
|
classifier = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml')
|
||||||
|
lcd.clear()
|
||||||
|
lcd.message("Init scanner...")
|
||||||
|
|
||||||
prevFaceCount = 0
|
prevFaceCount = 0
|
||||||
totalUse = 0
|
totalUse = 0 #in face-seconds
|
||||||
|
|
||||||
|
lastFaceTime = datetime.datetime.utcnow()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print(time.time(),"GO")
|
print(time.time(),"GO")
|
||||||
|
@ -56,22 +69,27 @@ while True:
|
||||||
|
|
||||||
print(time.time(),"Found {} faces".format(len(faces)))
|
print(time.time(),"Found {} faces".format(len(faces)))
|
||||||
|
|
||||||
|
end = datetime.datetime.utcnow()
|
||||||
|
# take the frame as being representative of whole frame
|
||||||
|
scanDuration = (end - start).total_seconds()
|
||||||
|
totalUse += len(faces) * scanDuration
|
||||||
|
|
||||||
lcd.clear()
|
lcd.clear()
|
||||||
lcd.message("Current {:>8}\nTotal {:>10}".format(len(faces), totalUse))
|
#~ lcd.message("viewers {:>8}\nview-min. {:>7.2f}".format(len(faces), totalUse/60))
|
||||||
if len(faces) < 1 and prevFaceCount < 1:
|
lcd.message("viewers {:>8}\nview-sec {:>7}".format(len(faces), int(totalUse)))
|
||||||
|
if len(faces) < 1 and end - lastFaceTime > dimTimeDelta:
|
||||||
lcd.set_backlight(0)
|
lcd.set_backlight(0)
|
||||||
else:
|
else:
|
||||||
lcd.set_backlight(1)
|
lcd.set_backlight(1)
|
||||||
|
|
||||||
end = datetime.datetime.utcnow()
|
if len(faces) > 0:
|
||||||
prevFaceCount = len(faces)
|
lastFaceTime = end
|
||||||
totalUse += len(faces)
|
|
||||||
|
|
||||||
if end - start < frameTimeDelta:
|
|
||||||
|
|
||||||
waitTime = frameTimeDelta - (end-start)
|
#~ if end - start < frameTimeDelta:
|
||||||
print("wait {}".waitTime.total_seconds())
|
|
||||||
time.sleep(waitTime.total_seconds())
|
#~ waitTime = frameTimeDelta - (end-start)
|
||||||
|
#~ print("wait {}".waitTime.total_seconds())
|
||||||
|
#~ time.sleep(waitTime.total_seconds())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue