supervisorconf + fixes

This commit is contained in:
Artwork1 2018-01-05 00:04:52 +01:00
parent 1a38065a08
commit 4e1a633ba0
2 changed files with 51 additions and 42 deletions

View file

@ -89,50 +89,54 @@ log = open(logfile, "a")
lastFaceTime = datetime.datetime.utcnow() lastFaceTime = datetime.datetime.utcnow()
while True: while True:
print(time.time(),"GO") try:
start = datetime.datetime.utcnow() print(time.time(),"GO")
stream = io.BytesIO() start = datetime.datetime.utcnow()
camera.capture(stream, format='jpeg') stream = io.BytesIO()
print(time.time(),"captured") camera.capture(stream, format='jpeg')
buff = np.fromstring(stream.getvalue(), dtype=np.uint8) print(time.time(),"captured")
image = cv2.imdecode(buff,1) buff = np.fromstring(stream.getvalue(), dtype=np.uint8)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) image = cv2.imdecode(buff,1)
print(time.time(),"grayed") gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = classifier.detectMultiScale(gray, 1.2, 5, minSize=(30,20)) print(time.time(),"grayed")
faces = classifier.detectMultiScale(gray, 1.2, 5, minSize=(30,20))
print(time.time(),"Found {} faces".format(len(faces))) print(time.time(),"Found {} faces".format(len(faces)))
end = datetime.datetime.utcnow() end = datetime.datetime.utcnow()
# take the frame as being representative of whole frame # take the frame as being representative of whole frame
scanDuration = (end - start).total_seconds() scanDuration = (end - start).total_seconds()
totalUse += len(faces) * scanDuration totalUse += len(faces) * scanDuration
lcd.clear() lcd.clear()
#~ lcd.message("viewers {:>8}\nview-min. {:>7.2f}".format(len(faces), totalUse/60)) #~ lcd.message("viewers {:>8}\nview-min. {:>7.2f}".format(len(faces), totalUse/60))
lcd.message("{:>7} viewers \n{:>7}view-sec".format(len(faces), si_format(totalUse,precision=1))) lcd.message("{:>7} viewers \n{:>7}view-sec".format(len(faces), si_format(totalUse,precision=1)))
log.write("{},{},{}\n".format(time.time(), len(faces), int(totalUse))) log.write("{},{},{}\n".format(time.time(), len(faces), int(totalUse)))
log.flush() log.flush()
os.fsync(log.fileno())
content = urllib2.urlopen("https://artstats.rubenvandeven.com/artwork1/views.php?time=%d&count=%d&total=%d" % (int(time.time()), len(faces), int(totalUse)) ).read()
os.fsync(log.fileno())
if len(faces) < 1 and end - lastFaceTime > dimTimeDelta:
lcd.set_backlight(0)
else:
lcd.set_backlight(1)
if len(faces) > 0:
lastFaceTime = end
#~ if end - start < frameTimeDelta:
#~ waitTime = frameTimeDelta - (end-start)
#~ print("wait {}".waitTime.total_seconds())
#~ time.sleep(waitTime.total_seconds())
if len(faces) < 1 and end - lastFaceTime > dimTimeDelta:
lcd.set_backlight(0)
else:
lcd.set_backlight(1)
if len(faces) > 0:
lastFaceTime = end
content = urllib2.urlopen("https://artstats.rubenvandeven.com/artwork1/views.php?time=%d&count=%d&total=%d" % (int(time.time()), len(faces), int(totalUse)) ).read()
#~ if end - start < frameTimeDelta:
#~ waitTime = frameTimeDelta - (end-start)
#~ print("wait {}".waitTime.total_seconds())
#~ time.sleep(waitTime.total_seconds())
except Exception as e:
print e

5
supervisord.conf Normal file
View file

@ -0,0 +1,5 @@
[program:scan_faces]
directory=/home/pi/scan_faces
command=/usr/bin/python /home/pi/scan_faces/scan_faces.py
user=pi
autorestart=true