|
|
@ -56,7 +56,14 @@ def resize_and_center_frame(frame):
|
|
|
|
# Create a black background of the window size
|
|
|
|
# Create a black background of the window size
|
|
|
|
window_background = np.zeros((WINDOW_HEIGHT, WINDOW_WIDTH, 3), dtype=np.uint8)
|
|
|
|
window_background = np.zeros((WINDOW_HEIGHT, WINDOW_WIDTH, 3), dtype=np.uint8)
|
|
|
|
|
|
|
|
|
|
|
|
# Overlay the resized frame onto the background at the calculated offset
|
|
|
|
# Overlay the resized frame onto the background at the calculated offset
|
|
|
|
|
|
|
|
print(y_offset)
|
|
|
|
|
|
|
|
print(y_offset)
|
|
|
|
|
|
|
|
print(new_height)
|
|
|
|
|
|
|
|
print(x_offset)
|
|
|
|
|
|
|
|
print(x_offset)
|
|
|
|
|
|
|
|
print(new_width)
|
|
|
|
|
|
|
|
|
|
|
|
window_background[
|
|
|
|
window_background[
|
|
|
|
y_offset : y_offset + new_height, x_offset : x_offset + new_width
|
|
|
|
y_offset : y_offset + new_height, x_offset : x_offset + new_width
|
|
|
|
] = resized_frame
|
|
|
|
] = resized_frame
|
|
|
@ -67,17 +74,22 @@ def resize_and_center_frame(frame):
|
|
|
|
# Show an image on the canvas
|
|
|
|
# Show an image on the canvas
|
|
|
|
def showImage(file):
|
|
|
|
def showImage(file):
|
|
|
|
# Read the image
|
|
|
|
# Read the image
|
|
|
|
current_image = cv2.imread(MEDIA_FOLDER + "/" + file)
|
|
|
|
current_image = cv2.imread(file)
|
|
|
|
|
|
|
|
|
|
|
|
if current_image is None:
|
|
|
|
if current_image is None:
|
|
|
|
print(f"Error loading image: {image_path}")
|
|
|
|
print(f"Error loading image: {current_image}")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
a = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY)
|
|
|
|
a = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY)
|
|
|
|
resized_frame = resize_and_center_frame(current_image)
|
|
|
|
|
|
|
|
cv2.imshow(WINDOW_NAME, resized_frame)
|
|
|
|
# resized_frame = resize_and_center_frame(current_image)
|
|
|
|
cv2.namedWindow(WINDOW_NAME,cv2.WND_PROP_FULLSCREEN)
|
|
|
|
cv2.imshow(WINDOW_NAME, current_image)
|
|
|
|
cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
|
|
|
# cv2.namedWindow(WINDOW_NAME,cv2.WND_PROP_FULLSCREEN)
|
|
|
|
|
|
|
|
# cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cv2.waitKey(1)
|
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
for i in range(12):
|
|
|
|
for i in range(12):
|
|
|
|
if mpr121[i].value:
|
|
|
|
if mpr121[i].value:
|
|
|
@ -87,7 +99,7 @@ def showImage(file):
|
|
|
|
|
|
|
|
|
|
|
|
def play_audio(file):
|
|
|
|
def play_audio(file):
|
|
|
|
clear_frame()
|
|
|
|
clear_frame()
|
|
|
|
sound = sa.WaveObject.from_wave_file("media/" + file)
|
|
|
|
sound = sa.WaveObject.from_wave_file(file)
|
|
|
|
play_obj = sound.play()
|
|
|
|
play_obj = sound.play()
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: check for sensor data change
|
|
|
|
# TODO: check for sensor data change
|
|
|
@ -96,39 +108,55 @@ def play_audio(file):
|
|
|
|
time.sleep(0.1)
|
|
|
|
time.sleep(0.1)
|
|
|
|
load_media()
|
|
|
|
load_media()
|
|
|
|
|
|
|
|
|
|
|
|
def get_random_file(previous=None):
|
|
|
|
def get_random_file(f):
|
|
|
|
random.shuffle(mediaFolder)
|
|
|
|
print("getting random file from ")
|
|
|
|
file = mediaFolder[0]
|
|
|
|
print(f)
|
|
|
|
if file == previous:
|
|
|
|
|
|
|
|
return get_random_file(previous)
|
|
|
|
folder = os.listdir(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
random.shuffle(folder)
|
|
|
|
|
|
|
|
file = folder[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isdir(file):
|
|
|
|
|
|
|
|
print("oh no u gave me a folder, load the sub instead")
|
|
|
|
|
|
|
|
nF = os.listdir(f + "/" + file)
|
|
|
|
|
|
|
|
return get_random_file(nF)
|
|
|
|
|
|
|
|
|
|
|
|
return file
|
|
|
|
return file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# create a function with an optional parameter
|
|
|
|
# create a function with an optional parameter
|
|
|
|
def load_media(region=None, override=None):
|
|
|
|
def load_media(region=None, override=None):
|
|
|
|
global current_file
|
|
|
|
global current_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("runningn load_media")
|
|
|
|
|
|
|
|
|
|
|
|
if region:
|
|
|
|
if region:
|
|
|
|
print("i should now load a media from region ")
|
|
|
|
print("i should now load a media from region ")
|
|
|
|
print(region)
|
|
|
|
print(region)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("region is not defined, just do something!")
|
|
|
|
print("region is not defined, just do something!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
folder = os.listdir(MEDIA_FOLDER)[region]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(folder)
|
|
|
|
|
|
|
|
|
|
|
|
if(override):
|
|
|
|
if(override):
|
|
|
|
file = override
|
|
|
|
file = override
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
file = get_random_file(current_file)
|
|
|
|
file = get_random_file(MEDIA_FOLDER + "/" + folder)
|
|
|
|
|
|
|
|
|
|
|
|
current_file = file
|
|
|
|
current_file = file
|
|
|
|
|
|
|
|
file_path = MEDIA_FOLDER + "/" + folder + "/" + file
|
|
|
|
|
|
|
|
print(file_path)
|
|
|
|
# Check if the file is an image or a video
|
|
|
|
# Check if the file is an image or a video
|
|
|
|
if file.endswith(".jpg") or file.endswith(".png") or file.endswith(".jpeg"):
|
|
|
|
if file.endswith(".jpg") or file.endswith(".png") or file.endswith(".jpeg"):
|
|
|
|
# Read and resize the image
|
|
|
|
# Read and resize the image
|
|
|
|
print("ive loaded an image: " + file)
|
|
|
|
print("ive loaded an image: " + file)
|
|
|
|
showImage(file)
|
|
|
|
showImage(file_path)
|
|
|
|
elif file.endswith(".mov") or file.endswith(".mp4") or file.endswith(".avi"):
|
|
|
|
elif file.endswith(".mov") or file.endswith(".mp4") or file.endswith(".avi"):
|
|
|
|
# Create a VideoCapture object and read from input file
|
|
|
|
# Create a VideoCapture object and read from input file
|
|
|
|
cap = cv2.VideoCapture("media/" + file)
|
|
|
|
cap = cv2.VideoCapture(file_path)
|
|
|
|
print("ive loaded a video" + file)
|
|
|
|
print("ive loaded a video" + file)
|
|
|
|
|
|
|
|
|
|
|
|
# show the input video file
|
|
|
|
# show the input video file
|
|
|
@ -156,7 +184,7 @@ def load_media(region=None, override=None):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
elif file.endswith(".wav") or file.endswith(".mp3"):
|
|
|
|
elif file.endswith(".wav") or file.endswith(".mp3"):
|
|
|
|
print("ive loaded an audio file: " + file)
|
|
|
|
print("ive loaded an audio file: " + file)
|
|
|
|
play_audio(file)
|
|
|
|
play_audio(file_path)
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Unsupported file format: " + file)
|
|
|
|
print("Unsupported file format: " + file)
|
|
|
@ -164,4 +192,4 @@ def load_media(region=None, override=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("start script ")
|
|
|
|
print("start script ")
|
|
|
|
load_media()
|
|
|
|
load_media(2)
|
|
|
|