Esempio n. 1
0
def save_substance_grid(substance_id, outdir, show_progress=False):
    try:
        os.makedirs(outdir)
    except OSError as e:
        print e

    substance = ShapeSubstance.objects.get(id=substance_id)
    print 'substance: %s' % substance
    qset = MaterialShape.objects.filter(substance_id=substance_id,
                                        photo__inappropriate=False)
    if not qset.exists():
        print 'no shapes for %s' % substance
        return

    from common.utils import create_image_grid_qset
    out = create_image_grid_qset(qset,
                                 'image_square_300',
                                 ncols=20,
                                 size=300,
                                 max_qset_size=10 * 20 * 16 / 9,
                                 downsample_ratio=2,
                                 show_progress=show_progress)

    outname = os.path.join(
        outdir,
        substance.name.replace(' - ', '-').replace(' ', '-').replace(
            '/', '-').replace("'", '') + '.png')
    with open(outname, 'wb') as outfile:
        save_image(out, outfile, format="PNG")
Esempio n. 2
0
def save_substance_grid(substance_id, outdir, show_progress=False):
    try:
        os.makedirs(outdir)
    except OSError as e:
        print e

    substance = ShapeSubstance.objects.get(id=substance_id)
    print 'substance: %s' % substance
    qset = MaterialShape.objects.filter(
        substance_id=substance_id, photo__inappropriate=False)
    if not qset.exists():
        print 'no shapes for %s' % substance
        return

    from common.utils import create_image_grid_qset
    out = create_image_grid_qset(qset, 'image_square_300',
                                 ncols=20, size=300,
                                 max_qset_size=10 * 20 * 16 / 9,
                                 downsample_ratio=2,
                                 show_progress=show_progress)

    outname = os.path.join(outdir, substance.name
                           .replace(' - ', '-').replace(' ', '-')
                           .replace('/', '-').replace("'", '') + '.png')
    with open(outname, 'wb') as outfile:
        save_image(out, outfile, format="PNG")
Esempio n. 3
0
def save_texture_grid(outdir, max_qset_size=None, ncols=25, show_progress=False, category=None):
    try:
        os.makedirs(outdir)
    except OSError as e:
        print e

    qset = ShapeRectifiedNormalLabel.objects \
        .filter(shape__photo__license__publishable=True,
                shape__correct=True, shape__planar=True,
                shape__rectified_normal_id=F('id')) \
        .order_by('-shape__num_vertices')

    if category:
        qset = qset.filter(shape__substance__name=category)

    if not qset.exists():
        print 'no textures found'
        return

    if max_qset_size:
        qset = qset[:max_qset_size]

    from common.utils import create_image_grid_qset
    out = create_image_grid_qset(qset, 'image_rectified_square_300',
                                 ncols=ncols, size=256,
                                 downsample_ratio=1,
                                 show_progress=show_progress)

    if category:
        outname = os.path.join(outdir, '%s.png' % category.lower())
    else:
        outname = os.path.join(outdir, 'textures.png')
    with open(outname, 'wb') as outfile:
        save_image(out, outfile, format="PNG")
Esempio n. 4
0
def save_texture_grid(outdir,
                      max_qset_size=None,
                      ncols=25,
                      show_progress=False,
                      category=None):
    try:
        os.makedirs(outdir)
    except OSError as e:
        print e

    qset = ShapeRectifiedNormalLabel.objects \
        .filter(shape__photo__license__publishable=True,
                shape__correct=True, shape__planar=True,
                shape__rectified_normal_id=F('id')) \
        .order_by('-shape__num_vertices')

    if category:
        qset = qset.filter(shape__substance__name=category)

    if not qset.exists():
        print 'no textures found'
        return

    if max_qset_size:
        qset = qset[:max_qset_size]

    from common.utils import create_image_grid_qset
    out = create_image_grid_qset(qset,
                                 'image_rectified_square_300',
                                 ncols=ncols,
                                 size=256,
                                 downsample_ratio=1,
                                 show_progress=show_progress)

    if category:
        outname = os.path.join(outdir, '%s.png' % category.lower())
    else:
        outname = os.path.join(outdir, 'textures.png')
    with open(outname, 'wb') as outfile:
        save_image(out, outfile, format="PNG")