From bfb3d38aba8649e4ad4e3ec3d23aa8152621d088 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Wed, 24 Aug 2022 02:12:49 +0200 Subject: image import, single music, video pages --- pictures.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 pictures.py (limited to 'pictures.py') diff --git a/pictures.py b/pictures.py new file mode 100755 index 0000000..b9f3095 --- /dev/null +++ b/pictures.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +import os +import numpy as np +import subprocess +import json + + +def descriptors(file): + npy = os.path.join( + os.path.dirname(file), + ".meta", + "descriptors", + os.path.basename(os.path.splitext(file)[0]) + ".npy", # TODO + ) + return np.load(npy, allow_pickle=False) + + +mail = "pdp8@pdp8.info" +cmd = "grep '3$' /home/ch/img/art/.meta/ratings|cut -f1" +favs = subprocess.check_output(cmd, shell=True, text=True).splitlines() +distances = {} +for fav in favs: + basename = os.path.basename(fav) + """ + out = os.path.join("/home/ch/pub/pictures/", basename) + cmd = "convert '" + fav + "' -strip -resize 1024x '" + out + "'" + os.system(cmd) + cmd = ( + "exiv2 -M'set Xmp.dc.creator " + + mail + + "' -M'set Xmp.dc.rights © " + + mail + + "' -M'set Xmp.dc.license http://creativecommons.org/licenses/by-sa/4.0/' -M'set Xmp.xmpRights.UsageTerms Creative Commons Attribution-ShareAlike 4.0 International License' -M'set Xmp.xmpRights.Marked True' -M'set Xmp.dc.description Original artwork available from " + + mail + + "' " + + out + ) + os.system(cmd) + """ + fav_d = descriptors(fav) + distances[basename] = {} + for img in favs: + if fav != img: + img_d = descriptors(img) + sim = np.dot(fav_d, img_d) / (np.linalg.norm(fav_d) * np.linalg.norm(img_d)) + img_basename = os.path.basename(img) + distances[basename][img_basename] = np.float64(1.0 - sim) +with open("/home/ch/pub/distances.js", "w") as f: + s = "distances = " + json.dumps(distances) + print(s, file=f) -- cgit v1.2.3