/
image_tags.py
54 lines (41 loc) · 1.38 KB
/
image_tags.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
49
50
51
52
from subprocess import Popen, PIPE
#import geo_tags
import tracer as trace
from main_config import exiftool
@trace.enter
def write_tags_to_image_via_et(image, tags):
options = ['-codedcharacterset=UTF8',
'-charset', 'iptc=cp1251',
'-charset', 'filename=cp1251',
'{0}'.format(image)]
for tag in tags:
if tag.lower() == "keywords":
for i in tags[tag]:
options.append('-iptc:{0}={1}'.format(tag, i))
else:
options.append('-iptc:{0}={1}'.format(tag, tags[tag]))
cmd = [exiftool]
cmd.extend(options)
trace.debug('Cmd: {0}'.format(cmd))
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
trace.debug('stdout: {0}; stderr: {1}'.format(out, err))
if proc.returncode:
trace.error('Unexpected return code: {0}; cmd: {1}'.format(proc.returncode, cmd))
return proc.returncode
#@trace.enter
#def get_tags(image):
# #get_geo_tags_in_et_format is missing geo_tags
# tags = geo_tags.get_geo_tags_in_et_format(image)
# if 'keywords' in tags:
# tags['keywords'].extend(people_detection.get_keywords(image))
# else:
# tags['keywords'] = people_detection.get_keywords(image)
#
# return tags
#
#path = "D:/_test/control_set_01"
#import exiftool
#
#for image in os.listdir(path):
# get_tags(os.path.join(path, image))