Documentation & cleaning up
parent
bed4bdfe6f
commit
f8642cc37e
|
@ -1,3 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from glob import glob
|
||||
from pathlib import Path
|
||||
|
@ -8,6 +11,7 @@ from sklearn.cluster import KMeans
|
|||
|
||||
data_folder = str(Path(__file__).parents[3]) + "/data/"
|
||||
|
||||
# Find the most dominant colors trough k-means clustering
|
||||
def find_dominant_color(image_path, k=1):
|
||||
# Load the image
|
||||
image = cv2.imread(image_path)
|
||||
|
@ -30,6 +34,7 @@ def find_dominant_color(image_path, k=1):
|
|||
|
||||
return tuple(map(tuple, dominant_colors))
|
||||
|
||||
# Convert RGB to HEX
|
||||
def convert_to_hex(arr):
|
||||
|
||||
colors = []
|
||||
|
@ -39,6 +44,7 @@ def convert_to_hex(arr):
|
|||
|
||||
return colors
|
||||
|
||||
# Loop trough the frames and get most dominant color
|
||||
def frame_to_dominant_colors(ep):
|
||||
|
||||
colors = []
|
||||
|
@ -50,22 +56,31 @@ def frame_to_dominant_colors(ep):
|
|||
|
||||
return colors
|
||||
|
||||
# Generate a SVG with the most dominant colors
|
||||
def generate_svg(data, ep):
|
||||
svg = ''
|
||||
width = len(data)
|
||||
for i, d in enumerate(data):
|
||||
for j, cl in enumerate(d):
|
||||
svg = svg + f'<rect width="{100 / width}%" x="{(100 / width) *i}%" y="{j * 20}%" height="20%" fill="{cl}" />'
|
||||
svg = svg + f'<rect width="{100 / width}%" x="{(100 / width) *i}%" y="0" height="100%" fill="{cl}" />'
|
||||
|
||||
svg = f'<svg version="1.1" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">' + svg + '</svg>'
|
||||
svg = f'<svg version="1.1" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">{svg}</svg>'
|
||||
queries.save_data_viz(ep, svg)
|
||||
return svg
|
||||
|
||||
# Initialize the SVG generation
|
||||
def dominant_color_svg(ep):
|
||||
svg = generate_svg(frame_to_dominant_colors(ep), ep)
|
||||
with open(f"{data_folder}/{ep}/dominant_colors.svg", "w") as f:
|
||||
f.write(svg)
|
||||
return "SVG generated!"
|
||||
|
||||
dominant_color_svg("24")
|
||||
# CLI
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="Dominant Color Generation", description="Get the most dominant colors of a image and assemble a SVG."
|
||||
)
|
||||
|
||||
parser.add_argument("--episode", "-ep", type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
dominant_color_svg(args.episode)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/bash
|
||||
area=$(magick $1 -format "%[fx:w*h]" info:)
|
||||
magick $1 -kmeans 5 -format "%c" histogram:info: | sed 's/://g' | awk -v area=$area '{print 100*$1/area, "%,", $3}' | sed 's/ *//g' | sort -nr -k1,1 -t ","
|
|
@ -1,9 +0,0 @@
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
start = time.time()
|
||||
path = "/home/gio/Code/VANA/data/25/frame000007.jpg"
|
||||
img_format = subprocess.getstatusoutput(f'./dominant_colors.sh {path}')
|
||||
print(img_format)
|
||||
end = time.time()
|
||||
print(end - start)
|
|
@ -8,7 +8,7 @@
|
|||
[
|
||||
{
|
||||
"name": "Python venv",
|
||||
"cmd": ["/home/gio/Code/VANA/VANA-python/normalize_subtitles/.pixi/envs/default/bin/python", "$file"],
|
||||
"cmd": ["/home/gio/Code/VANA/VANA-python/video_deepface2/.pixi/envs/default/bin/python", "$file"],
|
||||
"selector": "source.python",
|
||||
"file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)"
|
||||
}
|
||||
|
|
34875
VANA.sublime-workspace
34875
VANA.sublime-workspace
File diff suppressed because one or more lines are too long
BIN
database.sqlite
BIN
database.sqlite
Binary file not shown.
Loading…
Reference in New Issue