Exemplo n.º 1
0
def index_at_multiple_scales(
    codebook_dir,
    min_scale,
    max_scale,
    height_aspect,
    width_aspect,
    vectorization_factor=1,
    precompute_target=None,
    use_stabilization=True,
    stabilization_threshold=0.85,
    randomness=0.0,
    caching=True,
    use_detect_faces=True,
):
    scale2index = {}
    scale2mosaic = {}
    count = 0
    scales = range(min_scale, max_scale + 1, 1)
    aspect_ratio = height_aspect / float(width_aspect)

    with tqdm(total=len(scales)) as pbar:
        for scale in scales:
            print("Indexing scale=%d..." % scale)
            h, w = compute_hw(scale, height_aspect, width_aspect)
            tile_index, _, tile_images = index_images(
                paths='%s/*.jpg' % codebook_dir,
                aspect_ratio=aspect_ratio,
                height=h,
                width=w,
                vectorization_scaling_factor=vectorization_factor,
                caching=True,
                use_detect_faces=use_detect_faces,
            )
            scale2index[scale] = (tile_index, tile_images)

            # then precompute the mosaic
            h, w = compute_hw(scale, height_aspect, width_aspect)

            # mosaic-ify & show it
            if precompute_target is not None:
                mosaic, _, _ = mosaicify(
                    precompute_target,
                    h,
                    w,
                    tile_index,
                    tile_images,
                    use_stabilization=use_stabilization,
                    stabilization_threshold=stabilization_threshold,
                    randomness=randomness)
                scale2mosaic[scale] = mosaic

            count += 1
            pbar.update(1)

    return scale2index, scale2mosaic
Exemplo n.º 2
0
# constants
height_aspect = 4
width_aspect = 3
target_image = cv2.imread(args.target)

# index
scale2index = {}
scales = range(args.min_scale, args.max_scale + 1, 1)
dimensions = []
global_timings = defaultdict(list)
num_tiles = []

for scale in scales:
    print("Indexing scale=%d..." % scale)
    h, w = compute_hw(scale, height_aspect, width_aspect)
    tile_index, _, tile_images = index_images(
        paths='%s/*.jpg' % args.codebook_dir,
        aspect_ratio=height_aspect / float(width_aspect),
        height=h,
        width=w,
        caching=True,
    )
    scale2index[scale] = (tile_index, tile_images)

    # then precompute the mosaic
    h, w = compute_hw(scale, height_aspect, width_aspect)
    dims = h * w * 3

    # mosaic-ify & show it
    _, rect_starts, timings = mosaicify(target_image,