Esempio n. 1
0
    def test_set_camera_intrisics(self):
        # overwrite parameters
        self._cam_info.intrinsic = np.array([390, 390, 320, 240])
        self._cam_info.intrinsics_conversion_mode = 'fov'
        K_test = np.asarray([[2666.67, 0, 960], [0, 2666.67, 540], [0, 0, 1]])
        # set camera and get matrix
        camera.set_camera_info(bpy.context.scene, self._cam.data,
                               self._cam_info)
        K = np.asarray(
            camera.get_calibration_matrix(bpy.context.scene, self._cam.data))
        # test
        npt.assert_almost_equal(
            K_test,
            K,
            decimal=2,
            err_msg=
            'Error while setting camera from intrinsics with conv. mode "fov"')

        # overwrite parameters
        self._cam_info.intrinsics_conversion_mode = 'mm'
        K_test = np.asarray([[2666.67, 0, 960], [0, 2666.67, 540], [0, 0, 1]])
        # set camera and get amtrix
        camera.set_camera_info(bpy.context.scene, self._cam.data,
                               self._cam_info)
        K = np.asarray(
            camera.get_calibration_matrix(bpy.context.scene, self._cam.data))
        # test
        npt.assert_almost_equal(
            K_test,
            K,
            decimal=2,
            err_msg=
            'Error while setting camera from intrinsics with conv. mode "mm"')
Esempio n. 2
0
    def setup_cameras(self):
        """Setup camera, and place at a default location"""
        # get scene
        scene = bpy.context.scene

        # add camera, update with calibration data, and make it active for the scene
        bpy.ops.object.add(type='CAMERA', location=(0.66, -0.66, 0.5))
        self.cam_obj = bpy.context.object
        self.cam = self.cam_obj.data
        camera_utils.set_camera_info(scene, self.cam, self.config.camera_info)

        # re-set camera and set rendering size
        bpy.context.scene.camera = self.cam_obj
        if (self.config.camera_info.width >
                0) and (self.config.camera_info.height > 0):
            bpy.context.scene.render.resolution_x = self.config.camera_info.width
            bpy.context.scene.render.resolution_y = self.config.camera_info.height

        # look at center
        blnd.look_at(self.cam_obj, Vector((0.0, 0.0, 0.0)))

        # get effective extrinsics
        effective_intrinsic = camera_utils.get_intrinsics(scene, self.cam)
        # store in configuration (and backup original values)
        if self.config.camera_info.intrinsic is not None:
            self.config.camera_info.original_intrinsic = self.config.camera_info.intrinsic
        else:
            self.config.camera_info.original_intrinsic = ''
        self.config.camera_info.intrinsic = list(effective_intrinsic)
 def test_set_camera_hfov(self):
     "test setting up camera with field of view"
     # overwrite parameters
     self._cam_info.hfov = 78.694
     K_test = np.asarray([[73.2517014, 0, 960], [0, 73.2517014, 540], [0, 0, 1]])
     # set camera and get matrix
     camera.set_camera_info(bpy.context.scene, self._cam.data, self._cam_info)
     K = np.asarray(camera.get_calibration_matrix(bpy.context.scene, self._cam.data))
     # test
     npt.assert_almost_equal(K_test, K, err_msg='Error while setting camera from hfov')
 def test_set_camera_swfl(self):
     "test setting up camera with sensor-width and focal length"
     # overwrite parameters
     self._cam_info.sensor_width = 1.89882275303
     self._cam_info.focal_length = 1.158
     K_test = np.asarray([[1170.91, 0, 960], [0, 1170.91, 540], [0, 0, 1]])
     # set camera and get matrix
     camera.set_camera_info(bpy.context.scene, self._cam.data, self._cam_info)
     K = np.asarray(camera.get_calibration_matrix(bpy.context.scene, self._cam.data))
     # test
     npt.assert_almost_equal(K_test, K, decimal=2, err_msg='Error while setting camera from swfl')
Esempio n. 5
0
    def setup_cameras(self):
        """Set up all cameras.

        Note that this does not select a camera for which to render. This will
        be selected elsewhere.
        """
        scene = bpy.context.scene
        for cam in self.config.scene_setup.cameras:
            # first get the camera name. This depends on the scene (blend file)
            cam_name = self.get_camera_name(cam)
            # select the camera. Blender often operates on the active object, to
            # make sure that this happens here, we select it
            blnd.select_object(cam_name)
            # modify camera according to the intrinsics
            blender_camera = bpy.data.objects[cam_name].data
            # set the calibration matrix
            camera_utils.set_camera_info(scene, blender_camera, self.config.camera_info)