Commit 4900180d authored by Manuel Günther's avatar Manuel Günther
Browse files

Removed unnecessary prints; changed function to retrieve original file names...

Removed unnecessary prints; changed function to retrieve original file names to overwrite base class (note: return type is different)
parent b7e2fb91
......@@ -115,7 +115,6 @@ def annotations(args):
output = null()
a = db.annotations(args.id)
# k = sorted(a.keys(), cmp=lambda x,y : cmp(int(x.split('.')[1]), int(y.split('.')[1])))
k = sorted(a.keys(), key=lambda x : int(x.split('.')[1]))
for i in k:
output.write("\n%s "%i)
......
......@@ -529,8 +529,6 @@ class Database(bob.db.verification.utils.SQLiteDatabase):
query = self.query(Directory).filter(Directory.id == directory_id)
assert query.count() == 1
video = query.first()
if video.client is None:
print video.path
annotation_file = os.path.join(self.original_directory, video.client.name + self.annotation_extension)
annots = {}
......@@ -554,14 +552,27 @@ class Database(bob.db.verification.utils.SQLiteDatabase):
return annots
def original_image_list(self, directory):
"""Returns the list of original image names for the given ``Directory``."""
# get original filename expression for the database
file_name_filter = self.original_file_name(directory, check_existence = False)
def original_file_name(self, directory, check_existence = None):
"""Returns the list of original image names for the given ``directory``, sorted by frame number.
In opposition to other bob databases, here a **list** of file names is returned.
Keyword arguments:
directory : :py:class:`bob.db.youtube.Directory`
The Directory object to retrieve the list of file names for
check_existence : bool
Shall the existence of the files be checked?
"""
# get original filename expression for the directory
file_name_filter = bob.db.verification.utils.SQLiteDatabase.original_file_name(self, directory, check_existence = False)
# list the data
import glob
file_name_list = glob.glob(file_name_filter)
if check_existence and not file_name_list:
raise ValueError("No image was found in directory '%s'. Please check the original directory '%s'." % (file_name_filter, self.original_directory))
# get the file names sorted by id
return sorted(file_name_list, key = lambda x: int(x.split('.')[-2]))
......
......@@ -219,20 +219,20 @@ def test_annotations():
# Tests the unrestricted configuration
db = bob.db.youtube.Database(original_directory = dir)
# get all files
files = random.sample(list(db.objects()), 100) # if the random sampling fails, please remove it to get all files checked.
dirs = random.sample(list(db.objects()), 100) # if the random sampling fails, please remove it to get all files checked.
# iterate over all files
for file in files:
for dir in dirs:
# get the files
import glob
images = glob.glob(db.original_file_name(file, check_existence = False))
images = db.original_file_name(dir)
# get the annotations for 10 images
annotations = db.annotations(file.id)
annotations = db.annotations(dir.id)
# check that images and annotations are from the same image ID
assert len(images) == len(annotations)
# check a subset of the annotations
image_names = sorted(set([os.path.basename(images[random.randrange(len(images))]) for i in range(10)]))
annotations = db.annotations(file.id, image_names = image_names)
annotations = db.annotations(dir.id, image_names = image_names)
assert len(annotations) <= 10
for i, image_id in enumerate(sorted(annotations.keys())):
assert image_id == image_names[i]
......
......@@ -92,10 +92,14 @@ Since the videos are stored as a list of frames, the ``Directory`` interface wil
.. .. doctest::
.. code-block:: python
>>> file_names = db.original_image_list(d)
>>> file_names = db.original_file_name(d)
>>> print (file_names[0]) #doctest:+SKIP
[...]/AJ_Cook/0/0.123.jpg
.. warning::
Please note that -- in opposition to other bob.db database interfaces -- the ``original_file_name`` function returns a **list** of file names.
Likewise, ``original_file_names`` returns a list of lists of file names.
Finally, bounding boxes are annotated in the images.
To get these bounding boxes for a specific (set of) images, you can use the :py:func:`bob.db.youtube.Database.annotations` function.
......
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