Exemplo n.º 1
0
 def import_testing_object(self):
     object_name = 'test_cube'
     object_path = src_dir + "/test/test_objects/" + object_name + ".obj"
     obj = Object(object_path, 'random', 'random', 'random', 420)
     obj.randomize_object(420)
     self.blender.setup_object(obj)
     return [bpy.data.objects[1], obj, object_name]
Exemplo n.º 2
0
 def test_random_orientation(self):
     random_object = Object("name", 'random', 'random', 'random', 420)
     random_object.randomize_object(420)
     [x, y, z] = random_object.orientation
     np.random.seed(self.seed)
     self.assertEquals(np.random.uniform(low=0, high=360) * np.pi / 180, x)
     self.assertEquals(np.random.uniform(low=0, high=360) * np.pi / 180, y)
     self.assertEquals(np.random.uniform(low=0, high=360) * np.pi / 180, z)
Exemplo n.º 3
0
 def test_random_color(self):
     random_object = Object("name", 'random', 'random', 'random', 420)
     random_object.randomize_object(420)
     [r, g, b, a] = random_object.color
     np.random.seed(self.seed)
     self.assertEquals(np.random.uniform(low=0.0, high=1.0), r)
     self.assertEquals(np.random.uniform(low=0.0, high=1.0), g)
     self.assertEquals(np.random.uniform(low=0.0, high=1.0), b)
Exemplo n.º 4
0
 def test_random_location(self):
     random_object = Object("name", 'random', 'random', 'random', 420)
     random_object.randomize_object(420)
     [x, y, z] = random_object.location
     np.random.seed(self.seed)
     self.assertEquals(np.random.uniform(low=-0.5, high=0.5), x)
     self.assertEquals(np.random.uniform(low=-0.5, high=0.5), y)
     self.assertEquals(1, z)
 def test_crush_model(self):
     BlenderTestCase.import_testing_object(self)
     obj = Object(src_dir + '/test/test_objects/test_cube.obj', 'random',
                  'random', 'random', 420)
     self.crush.crush_model(obj, self.temporary_path)
     self.assertEqual(
         True,
         Path(self.temporary_path + bpy.data.objects[1].name +
              '.obj').is_file())
Exemplo n.º 6
0
    def test_change_mtl(self):
        # Create object
        test_object = Object("name", "random", "random", "random", 420)

        # Setup object since it requires an external file to be edited
        file_to_edit = pathlib.Path("./test/test_objects/test_cube.mtl")
        test_object.change_mtl(file_to_edit, "TestDoesNotExist.png", 12)
        # Verify initial map_Kd
        assert read_mtl_map_kd(file_to_edit) == "map_Kd TestDoesNotExist.png\n"

        # Change map_Kd to test and assert
        test_object.change_mtl(file_to_edit, "NewSkin.png", 12)
        assert read_mtl_map_kd(file_to_edit) == "map_Kd NewSkin.png\n"
Exemplo n.º 7
0
    def test_randomize_skin(self):
        # Create object
        random_object = Object("./test/test_objects/cube/random_cube.obj",
                               "random", "random", "random", 420)

        # Setup object since it requires an external file to be edited
        file_to_edit = pathlib.Path("./test/test_objects/cube/random_cube.mtl")
        random_object.change_mtl(file_to_edit, "TestDoesNotExist.png", 12)
        # Verify initial map_Kd
        assert read_mtl_map_kd(file_to_edit) == "map_Kd TestDoesNotExist.png\n"

        src_dir = "./test/test_objects/cube"
        random_object.randomize_skin(src_dir)

        assert read_mtl_map_kd(file_to_edit) == 'map_Kd NewSkin.png\n'
Exemplo n.º 8
0
 def test_normal_setup(self):
     normal_object = Object("name", [1, 2, 3], [4, 5, 6], [7, 8, 9], 420)
     self.assertEqual("name", normal_object.path)
     self.assertEqual([1, 2, 3], normal_object.location)
     self.assertEqual([4, 5, 6], normal_object.orientation)
     self.assertEqual([7, 8, 9], normal_object.color)
Exemplo n.º 9
0
def main(args):  # noqa: CFQ001
    """
    Main method of our code.
    Sets the paths of background and object.
    :param args: arguments used for parsing to values.
    :return: time_data: a dictionary with timestamps of the different stages of the pipeline
    """
    total_start_time = time.time()

    parser = Parser()

    # Load the config file for camera and lights
    configuration = parser.parse_long_term_configuration(pathlib.Path(
        src_dir + r"/configuration.yaml"))

    # Parse arguments provided as input by user
    args = parser.parse_args(args)

    # Load objects
    if args.reuse_crushes:
        material_dirs = list(map(lambda x: list(pathlib.Path(src_dir + r'/Crushed Models/' +
                                                             x).glob('**/*.obj')), args.materials))
    else:
        material_dirs = list(map(lambda x: list(pathlib.Path(src_dir + r'/Models/' + x).glob(
            '**/*.obj')), args.materials))

    # List of the models
    models = [list(map(lambda path: Object(str(
        path), 'random', 'random', 'random', None), material)) for material in material_dirs]

    # Calculate number of objects per material based on proportions
    number_of_objects = list(map(lambda x: int(round(
        args.objects_per_image * (x / 100))), args.proportions))

    objects = make_object_selection(args, number_of_objects, models)

    if not args.only_crush:
        # Setup scene
        scene = Scene(configuration['camera']['location'], configuration['camera']['rotation'],
                      configuration['light']['location'], configuration['light']['energy'],
                      configuration['light']['type'])
        scene.add_background(args.background, None)

        # Render images
        image_object_bboxes = render(args, configuration['render'], scene, objects)

        # Write info file
        write_file(configuration['info_json'],
                   (configuration['render']['res_width'], configuration['render']['res_height']),
                   'info', args.image_count, image_object_bboxes)

    time_data['total'] = time.time() - total_start_time

    # Print time data
    print('Total Time: ' + str(time_data['total']))
    print('Object Creation Time: ' + str(time_data['object_creation_time']))
    if not args.only_crush:
        print('Object Setup Time: ' + str(time_data['object_setup_time']))
        for i in range(args.image_count):
            print('Image ' + str(i) + ' Time: ' + str(time_data['image_' + str(i)]))

    # To be displayed on the server page
    return time_data