def test_set_rotation(self): for pos in self.camera_poses: rot = pos[1] # rotation param_str = '%.3f %.3f %.3f' % (rot[0], rot[1], rot[2]) cmd = 'vset /camera/0/rotation %s' % param_str response = client.request(cmd) self.assertEqual(response, 'ok') response = client.request('vget /camera/0/rotation') self.assertEqual(response, param_str, 'expect %s, got %s' % (param_str, response))
def test_location_limit(self): for pos in self.camera_poses: loc = pos[0] # location param_str = '%.3f %.3f %.3f' % (loc[0], loc[1], loc[2]) cmd = 'vset /camera/0/location %s' % param_str response = client.request(cmd) self.assertEqual(response, 'ok') response = client.request('vget /camera/0/location') self.assertEqual(response, param_str, 'expect %s, got %s' % (param_str, response)) # TODO: also try random positions # Will there be some invalid location that can not be set to? # Can I know the boundary of the world? for _ in range(5): param_str = '%.3f %.3f %.3f' % (random.randrange(100), random.randrange(100), random.randrange(100)) cmd = 'vset /camera/0/location %s' % param_str response = client.request(cmd) self.assertEqual(response, 'ok') response = client.request('vget /camera/0/location') print 'expect %s, got %s' % (param_str, response)
def test_objects(self): response = client.request('vget /objects') # _L.debug(response) self.assertTrue(testutil.validate_format(response)) objects = response.split(' ')[:10] self.assertTrue(len(objects) > 0) tasks = [] for objname in objects: tasks.append(['vget /object/%s/name' % objname, objname]) tasks.append(['vget /object/%s/color' % objname, testutil.skip]) # TODO: add a function to check regular expression testutil.run_tasks(self, client, tasks)
def test_objects(self): ''' Make sure the object list is the same as expected ''' response = client.request('vget /objects') response = response.strip() # TODO: remove this line self.assertTrue(validate_format(response)) objects = response.split(' ') self.assertTrue(len(objects) > 0) print 'Number of objects %d' % len(objects) tasks = [] for objname in objects: tasks.append(['vget /object/%s/name' % objname, objname]) tasks.append(['vget /object/%s/color' % objname, skip]) testutil.run_tasks(self, self.client, tasks)
client.connect() output_folder = 'unrealcv-files' def f(mode, ext): return os.path.join(output_folder, '%s.%s' % (mode, ext)) # Check if the connection is successfully established if not client.isconnected(): print 'UnrealCV server is not running. Run the game downloaded from http://unrealcv.github.io first.' else: mode_list = [ ('lit', 'png'), ('depth', 'png'), ('depth', 'exr'), ('object_mask', 'png'), ('debug', 'exr'), ] for (mode, ext) in mode_list: filename = client.request('vget /camera/0/%s %s' % (mode, f(mode, ext))) print '%s is saved to %s' % (mode, filename) # Switch the camera mode back to normal res = client.request('vset /viewmode lit') assert res == 'ok', res # Make sure operation is successful # Disconnect python client from the game client.disconnect()