Exemplo n.º 1
0
  def testMJCFCamera(self):
    mjcf_root = mjcf.from_xml_string(_MJCF)
    physics = mjcf.Physics.from_mjcf_model(mjcf_root)

    camera = mjcf_root.find('camera', 'world')
    camera_observable = mjcf_observable.MJCFCamera(
        mjcf_element=camera, height=480, width=640, update_interval=7)
    self.assertEqual(camera_observable.update_interval, 7)
    camera_observation = camera_observable.observation_callable(physics)()
    np.testing.assert_array_equal(
        camera_observation, physics.render(480, 640, 'world'))
    self.assertEqual(camera_observation.shape,
                     camera_observable.array_spec.shape)
    self.assertEqual(camera_observation.dtype,
                     camera_observable.array_spec.dtype)

    camera_observable.height = 300
    camera_observable.width = 400
    camera_observation = camera_observable.observation_callable(physics)()
    self.assertEqual(camera_observable.height, 300)
    self.assertEqual(camera_observable.width, 400)
    np.testing.assert_array_equal(
        camera_observation, physics.render(300, 400, 'world'))
    self.assertEqual(camera_observation.shape,
                     camera_observable.array_spec.shape)
    self.assertEqual(camera_observation.dtype,
                     camera_observable.array_spec.dtype)

    with six.assertRaisesRegex(self, ValueError, 'expected an `mjcf.Element`'):
      mjcf_observable.MJCFCamera('world')
    with six.assertRaisesRegex(self, ValueError, 'expected an `mjcf.Element`'):
      mjcf_observable.MJCFCamera([camera])
    with six.assertRaisesRegex(self, ValueError, 'expected a <camera>'):
      mjcf_observable.MJCFCamera(mjcf_root.find('body', 'body'))
Exemplo n.º 2
0
 def testErrorIfSegmentationAndDepthBothEnabled(self):
     camera = mjcf.from_xml_string(_MJCF).find('camera', 'world')
     with self.assertRaisesWithLiteralMatch(
             ValueError,
             mjcf_observable._BOTH_SEGMENTATION_AND_DEPTH_ENABLED):
         mjcf_observable.MJCFCamera(mjcf_element=camera,
                                    segmentation=True,
                                    depth=True)
Exemplo n.º 3
0
 def testMJCFSegCamera(self):
   mjcf_root = mjcf.from_xml_string(_MJCF)
   physics = mjcf.Physics.from_mjcf_model(mjcf_root)
   camera = mjcf_root.find('camera', 'world')
   camera_observable = mjcf_observable.MJCFCamera(
       mjcf_element=camera, height=480, width=640, update_interval=7,
       segmentation=True)
   self.assertEqual(camera_observable.update_interval, 7)
   camera_observation = camera_observable.observation_callable(physics)()
   np.testing.assert_array_equal(
       camera_observation,
       physics.render(480, 640, 'world', segmentation=True))
   camera_observable.array_spec.validate(camera_observation)
Exemplo n.º 4
0
 def testMJCFCameraSpecs(self, camera_type, channels, dtype, minimum,
                         maximum):
     width = 640
     height = 480
     shape = (height, width, channels)
     expected_spec = specs.BoundedArray(shape=shape,
                                        dtype=dtype,
                                        minimum=minimum,
                                        maximum=maximum)
     mjcf_root = mjcf.from_xml_string(_MJCF)
     camera = mjcf_root.find('camera', 'world')
     observable_kwargs = {} if camera_type == 'rgb' else {camera_type: True}
     camera_observable = mjcf_observable.MJCFCamera(mjcf_element=camera,
                                                    height=height,
                                                    width=width,
                                                    update_interval=7,
                                                    **observable_kwargs)
     self.assertEqual(camera_observable.array_spec, expected_spec)