From 4e1a633ba02a6af1213e4bf5d77564f35922d2e4 Mon Sep 17 00:00:00 2001 From: Artwork1 Date: Fri, 5 Jan 2018 00:04:52 +0100 Subject: [PATCH] supervisorconf + fixes --- scan_faces.py | 88 +++++++++++++++++++++++++----------------------- supervisord.conf | 5 +++ 2 files changed, 51 insertions(+), 42 deletions(-) create mode 100644 supervisord.conf diff --git a/scan_faces.py b/scan_faces.py index b4eed7f..ab9ff7b 100755 --- a/scan_faces.py +++ b/scan_faces.py @@ -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)) + 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() - - 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: + print(time.time(),"Found {} faces".format(len(faces))) - #~ waitTime = frameTimeDelta - (end-start) - #~ print("wait {}".waitTime.total_seconds()) - #~ time.sleep(waitTime.total_seconds()) - + 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 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 + - diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..197b89c --- /dev/null +++ b/supervisord.conf @@ -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