def _get_attribute(self, cam_pose, attribute_name): """ Returns the value of the requested attribute for the given object. :param cam_pose: The mesh object. :param attribute_name: The attribute name. Type: string. :return: The attribute value. """ cam, cam_ob = cam_pose if attribute_name == "fov_x": return cam.angle_x elif attribute_name == "fov_y": return cam.angle_y elif attribute_name == "shift_x": return cam.shift_x elif attribute_name == "shift_y": return cam.shift_y elif attribute_name == "half_fov_x": return cam.angle_x * 0.5 elif attribute_name == "half_fov_y": return cam.angle_y * 0.5 elif attribute_name == "cam_K": return [[x for x in c] for c in CameraUtility.get_intrinsics_as_K_matrix()] else: return super()._get_attribute(cam_ob, attribute_name)
def _get_frame_camera(self): """ Returns camera parameters for the active camera. """ return { 'cam_K': np.hstack(CameraUtility.get_intrinsics_as_K_matrix()).tolist(), 'depth_scale': self.depth_scale }
def _write_camera(self): """ Writes camera.json into dataset_dir. """ width = bpy.context.scene.render.resolution_x height = bpy.context.scene.render.resolution_y cam_K = CameraUtility.get_intrinsics_as_K_matrix() camera = { 'cx': cam_K[0][2], 'cy': cam_K[1][2], 'depth_scale': self.depth_scale, 'fx': cam_K[0][0], 'fy': cam_K[1][1], 'height': height, 'width': width } save_json(self.camera_path, camera) return
def get_cam_attribute( cam_ob: bpy.context.scene.camera, attribute_name: str, local_frame_change: Union[None, List[str]] = None, world_frame_change: Union[None, List[str]] = None) -> Any: """ Returns the value of the requested attribute for the given object. :param cam_ob: The camera object. :param attribute_name: The attribute name. :param local_frame_change: Can be used to change the local coordinate frame of matrices. Default: ["X", "Y", "Z"] :param world_frame_change: Can be used to change the world coordinate frame of points and matrices. Default: ["X", "Y", "Z"] :return: The attribute value. """ if attribute_name == "fov_x": return CameraUtility.get_fov()[0] elif attribute_name == "fov_y": return CameraUtility.get_fov()[1] elif attribute_name == "shift_x": return cam_ob.data.shift_x elif attribute_name == "shift_y": return cam_ob.data.shift_y elif attribute_name == "half_fov_x": return CameraUtility.get_fov()[0] * 0.5 elif attribute_name == "half_fov_y": return CameraUtility.get_fov()[1] * 0.5 elif attribute_name == "cam_K": return [[x for x in c] for c in CameraUtility.get_intrinsics_as_K_matrix()] else: if attribute_name == "cam2world_matrix": return WriterUtility.get_common_attribute( cam_ob, "matrix_world", local_frame_change, world_frame_change) else: return WriterUtility.get_common_attribute( cam_ob, attribute_name, local_frame_change, world_frame_change)
def get_cam_attribute( cam_ob: bpy.context.scene.camera, attribute_name: str, destination_frame: Union[List[str], None] = None) -> Any: """ Returns the value of the requested attribute for the given object. :param cam_ob: The camera object. :param attribute_name: The attribute name. :param destination_frame: Used to transform camera to blender coordinates. Default: ["X", "Y", "Z"] :return: The attribute value. """ if attribute_name == "fov_x": return cam_ob.data.angle_x elif attribute_name == "fov_y": return cam_ob.data.angle_y elif attribute_name == "shift_x": return cam_ob.data.shift_x elif attribute_name == "shift_y": return cam_ob.data.shift_y elif attribute_name == "half_fov_x": return cam_ob.data.angle_x * 0.5 elif attribute_name == "half_fov_y": return cam_ob.data.angle_y * 0.5 elif attribute_name == "cam_K": return [[x for x in c] for c in CameraUtility.get_intrinsics_as_K_matrix()] else: if destination_frame is None: destination_frame = ["X", "Y", "Z"] if attribute_name == "cam2world_matrix": return WriterUtility.get_common_attribute( cam_ob, "matrix_world", destination_frame) else: return WriterUtility.get_common_attribute( cam_ob, attribute_name, destination_frame)