Skip to content

Commit

Permalink
Add support for alt brown background in music scan
Browse files Browse the repository at this point in the history
  • Loading branch information
EhsanKia committed Nov 25, 2021
1 parent 4726b4b commit cfd42e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Binary file added examples/extra/music_brown2.mp4
Binary file not shown.
25 changes: 15 additions & 10 deletions music.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
BG_COLOR1 = (240, 210, 100)
BG_COLOR2 = (226, 119, 79)
BG_COLOR3 = (49, 60, 102)
BG_COLOR4 = (83, 117, 173)


class SongCover:
Expand All @@ -32,11 +33,7 @@ def __repr__(self):
def detect(frame: numpy.ndarray) -> bool:
"""Detects if a given frame is showing the music list."""
color = frame[:20, 1220:1250].mean(axis=(0, 1))
if numpy.linalg.norm(color - BG_COLOR1) < 15:
return True
if numpy.linalg.norm(color - BG_COLOR2) < 15:
return True
if numpy.linalg.norm(color - BG_COLOR3) < 15:
if _is_background(color):
return True
return False

Expand Down Expand Up @@ -170,16 +167,24 @@ def _remove_blanks(all_icons: List[numpy.ndarray]) -> List[numpy.ndarray]:
filtered_icons = []
for icon in all_icons:
color = icon[5:25, 60:200].mean(axis=(0, 1))
if numpy.linalg.norm(color - BG_COLOR1) < 15:
continue
if numpy.linalg.norm(color - BG_COLOR2) < 15:
continue
if numpy.linalg.norm(color - BG_COLOR3) < 15:
if _is_background(color):
continue
filtered_icons.append(icon)
return filtered_icons


def _is_background(color: numpy.ndarray) -> bool:
if numpy.linalg.norm(color - BG_COLOR1) < 15:
return True
if numpy.linalg.norm(color - BG_COLOR2) < 15:
return True
if numpy.linalg.norm(color - BG_COLOR3) < 15:
return True
if numpy.linalg.norm(color - BG_COLOR4) < 15:
return True
return False


@functools.lru_cache()
def _get_song_db() -> List[SongCover]:
"""Fetches the song cover database for a given locale, with caching."""
Expand Down
1 change: 1 addition & 0 deletions testdata/extra.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"critters_seacreatures_img.jpg": ["abalone", "acorn barnacle", "flatworm", "gazami crab", "giant isopod", "gigas giant clam", "horseshoe crab", "mantis shrimp", "moon jellyfish", "mussel", "octopus", "pearl oyster", "scallop", "sea anemone", "sea grapes", "sea pineapple", "sea slug", "sea star", "sea urchin", "seaweed", "slate pencil urchin", "spotted garden eel", "tiger prawn", "vampire squid", "whelk"],
"music_dark.mp4": ["Agent K.K.", "Bubblegum K.K.", "Caf\u00e9 K.K.", "I Love You", "K.K. Adventure", "K.K. Aria", "K.K. Bossa", "K.K. Casbah", "K.K. Cruisin'", "K.K. D&B", "K.K. Dirge", "K.K. Disco", "K.K. Faire", "K.K. Flamenco", "K.K. Folk", "K.K. Gumbo", "K.K. House", "K.K. Island", "K.K. Jongara", "K.K. Mambo", "K.K. Metal", "K.K. Parade", "K.K. Rally", "K.K. Rock", "K.K. Rockabilly", "K.K. Safari", "K.K. Soul", "K.K. Steppe", "K.K. Synth", "K.K. Waltz", "Only Me", "Spring Blossoms", "Stale Cupcakes", "Steep Hill", "To the Edge", "Welcome Horizons"],
"music_brown.mp4": ["Agent K.K.", "Bubblegum K.K.", "Caf\u00e9 K.K.", "Farewell", "Imperial K.K.", "K.K. Birthday", "K.K. Casbah", "K.K. Country", "K.K. Dirge", "K.K. Dixie", "K.K. Faire", "K.K. Flamenco", "K.K. House", "K.K. Island", "K.K. Jongara", "K.K. Lament", "K.K. Love Song", "K.K. Marathon", "K.K. March", "K.K. Oasis", "K.K. Ragtime", "K.K. Rally", "K.K. Rockabilly", "K.K. Samba", "K.K. Sonata", "K.K. Stroll", "K.K. Synth", "K.K. Tango", "K.K. Technopop", "K.K. \u00c9tude", "King K.K.", "Mountain Song", "Mr. K.K.", "My Place", "Neapolitan", "Rockin' K.K.", "Soulful K.K.", "Space K.K.", "Spring Blossoms", "Stale Cupcakes", "Surfin' K.K.", "The K. Funk", "To the Edge", "Wandering", "Welcome Horizons"],
"music_brown2.mp4": ["Agent K.K.", "Aloha K.K.", "Animal City", "Bubblegum K.K.", "Café K.K.", "Chillwave", "Comrade K.K.", "DJ K.K.", "Drivin'", "Farewell", "Forest Life", "Go K.K. Rider", "Hypno K.K.", "I Love You", "Imperial K.K.", "K.K. Adventure", "K.K. Aria", "K.K. Ballad", "K.K. Bashment", "K.K. Bazaar", "K.K. Birthday", "K.K. Blues", "K.K. Bossa", "K.K. Break", "K.K. Calypso", "K.K. Casbah", "K.K. Chorale", "K.K. Chorinho", "K.K. Condor", "K.K. Country", "K.K. Cruisin'", "K.K. D&B", "K.K. Dirge", "K.K. Disco", "K.K. Dixie", "K.K. Dub", "K.K. Faire", "K.K. Flamenco", "K.K. Folk", "K.K. Fugue", "K.K. Fusion", "K.K. Groove", "K.K. Gumbo", "K.K. Hop", "K.K. House", "K.K. Island", "K.K. Jazz", "K.K. Jongara", "K.K. Khoomei", "K.K. Lament", "K.K. Love Song", "K.K. Lovers", "K.K. Lullaby", "K.K. Mambo", "K.K. Marathon", "K.K. March", "K.K. Mariachi", "K.K. Metal", "K.K. Milonga", "K.K. Moody", "K.K. Oasis", "K.K. Parade", "K.K. Polka", "K.K. Ragtime", "K.K. Rally", "K.K. Reggae", "K.K. Rock", "K.K. Rockabilly", "K.K. Safari", "K.K. Salsa", "K.K. Samba", "K.K. Ska", "K.K. Slack-Key", "K.K. Sonata", "K.K. Song", "K.K. Soul", "K.K. Steppe", "K.K. Stroll", "K.K. Swing", "K.K. Synth", "K.K. Tango", "K.K. Technopop", "K.K. Waltz", "K.K. Western", "K.K. Étude", "King K.K.", "Lucky K.K.", "Marine Song 2001", "Mountain Song", "Mr. K.K.", "My Place", "Neapolitan", "Only Me", "Pondering", "Rockin' K.K.", "Soulful K.K.", "Space K.K.", "Spring Blossoms", "Stale Cupcakes", "Steep Hill", "Surfin' K.K.", "The K. Funk", "To the Edge", "Two Days Ago", "Wandering", "Welcome Horizons"],
"music_img.jpg": ["Animal City", "K.K. Gumbo", "K.K. Swing", "K.K. Tango", "K.K. Technopop", "Welcome Horizons"],
"music_img2.jpg": ["Agent K.K.", "Bubblegum K.K.", "Caf\u00e9 K.K.", "I Love You", "K.K. Adventure", "K.K. Aria", "K.K. Bossa"],
"music_short_end.mp4": ["Agent K.K.", "Aloha K.K.", "Animal City", "Bubblegum K.K.", "Caf\u00e9 K.K.", "Comrade K.K.", "Drivin'", "Forest Life", "Hypno K.K.", "I Love You", "K.K. Bazaar", "K.K. Blues", "K.K. Bossa", "K.K. Calypso", "K.K. Casbah", "K.K. Condor", "K.K. Faire", "K.K. Flamenco", "K.K. Fusion", "K.K. Groove", "K.K. Gumbo", "K.K. Island", "K.K. Mambo", "K.K. March", "K.K. Moody", "K.K. Oasis", "K.K. Parade", "K.K. Ragtime", "K.K. Rally", "K.K. Rock", "K.K. Rockabilly", "K.K. Safari", "K.K. Sonata", "K.K. Song", "K.K. Soul", "K.K. Swing", "K.K. Tango", "K.K. \u00c9tude", "Marine Song 2001", "My Place", "Neapolitan", "Pondering", "Space K.K.", "Spring Blossoms", "Stale Cupcakes", "The K. Funk", "To the Edge", "Welcome Horizons"],
Expand Down

0 comments on commit cfd42e1

Please sign in to comment.