Interaction-without-Interac.../server/main.py

38 lines
1.0 KiB
Python
Raw Normal View History

2019-04-09 20:05:04 +00:00
import time
import requests
import detector as dt
import cv2
if __name__ == "__main__":
2019-06-06 16:46:25 +00:00
t = 1 # seconds a person can leave the room for
2019-04-09 20:05:04 +00:00
t0 = time.time()
time.clock()
elapsed = 0
2019-06-06 16:46:25 +00:00
#stream = "https://192.168.178.56:8080/video"
2019-04-09 20:05:04 +00:00
stream = "http://217.128.254.187:8083/mjpg/video.mjpg"
detector = dt.Detector(stream)
music_playing = False
2019-06-06 16:46:25 +00:00
#cv2.startWindowThread()
#cv2.namedWindow("preview")
2019-04-09 20:05:04 +00:00
while True:
elapsed = time.time() - t0
if elapsed > t and music_playing:
r = requests.get("http://192.168.178.53/stop")
if r.status_code == 200:
music_playing = False
2019-06-06 16:46:25 +00:00
tmp = time.time()
img = detector.detect()
print(time.time()-tmp)
if img is not None and not music_playing:
2019-04-09 20:05:04 +00:00
r = requests.get("http://192.168.178.53/play")
if r.status_code == 200:
music_playing = True
t0 = time.time()
2019-06-06 16:46:25 +00:00
cv2.imshow("preview", img)
cv2.waitKey(1)
2019-04-09 20:05:04 +00:00