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 numpy
import numpy as np
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')
class Image:
def __init__(self, x, y):
self.x = x
self.y = y
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)
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)
def blank(self):
blank_image = np.zeros(shape=[512, 512, 3], dtype=np.uint8)
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", blank_image)

View File

@ -6,19 +6,25 @@ from random import randint
from time import sleep
import paho.mqtt.client as mqtt
from video import Video
import multiprocessing
import sys
from random import randint
from PIL import Image, ImageDraw
import cv2
from image import Image
import multiprocessing
class App:
def __init__(self, client, x, y):
self.x = x
self.y = y
self.client = client
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.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[randint(0, len(self.videos)-1)])
@ -43,32 +49,44 @@ class App:
def idle(self):
last = -1
secondlast = -1
while True:
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)
# if i == last:
# continue
if randint(0,5) == 0:
self.showimage()
else:
self.playvideo()
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 showimage(self):
totalimages = len(self.images)-1
i = randint(0, totalimages)
if i == self.lastimage:
i += 1
if i > totalimages:
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():

View File

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