Using shotwell to label images
I needed to label a lot of images into 4 classes. Using the ratings of shotwell this can be really fast.
Pressing 1
to 5
to set a rating on an image.
The next step was to get the ratings for later use as labels in machine learning.
Because shotwell stores its data in a sqlite database we only need some lines of Python to get the labels:
import csv import os.path import sqlite3 import sys # location of shotwell sqlite file db_file = os.path.join(os.environ.get("HOME"), '.local/share/shotwell', 'data', 'photo.db') conn = sqlite3.connect(db_file) c = conn.cursor() rows = c.execute('SELECT filename, rating FROM phototable WHERE rating > 0 ORDER BY filename;') csvwriter = csv.writer(sys.stdout, delimiter=';') csvwriter.writerow(["filename", "rating"]) for (filename, rating) in rows: csvwriter.writerow([os.path.basename(filename), rating])
Only the ratings bigger than 0 are selected. The CSV is written to stdout by default.