This commit is contained in:
jimmy 2022-07-22 00:09:36 +12:00
parent b60b02e223
commit e784983f99
3 changed files with 58 additions and 40 deletions

View File

@ -1,23 +1,22 @@
from PIL import Image, ImageDraw
import cv2 import cv2
import numpy import numpy as np
from time import sleep from time import sleep
def blank(x, y): class Image:
image = Image.new('RGB', (1920, 1080), color='black') def __init__(self, x, y):
draw = ImageDraw.Draw(image) self.x = x
draw.ellipse((0, 0, 500, 500), fill='Black') self.y = y
draw.ellipse((10, 10, 490, 490), fill='White')
def show(self, path):
image = cv2.imread(path)
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)
opencvImage = cv2.cvtColor(numpy.array(image), cv2.COLOR_RGB2BGR) def blank(self):
blank_image = np.zeros(shape=[512, 512, 3], dtype=np.uint8)
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN) cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.moveWindow("window", 0, 0) cv2.moveWindow("window", self.x, self.y)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN) cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", blank_image)
cv2.imshow("window", opencvImage)
if __name__ == "__main__":
blank(0, 0)
cv2.waitKey(1000)

View File

@ -6,19 +6,25 @@ from random import randint
from time import sleep from time import sleep
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from video import Video from video import Video
import multiprocessing
import sys import sys
from random import randint from random import randint
from PIL import Image, ImageDraw
import cv2 import cv2
from image import Image
import multiprocessing
class App: class App:
def __init__(self, client, x, y): def __init__(self, client, x, y):
self.x = x self.x = x
self.y = y self.y = y
self.client = client self.client = client
self.video = Video(x, y) self.video = Video(x, y)
self.image = Image(x, y)
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))] self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
self.images = [join("slave/images", f) for f in listdir("slave/images") if isfile(join("slave/images", f))]
self.lastvideo = -1
self.lastimage = -1
print(self.videos) print(self.videos)
print(self.videos[randint(0, len(self.videos)-1)]) print(self.videos[randint(0, len(self.videos)-1)])
@ -43,32 +49,44 @@ class App:
def idle(self): def idle(self):
last = -1 last = -1
secondlast = -1
while True: while True:
try: try:
self.x.terminate() self.x.terminate()
except: except:
pass pass
i = randint(0, len(self.videos)-1)
if i == last or i == secondlast:
continue
secondlast = last # if i == last:
last = i # continue
video = self.videos[i] if randint(0,5) == 0:
print(video) self.showimage()
self.video.start(video) else:
self.blank() self.playvideo()
sleep(1)
def blank(self): def showimage(self):
image = Image.new('RGB', (2000, 2000), color='black') totalimages = len(self.images)-1
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN) i = randint(0, totalimages)
cv2.moveWindow("window", self.x, self.y) if i == self.lastimage:
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN) i += 1
if i > totalimages:
cv2.imshow("window", image) i = 0
self.lastimage = i
self.image.show(self.images[i])
cv2.waitKey(1000)
def playvideo(self):
totalvideos = len(self.videos)-1
i = randint(0, totalvideos)
if i == self.lastvideo:
i += 1
if i > totalvideos:
i = 0
self.lastvideo = i
video = self.videos[i]
print(video)
self.video.start(video)
self.image.blank()
cv2.waitKey(1)
def main(): def main():

View File

@ -27,9 +27,10 @@ class Video:
delay = 1/fps * 1000 delay = 1/fps * 1000
print(fps, delay) print(fps, delay)
i = 0 i = 0
playframes = randint(50, 200)
while(self.cap.isOpened() ): while(self.cap.isOpened() ):
i += 1 i += 1
if i > 100: if i > playframes:
break break
# Capture frame-by-frame # Capture frame-by-frame
@ -49,7 +50,7 @@ class Video:
# Break the loop # Break the loop
else: else:
break break
self.cap.release() #self.cap.release()
# Closes all the frames # Closes all the frames
#cv2.destroyAllWindows() #cv2.destroyAllWindows()