supervisorconf + fixes

master
Artwork1 5 years ago
parent 1a38065a08
commit 4e1a633ba0
  1. 90
      scan_faces.py
  2. 5
      supervisord.conf

@ -89,50 +89,54 @@ log = open(logfile, "a")
lastFaceTime = datetime.datetime.utcnow()
while True:
print(time.time(),"GO")
start = datetime.datetime.utcnow()
stream = io.BytesIO()
camera.capture(stream, format='jpeg')
print(time.time(),"captured")
buff = np.fromstring(stream.getvalue(), dtype=np.uint8)
image = cv2.imdecode(buff,1)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
print(time.time(),"grayed")
faces = classifier.detectMultiScale(gray, 1.2, 5, minSize=(30,20))
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.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)))
log.write("{},{},{}\n".format(time.time(), len(faces), int(totalUse)))
log.flush()
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
try:
print(time.time(),"GO")
start = datetime.datetime.utcnow()
stream = io.BytesIO()
camera.capture(stream, format='jpeg')
print(time.time(),"captured")
buff = np.fromstring(stream.getvalue(), dtype=np.uint8)
image = cv2.imdecode(buff,1)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
print(time.time(),"grayed")
faces = classifier.detectMultiScale(gray, 1.2, 5, minSize=(30,20))
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.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)))
log.write("{},{},{}\n".format(time.time(), len(faces), int(totalUse)))
log.flush()
os.fsync(log.fileno())
if len(faces) < 1 and end - lastFaceTime > dimTimeDelta:
lcd.set_backlight(0)
else:
lcd.set_backlight(1)
#~ if end - start < frameTimeDelta:
if len(faces) > 0:
lastFaceTime = end
#~ waitTime = frameTimeDelta - (end-start)
#~ print("wait {}".waitTime.total_seconds())
#~ time.sleep(waitTime.total_seconds())
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

@ -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
Loading…
Cancel
Save