Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(
        description='Generate image signatures for files in database.')
    add_common_command_line_arguments(parser)
    parser.add_argument('-T', '--threads', metavar='THREADS',
                        nargs=1,
                        default=[DEFAULT_THREADS],
                        help=("Specify the number of threads to use. 'C' is " +
                              "substitued for the number of cores. " +
                              "Default is %r. Examples: '1', '10' or '1.5C'.")
                        % DEFAULT_THREADS)
    parser.add_argument('-s', '--min-similarity',
                        default=0.8,
                        help='require at least this image similarity')
    parser.add_argument('-S', '--signatures',
                        nargs=1,
                        default="3",
                        help=("Which signatures should be computed. " +
                              "Default is %r. Examples: '1,2', '3' or 'all'.")
                        % "3")

    args = parser.parse_args()
    repo = dfr.db.Database(args.db[0])
    signatures = args.signatures[0]
    if signatures == "all":
        signatures = [1, 2, 3, 4, 5]
    else:
        signatures = [int(x) for x in signatures.split(",")]
    threads = eval_thread_config(args.threads[0])
    indexer = ImageIndexer(repo, signatures, parallel_threads=threads)
    indexer.run()
    sim = float(args.min_similarity)
    for iht in signatures:
        comperator = ImageComperator(repo, iht)
        comperator.ensure_that_differences_are_calculated(sim)
    def test_nothing_to_index(self):
        with TempDir(0) as tmpdir:
            db_fn = join(tmpdir.name, 'files.sdb')
            the_db = db.Database(db_fn, verbose=0)

            indexer = ImageIndexer(the_db, [1], verbose_progress=0)
            indexer.run()

            self.assertTrue(len(the_db.content.find()) == 0)