Compare commits

...

4 Commits

Author SHA1 Message Date
jimmy 7ce521fb89 Add idle 2022-07-20 23:46:55 +12:00
jimmy 5d0764988f Add image 2022-07-20 23:46:36 +12:00
jimmy c9c0dd14b5 Start at random time for 100 frames 2022-07-20 23:46:27 +12:00
jimmy 581fcd8c85 Add controller 2022-07-20 23:45:24 +12:00
4 changed files with 137 additions and 14 deletions

70
controller/main.py Normal file
View File

@ -0,0 +1,70 @@
from gpiozero import LED, Button
from time import sleep
import paho.mqtt.client as mqtt
red = LED(19)
blue = LED(26)
green = LED(13)
button = Button(5)
def main ():
idle = False
while True:
if not idle:
send_idle()
idle = True
sleep(5)
red.on()
send_stop()
if buttonWait():
red.off()
idle = False
playaudio()
displaytext()
sleep(5)
playaudio()
displaytext()
green.on()
printquestion()
sleep(1)
green.off()
red.off()
def buttonWait():
for i in range(500):
if button.value:
print("Button pressed")
return True
sleep(0.01)
return False
def send_idle():
print("Idle")
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("slave", "idle")
def playaudio():
print("Play audio")
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("slave", "audio")
def playvideo():
pass
def displaytext():
print("Display text")
def printquestion():
print("Question")
client = mqtt.Client()
client.connect("localhost", 1883, 60)
client.publish("print", "question")
def send_stop():
pass
main()

23
slave/image.py Normal file
View File

@ -0,0 +1,23 @@
from PIL import Image, ImageDraw
import cv2
import numpy
from time import sleep
def blank(x, y):
image = Image.new('RGB', (1920, 1080), color='black')
draw = ImageDraw.Draw(image)
draw.ellipse((0, 0, 500, 500), fill='Black')
draw.ellipse((10, 10, 490, 490), fill='White')
opencvImage = cv2.cvtColor(numpy.array(image), cv2.COLOR_RGB2BGR)
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", 0, 0)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", opencvImage)
if __name__ == "__main__":
blank(0, 0)
cv2.waitKey(1000)

View File

@ -9,15 +9,18 @@ from video import Video
import multiprocessing
import sys
from random import randint
from PIL import Image, ImageDraw
import cv2
class App:
def __init__(self, client, x, y):
self.x = x
self.y = y
self.client = client
self.video = Video(x, y)
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
print(self.videos)
print(self.videos[randint(0, len(self.videos))])
print(self.videos[randint(0, len(self.videos)-1)])
def on_connect(self, client, userdata, flags, rc):
print("Connected with result code "+str(rc))
@ -33,15 +36,38 @@ class App:
elif msg.payload == b'stop':
print("Stop")
self.x.terminate()
try:
self.x.terminate()
except:
pass
def idle(self):
last = -1
secondlast = -1
while True:
#if self.x is not None:
# self.x.terminate()
video = self.videos[randint(0, len(self.videos))]
try:
self.x.terminate()
except:
pass
i = randint(0, len(self.videos)-1)
if i == last or i == secondlast:
continue
secondlast = last
last = i
video = self.videos[i]
print(video)
self.video.start(video)
self.blank()
sleep(1)
def blank(self):
image = Image.new('RGB', (2000, 2000), color='black')
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", self.x, self.y)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", image)
def main():

View File

@ -19,15 +19,19 @@ class Video:
print("The total number of frames in this video is ", totalframecount)
# self.cap.set(cv2.CAP_PROP_POS_FRAMES, randint(0, totalframecount* 0.9))
i = randint(0, int(totalframecount * 0.9))
self.cap.set(cv2.CAP_PROP_POS_FRAMES, i)
# Read until video is completed
fps = self.cap.get(cv2.CAP_PROP_FPS)
delay = 1/fps * 1000
print(fps, delay)
i = 0
while(self.cap.isOpened() ):
i += 1
if i > 100:
break
while(self.cap.isOpened()):
# Capture frame-by-frame
ret, frame = self.cap.read()
if ret == True:
@ -48,18 +52,18 @@ class Video:
self.cap.release()
# Closes all the frames
cv2.destroyAllWindows()
#cv2.destroyAllWindows()
if __name__ == "__main__":
video = Video(0, 0)
x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))
x = multiprocessing.Process(target = video.start, args=("slave/videos/sample-mp4-file.mp4",))
x.start()
time.sleep(2)
x.terminate()
time.sleep(1)
video = Video(4000, 0)
x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))
x = multiprocessing.Process(target = video.start, args=("slave/videos/sample-mp4-file.mp4",))
x.start()
time.sleep(1)
x.terminate()
x.terminate()