updated background dominant color calculation

reworked updater to work as handler, will restart if exception
This commit is contained in:
Brandon4466
2023-03-27 00:13:26 -07:00
parent ef4d0fee66
commit cf6f02acd1
7 changed files with 58 additions and 17 deletions

View File

@@ -12,6 +12,7 @@ import math
from time import sleep
import threading
import queue
import numpy
# SpotifyGUI - Made by Brandon Brunson
@@ -251,24 +252,58 @@ def addCorners(im, rad):
# return back
def get_colors(image_file, numcolors=1, resize=150):
# def get_colors(image_file, resize=150):
# # Resize image to speed up processing
# image_file.thumbnail((resize, resize))
# max_count_index = numpy.argmax(numpy.unique(numpy.array(image_file).reshape(-1, numpy.array(image_file).shape[-1]), axis=0, return_counts=True)[1])
# # colors = list()
# # for i in range(numcolors):
# # palette_index = color_counts[i][1]
# # dominant_color = palette[palette_index*3:palette_index*3+3]
# # colors.append(tuple(dominant_color))
# return tuple(numpy.unique(numpy.array(image_file).reshape(-1, numpy.array(image_file).shape[-1]), axis=0, return_counts=True)[0][max_count_index])
def get_colors(image_file, resize=150):
# Resize image to speed up processing
image_file.thumbnail((resize, resize))
# Reduce to palette
paletted = image_file.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
numpy_array = numpy.array(image_file)
pixels = numpy_array.reshape(-1, numpy_array.shape[-1])
color_counts = numpy.unique(pixels, axis=0, return_counts=True)
max_count_index = numpy.argmax(color_counts[1])
# Find dominant colors
palette = paletted.getpalette()
# color_counts = sorted(paletted.getcolors(), reverse=True)
dominant_color = (palette[0], palette[1], palette[2])
# colors = list()
# for i in range(numcolors):
# palette_index = color_counts[i][1]
# dominant_color = palette[palette_index*3:palette_index*3+3]
# colors.append(tuple(dominant_color))
return dominant_color
return tuple(color_counts[0][max_count_index])
# def get_colors(image_file, numcolors=1, resize=150):
# # Resize image to speed up processing
# image_file.thumbnail((resize, resize))
# # Reduce to palette
# paletted = image_file.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
# # Find dominant colors
# palette = paletted.getpalette()
# # color_counts = sorted(paletted.getcolors(), reverse=True)
# dominant_color = (palette[0], palette[1], palette[2])
# # colors = list()
# # for i in range(numcolors):
# # palette_index = color_counts[i][1]
# # dominant_color = palette[palette_index*3:palette_index*3+3]
# # colors.append(tuple(dominant_color))
# return dominant_color
def getLyrics(artist_name, track_name):
lrc = syncedlyrics.search("[" + track_name + "] [" + artist_name + "]")
@@ -489,8 +524,11 @@ def unloadSearching_Devices():
# Start updating the song label
# setup()
# Run the GUI
loadNow_playing()
update_song_label()
# Run the GUI
root.mainloop()