Commit d20f14fd authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira

Merge branch 'json' into 'master'

Add json annotation format support

See merge request !35
parents 06a10a02 a25d4217
Pipeline #14348 passed with stages
in 6 minutes and 46 seconds
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import os
import json
import logging
import os
logger = logging.getLogger(__name__)
_idiap_annotations = {
......@@ -51,6 +52,8 @@ def read_annotation_file(file_name, annotation_type):
* ``idiap``: The file contains enumerated annotations, one per line,
e.g.: ``1 key1_x key1_y``, and maybe some additional annotations like
gender, age, ...
* ``json``: The file contains annotations of any format, dumped in a
text json file.
Returns
......@@ -126,6 +129,8 @@ def read_annotation_file(file_name, annotation_type):
annotations['leye'] = ((annotations['leyeo'][0] + annotations['leyei'][0]) /
2., (annotations['leyeo'][1] + annotations['leyei'][1]) / 2.)
elif str(annotation_type) == 'json':
annotations = json.load(f)
else:
raise ValueError(
"The given annotation type '%s' is not known, choose one of ('eyecenter', 'named', 'idiap')" % annotation_type)
......
{
"leye": [
20,
40
],
"pose": 30,
"reye": [
20,
10
]
}
......@@ -75,7 +75,7 @@ def test01_annotations():
# tests the annotation IO functionality provided by this utility class
# check the different annotation types
for annotation_type in ('eyecenter', 'named', 'idiap'):
for annotation_type in ('eyecenter', 'named', 'idiap', 'json'):
# get the annotation file name
annotation_file = bob.io.base.test_utils.datafile(
"%s.pos" % annotation_type, 'bob.db.base')
......@@ -85,8 +85,8 @@ def test01_annotations():
# check
assert 'leye' in annotations
assert 'reye' in annotations
assert annotations['leye'] == (20, 40)
assert annotations['reye'] == (20, 10)
assert tuple(annotations['leye']) == (20, 40), annotations['leye']
assert tuple(annotations['reye']) == (20, 10), annotations['reye']
if annotation_type == 'named':
assert 'pose' in annotations
assert annotations['pose'] == 30
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment