Example #1
0
def render_example(example_id, render_dir, input_dir, output_dir, texture_dir,
                   csv_file, shape, views):
    example_in_dir = os.path.join(input_dir, example_id)
    example_out_dir = os.path.join(output_dir, example_id)
    example_render_dir = os.path.join(render_dir, example_id)

    # Set obj file path
    try:
        obj = os.path.join(example_in_dir, 'models', 'model_normalized.obj')
    except:
        return False

    if os.path.isdir(example_out_dir):
        if len(os.listdir(example_out_dir)) == views:
            return False
        else:
            shutil.rmtree(example_out_dir)

    if not os.path.isdir(example_out_dir):
        os.makedirs(example_out_dir)

    if not os.path.isdir(example_render_dir):
        os.makedirs(example_render_dir)

    # Set texture images path
    if os.path.isdir(texture_dir):
        textures = [name for name in os.listdir(texture_dir)]
        textures.sort()
    else:
        raise ValueError('Invalid texture directory !')

    # redirect output to log file
    logfile = 'render.log'
    open(logfile, 'a').close()
    old = os.dup(1)
    sys.stdout.flush()
    os.close(1)
    os.open(logfile, os.O_WRONLY)

    textures = [name for name in os.listdir(texture_dir)]
    textures.sort()
    texture = textures[np.random.randint(0, len(textures))]
    texture_img = os.path.join(texture_dir, texture)

    # generate the synthetic training images and its multi-view reference images
    render_obj_grid(obj, example_render_dir, [512, 512], 30, 5, 1, 2, False,
                    None, None)
    render_obj_with_view(obj, example_out_dir, csv_file, texture_img, views,
                         shape)

    # disable output redirection
    os.close(1)
    os.dup(old)
    os.close(old)

    return True
Example #2
0
            obj = os.path.join(input_dir, cat, example,
                               '{}.obj'.format(model_name))

            # create output dir
            if model_name == 'model':
                example_out_dir = os.path.join(output_dir, cat, example)
            else:
                example_out_dir = os.path.join(output_dir, cat, example,
                                               model_name)
            if not os.path.isdir(example_out_dir):
                os.makedirs(example_out_dir)

            # redirect output to log file
            logfile = 'render.log'
            open(logfile, 'a').close()
            old = os.dup(1)
            sys.stdout.flush()
            os.close(1)
            os.open(logfile, os.O_WRONLY)

            # Render object without texture
            render_obj_grid(obj, example_out_dir, [512, 512], 30, 5, 1, 1.5,
                            False, None, None)

            # disable output redirection
            os.close(1)
            os.dup(old)
            os.close(old)

os.system("rm render.log")
Example #3
0
from render_utils import resize_padding, makeLamp, parent_obj_to_camera, clean_obj_lamp_and_mesh, render_obj_grid

model_dir = 'models'
render_dir = 'Renders_semi_sphere'

models = [name for name in os.listdir(model_dir) if name.endswith(".obj")]
models.sort()
for model in tqdm(models):
    obj = os.path.join(model_dir, model)
    out = os.path.join(render_dir, model.split(".")[0])
    if not os.path.isdir(out):
        os.makedirs(out)

    # redirect output to log file
    logfile = 'render.log'
    open(logfile, 'a').close()
    old = os.dup(1)
    sys.stdout.flush()
    os.close(1)
    os.open(logfile, os.O_WRONLY)

    # render object reference images
    render_obj_grid(obj, out, [512, 512], 30, 8, 2, 2, True, 'X', 'Z')

    # disable output redirection
    os.close(1)
    os.dup(old)
    os.close(old)

os.system("rm render.log")
Example #4
0
render_dir = 'Renders_semi_sphere'

cats = [name for name in os.listdir(model_dir)]
cats.sort()
for cat in tqdm(cats):
    cat_models = [name for name in os.listdir(os.path.join(model_dir, cat))]
    cat_models.sort()
    for model in tqdm(cat_models):
        obj = os.path.join(model_dir, cat, model)
        out = os.path.join(render_dir, cat, model.split(".")[0])
        if not os.path.isdir(out):
            os.makedirs(out)
        
        # redirect output to log file
        logfile = 'render.log'
        open(logfile, 'a').close()
        old = os.dup(1)
        sys.stdout.flush()
        os.close(1)
        os.open(logfile, os.O_WRONLY)
            
        # render object reference images
        render_obj_grid(obj, out, [512, 512], 30, 5, 1, 1.5, False, '-Y', 'Z')
        
        # disable output redirection
        os.close(1)
        os.dup(old)
        os.close(old)
        
os.system("rm render.log")