-
Notifications
You must be signed in to change notification settings - Fork 0
/
volumes-colors-to-csv.py
48 lines (34 loc) · 1.06 KB
/
volumes-colors-to-csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#-*- coding: utf-8 -*-
# volumes.lu
# dominant colour from image to svg
# config
csv_filepath = 'csv/volumes-le-havre.csv'
csv_output_filepath = 'csv/volumes-le-havre-dominant.csv'
# imports
import csv
import sys
sys.path.insert(0, 'libs/dominant_image_colour')
from dominant_colour import most_frequent_colour
# pip install Pillow
from PIL import Image
# open csv
csv_file = open(csv_filepath, "rt")
csv_output_file = open(csv_output_filepath, "w+")
reader = csv.reader(csv_file, delimiter=';', quotechar ='"')
writer = csv.writer(csv_output_file, delimiter=';', quotechar ='"')
for row_idx, row in enumerate(reader):
# fetch data from csv
publisher = row[0]
title = row[1].replace('&', '&')
book_ref = row[5]
img_path = "./couvs/{}.jpg".format(book_ref)
# output dominant color to csv
im = Image.open(img_path)
color = most_frequent_colour(im)
rgb ='rgb{}'.format(color)
print ("{}, {}: {}".format(publisher, title, rgb))
row.append(rgb)
writer.writerow(row)
print('====')
csv_file.close()
csv_output_file.close()