Skip to content

Commit

Permalink
Updated Templates, added HDMI component to external, changed configur…
Browse files Browse the repository at this point in the history
…e to include gamma for DolbyVision/HDR10+
  • Loading branch information
AndrewMohawk committed Jan 3, 2021
1 parent 17ad538 commit 0883a74
Show file tree
Hide file tree
Showing 24 changed files with 1,751 additions and 1,257 deletions.
648 changes: 456 additions & 192 deletions Aurora.py

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ server_port = 8080
[EXTENSIONS]
directory = extensions
default_extension = Aurora_Ambient_AutoCrop
current_extension = Aurora_Ambient_NoCrop
current_extension = Aurora_Ambient_AutoCrop

[HDMI]
HDMI_BRIGHTNESS = -11
HDMI_SATURATION = 255
HDMI_CONTRAST = 130
HDMI_HUE = 0

[HDMI_INITIAL]
HDMI_BRIGHTNESS = -11
HDMI_SATURATION = 255
HDMI_CONTRAST = 130
HDMI_HUE = 0

[AURORA]
AURORA_PIXELCOUNT_TOTAL = 270
AURORA_PIXELCOUNT_LEFT = 49
AURORA_PIXELCOUNT_RIGHT = 49
AURORA_PIXELCOUNT_TOP = 86
AURORA_PIXELCOUNT_BOTTOM = 86
AURORA_GAMMA = 5.0
AURORA_DEBUG = true

29 changes: 22 additions & 7 deletions config.ini.bak
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[GENERAL]
screenshot_path = /tmp/aurora_screenshot.jpg
pixel_image_path = /tmp/aurora_pixels.jpg
configured = False
enabled = True

[WEBSERVER]
enabled = True
Expand All @@ -9,15 +11,28 @@ server_port = 8080

[EXTENSIONS]
directory = extensions
default_extension = Aurora_AutoCrop
current_extension = Aurora_AutoCrop
default_extension = Aurora_Ambient_AutoCrop
current_extension = Aurora_Ambient_AutoCrop

[HDMI]
HDMI_BRIGHTNESS = -11
HDMI_SATURATION = 255
HDMI_CONTRAST = 130
HDMI_HUE = 0

[HDMI_INITIAL]
HDMI_BRIGHTNESS = -11
HDMI_SATURATION = 255
HDMI_CONTRAST = 130
HDMI_HUE = 0

[AURORA]
AURORA_PIXELCOUNT_TOTAL = 300
AURORA_PIXELCOUNT_LEFT = 50
AURORA_PIXELCOUNT_RIGHT = 50
AURORA_PIXELCOUNT_TOP = 100
AURORA_PIXELCOUNT_BOTTOM = 100
AURORA_PIXELCOUNT_TOTAL = 270
AURORA_PIXELCOUNT_LEFT = 49
AURORA_PIXELCOUNT_RIGHT = 49
AURORA_PIXELCOUNT_TOP = 86
AURORA_PIXELCOUNT_BOTTOM = 86
AURORA_GAMMA = 5.0
AURORA_DEBUG = false


Expand Down
196 changes: 72 additions & 124 deletions extensions/Aurora_Ambient_AutoCrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,187 +2,135 @@
import time
import datetime
import numpy as np
import pandas as pd
import pandas as pd
import cv2


class Aurora_Ambient_AutoCrop(AuroraExtension):
def __init__(self,NeoPixels):
super().__init__(NeoPixels)
def __init__(self, NeoPixels, HDMI):
super().__init__(NeoPixels, HDMI)
self.Author = "Andrew MacPherson (@AndrewMohawk)"
self.Description = "This extension takes the HDMI input and calculates a border (including cropping for black borders) to work out ambient lighting for behind the display."
self.Name="Aurora Ambient Lighting ( AutoCrop )"
self.Name = "Aurora Ambient Lighting ( AutoCrop )"
self.count = 0
self.current_frame = False
self.cropped_frame = False
self.percent = 3


def autocrop(self,image, threshold=0):
"""Crops any edges below or equal to threshold
Crops blank image to 1x1.
Returns cropped image.
"""
if len(image.shape) == 3:
flatImage = np.max(image, 2)
else:
flatImage = image
assert len(flatImage.shape) == 2

rows = np.where(np.max(flatImage, 0) > threshold)[0]
if rows.size:
cols = np.where(np.max(flatImage, 1) > threshold)[0]
image = image[cols[0]: cols[-1] + 1, rows[0]: rows[-1] + 1]
else:
image = image[:1, :1]

return image

def takeScreenShot(self,filepath):
screenshot_frame = self.cropped_frame
widthPixels = int(self.vid_w * (self.percent/100)) + 1
heightPixels = int(self.vid_h * (self.percent/100)*2) + 1

colour = (0,0,255)


#top
screenshot_frame = cv2.rectangle(screenshot_frame, (0,0), (self.vid_w,heightPixels), (0,0,255), 1)
#bottom
screenshot_frame = cv2.rectangle(screenshot_frame, (0,self.vid_h-heightPixels), (self.vid_w,self.vid_h), (0,0,255), 1)
#left
screenshot_frame = cv2.rectangle(screenshot_frame, (0,0), (widthPixels,self.vid_h), (0,0,255), 1)
#right
screenshot_frame = cv2.rectangle(screenshot_frame, (self.vid_w-widthPixels,0), (self.vid_w,self.vid_h), (0,0,255), 1)

# sectionTop = self.current_frame[0:heightPixels,0:self.vid_w]
# sectionBottom = self.current_frame[self.vid_h-heightPixels:self.vid_h,0:self.vid_w]

# sectionLeft = self.current_frame[0:self.vid_h,0:widthPixels]
# sectionRight = self.current_frame[0:self.vid_h,self.vid_w-widthPixels:self.vid_w]
print("saved screenshot of size {} x {} to {}".format(widthPixels,heightPixels,filepath))
cv2.imwrite(filepath, screenshot_frame)

return True

def visualise(self):
# Capture the video frame
# Capture the video frame
ret, self.current_frame = self.getFrame()
self.vid_h, self.vid_w, self.channels = self.current_frame.shape
self.vid_h, self.vid_w, self.channels = self.current_frame.shape

crop_time = datetime.datetime.now()
#print("Image dimensions pre-crop {} {}".format(self.vid_h,self.vid_w))
# print("Image dimensions pre-crop {} {}".format(self.vid_h,self.vid_w))
self.current_frame = self.autocrop(self.current_frame)
self.cropped_frame = self.current_frame
self.vid_h, self.vid_w, self.channels = self.current_frame.shape
#print("Crop Time: \t{}".format(datetime.datetime.now() - crop_time))
#print("Image dimensions {} {}".format(vid_h,vid_w))
if(self.vid_h <= 1 and self.vid_w <= 1):
print("Empty image {} {}".format(self.vid_h,self.vid_w))
#print(ret)
#self.log("Empty image {} {}".format(self.vid_h,self.vid_w))
self.vid_h, self.vid_w, self.channels = self.current_frame.shape
# print("Crop Time: \t{}".format(datetime.datetime.now() - crop_time))

# print("Image dimensions {} {}".format(vid_h,vid_w))
if self.vid_h <= 1 and self.vid_w <= 1:
print("Empty image {} {}".format(self.vid_h, self.vid_w))
# print(ret)
# self.log("Empty image {} {}".format(self.vid_h,self.vid_w))
self.pixels.fill((0, 0, 0))
self.pixels.show()
return


#cv2.imwrite("frame%d.jpg" % ret, frame)
#if(flipImage == True):

# cv2.imwrite("frame%d.jpg" % ret, frame)
# if(flipImage == True):
# frame = cv2.flip(frame,1)
# img[y:y+h, x:x+w]



widthPixels = int(self.vid_w * (self.percent/100)) + 1
heightPixels = int(self.vid_h * (self.percent/100)*2) + 1


widthPixels = int(self.vid_w * (self.percent / 100)) + 1
heightPixels = int(self.vid_h * (self.percent / 100) * 2) + 1

cutTime = datetime.datetime.now()

sectionTop = self.current_frame[0:heightPixels,0:self.vid_w]
sectionBottom = self.current_frame[self.vid_h-heightPixels:self.vid_h,0:self.vid_w]

sectionLeft = self.current_frame[0:self.vid_h,0:widthPixels]
sectionRight = self.current_frame[0:self.vid_h,self.vid_w-widthPixels:self.vid_w]


#print("Cut Time: \t{}".format(datetime.datetime.now() - cutTime))
sectionTop = self.current_frame[0:heightPixels, 0 : self.vid_w]
sectionBottom = self.current_frame[
self.vid_h - heightPixels : self.vid_h, 0 : self.vid_w
]

sectionLeft = self.current_frame[0 : self.vid_h, 0:widthPixels]
sectionRight = self.current_frame[
0 : self.vid_h, self.vid_w - widthPixels : self.vid_w
]

# print("Cut Time: \t{}".format(datetime.datetime.now() - cutTime))
resizeTime = datetime.datetime.now()
# get shape
h, w, c = sectionTop.shape
hs = 1
ws = self.pixelsTop

# resize image using block averaging
#print("b {} {} {}".format(sectionTop,ws,hs))
#print("0:{},0:{}".format(heightPixels,vid_w))
resizedTop = cv2.resize(sectionTop, (ws,hs), interpolation = cv2.INTER_AREA)
resizedBottom = cv2.resize(sectionBottom, (ws,hs), interpolation = cv2.INTER_AREA)


#get shape for sides
h,w,c = sectionLeft.shape
# resize image using block averaging
# print("b {} {} {}".format(sectionTop,ws,hs))
# print("0:{},0:{}".format(heightPixels,vid_w))
resizedTop = cv2.resize(sectionTop, (ws, hs), interpolation=cv2.INTER_AREA)
resizedBottom = cv2.resize(
sectionBottom, (ws, hs), interpolation=cv2.INTER_AREA
)

# get shape for sides
h, w, c = sectionLeft.shape
hs = self.pixelsLeft
ws = 1
#print("c")
resizedLeft = cv2.resize(sectionLeft, (ws,hs), interpolation = cv2.INTER_AREA)
resizedRight = cv2.resize(sectionRight, (ws,hs), interpolation = cv2.INTER_AREA)

#print("Resize Time: \t{}".format(datetime.datetime.now() - resizeTime))
#Finished calculations
# print("c")
resizedLeft = cv2.resize(sectionLeft, (ws, hs), interpolation=cv2.INTER_AREA)
resizedRight = cv2.resize(sectionRight, (ws, hs), interpolation=cv2.INTER_AREA)

# print("Resize Time: \t{}".format(datetime.datetime.now() - resizeTime))
# Finished calculations

#Populate LEDs
# Populate LEDs
startPoint = 0
for i in range(self.pixelsLeft):
B,G,R = resizedLeft[i][0]
self.pixels[self.pixelsLeft - (startPoint + i)] = (R,G,B)
#print(pixels)
B, G, R = resizedLeft[i][0]
self.pixels[self.pixelsLeft - (startPoint + i)] = (R, G, B)
# print(pixels)

startPoint += self.pixelsLeft
for i in range(self.pixelsTop):
B,G,R = resizedTop[0][i]
self.pixels[startPoint + i] = (R,G,B)
B, G, R = resizedTop[0][i]
self.pixels[startPoint + i] = (R, G, B)

startPoint += self.pixelsTop
for i in range(self.pixelsRight):
B,G,R = resizedRight[i][0]
self.pixels[startPoint + i] = (R,G,B)
B, G, R = resizedRight[i][0]
self.pixels[startPoint + i] = (R, G, B)

startPoint += self.pixelsRight
#print("starting at {} adding {} pixels".format(startPoint,bottomPixels))
# print("starting at {} adding {} pixels".format(startPoint,bottomPixels))
for i in range(self.pixelsBottom):
B,G,R = resizedBottom[0][i]
self.pixels[startPoint + self.pixelsBottom - i -1] = (R,G,B)
'''
B, G, R = resizedBottom[0][i]
self.pixels[startPoint + self.pixelsBottom - i - 1] = (R, G, B)
"""
print("Showing {} Pixels".format(len(pixels)))
for x in range(10):
print("Pixels {}: {}".format(x,pixels[x]))
for x in range(290,300):
print("Pixels {}: {}".format(x,pixels[x]))
'''
"""
self.pixels.show()


# if( showWindows ):
# cv2.imshow('TopPixels', cv2.resize(resizedTop,(600,5)))
# cv2.imshow('LeftPixels', cv2.resize(resizedLeft,(5,600)))
# cv2.imshow('RightPixels', cv2.resize(resizedRight,(5,600)))
# cv2.imshow('BottomPixels', cv2.resize(resizedBottom,(600,5)))
# cv2.imshow('Main Image', cv2.resize(frame,(360,240)))


# # the 'q' button is set as the
# # quitting button you may use any
# # desired button of your choice
# if cv2.waitKey(1) & 0xFF == ord('q'):
# # the 'q' button is set as the
# # quitting button you may use any
# # desired button of your choice
# if cv2.waitKey(1) & 0xFF == ord('q'):
# return
#print("Total Time: \t{}\n".format(datetime.datetime.now() - start_time))


#visualise!
# print("Total Time: \t{}\n".format(datetime.datetime.now() - start_time))

# visualise!
self.count += 1
#print("{} : {}".format(self.Name,self.count))
# print("{} : {}".format(self.Name,self.count))
Loading

0 comments on commit 0883a74

Please sign in to comment.