Commit ba86a670 authored by André Anjos's avatar André Anjos 💬

Multiple fixes and improvements

parent 2a1ddafc
Pipeline #26416 failed with stages
in 13 minutes and 13 seconds
This diff is collapsed.
......@@ -6,6 +6,25 @@
import os
import six
import json
import fnmatch
def uniq(seq, idfun=None):
'''Order preserving uniq for lists
See: https://www.peterbe.com/plog/uniqifiers-benchmark
'''
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result
def save(data, fp, backup=False):
......@@ -35,7 +54,7 @@ def save(data, fp, backup=False):
fp = open(fp, 'w')
json.dump(data, fp)
json.dump(data, fp, indent=2)
def load(fp):
......@@ -59,3 +78,25 @@ def load(fp):
fp = open(fp, 'r')
return json.load(fp)
def find(basedir, name):
"""Finds all files on basedir that match the given name
Parameters:
basedir (str): Base path to search for files
name (str): A string, maybe a glob, with an expression to search for
Returns:
list: List of paths that match the given name glob
"""
retval = []
for root, dirs, files in os.walk(basedir):
matched = fnmatch.filter(files, name)
retval += [os.path.join(root, k) for k in matched]
retval.sort()
return retval
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
import os
import click
from bob.extension.scripts.click_helper import verbosity_option, \
ResourceOption
......@@ -8,24 +10,27 @@ from bob.extension.scripts.click_helper import verbosity_option, \
@click.command(epilog='''
Examples:
Annotate two images, results in the directory `./tmp':
Annotate all images (ending in ".png") from "images" directory (scanned
recursively), put annotations in the current work directory, following the
same directory structure:
$ bob annotate -v --output=./tmp A/B/img1.png A/C/img2.png
$ bob annotate -v images
Annotate all images, results in the directory `./tmp':
Annotate all images (ending in ".png") from "images" directory (scanned
recursively), put annotations in the "annotations" directory (that is created
if it does not already exists), following the same directory structure:
$ bob annotate -v --output=./tmp A/*/*.png
$ bob annotate -v images annotations
Annotate the image of Lena, with a 2x zoom, get the result in `lena.txt`:
Annotate the image of Lena, with a 2x zoom, get the result in `lena.json`:
$ bob annotate -v --zoom=2 bob/ip/annotator/data/lena.jpg
$ bob annotate -v --zoom=2 bob/ip/annotator/data -e '.jpg'
Visualize annotations for Lena, with a 0.5x zoom, from the file `lena.txt`:
Visualize annotations for Lena, with a 0.5x zoom, from the file `lena.json`:
$ bob annotate -v --readonly --zoom=0.5 bob/ip/annotator/data/lena.jpg
$ bob annotate -v --readonly --zoom=0.5 bob/ip/annotator/data
''')
@verbosity_option(cls=ResourceOption)
@click.argument('images', required=False, type=click.Path(file_okay=False,
@click.argument('images', required=True, type=click.Path(file_okay=False,
dir_okay=True, writable=False, readable=True, exists=True))
@click.argument('annotations', required=False, type=click.Path(file_okay=False,
dir_okay=True, writable=True, readable=True, exists=False))
......@@ -39,8 +44,14 @@ Examples:
'setting to adjust window size on your screen')
@click.option('-r', '--readonly/--no-readonly', default=False,
help='Set this avoid any changes to existing annotations')
def annotate(images, annotations, extension, zoom, readonly):
@verbosity_option(cls=ResourceOption)
def annotate(images, annotations, extension, zoom, readonly, verbose):
"""A TkInter-based keypoint annotation tool for images"""
if annotations is None:
# if the user did not specify location, use the current directory
annotations = os.path.realpath(os.curdir)
from ..gui import AnnotatorApp
app = AnnotatorApp(images, annotations, readonly, zoom)
app = AnnotatorApp(images, extension, annotations, readonly, zoom)
app.mainloop()
This diff is collapsed.
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