def add_cameras(
    cameras,
    parent_collection,
    add_background_images=False,
    add_image_planes=False,
    add_depth_maps_as_point_cloud=True,
    convert_camera_coordinate_system=True,
    camera_collection_name="Cameras",
    image_plane_collection_name="Image Planes",
    depth_map_collection_name="Depth Maps",
    camera_scale=1.0,
    image_plane_transparency=0.5,
    add_image_plane_emission=True,
    depth_map_point_size=1,
    use_default_depth_map_color=False,
    depth_map_default_color=(1.0, 0.0, 0.0),
    depth_map_display_sparsity=10,
    depth_map_id_or_name_str="",
    op=None,
):
    """Add a set of reconstructed cameras to Blender's 3D view port."""
    log_report("INFO", "Adding Cameras: ...", op)
    stop_watch = StopWatch()
    camera_collection = add_collection(
        camera_collection_name, parent_collection
    )

    if add_image_planes:
        log_report("INFO", "Adding image planes: True", op)
        image_planes_collection = add_collection(
            image_plane_collection_name, parent_collection
        )
        camera_image_plane_pair_collection = add_collection(
            "Camera Image Plane Pair Collection", parent_collection
        )
    else:
        log_report("INFO", "Adding image planes: False", op)

    if add_depth_maps_as_point_cloud:
        log_report("INFO", "Adding depth maps as point cloud: True", op)
        depth_map_collection = add_collection(
            depth_map_collection_name, parent_collection
        )
        camera_depth_map_pair_collection = add_collection(
            "Camera Depth Map Pair Collection", parent_collection
        )
    else:
        log_report("INFO", "Adding depth maps as point cloud: False", op)

    depth_map_id_or_name_str = depth_map_id_or_name_str.rstrip()
    if depth_map_id_or_name_str == "":
        depth_map_indices = None
    else:
        depth_map_indices = []
        cam_rel_fp_to_idx = {}
        for idx, camera in enumerate(cameras):
            rel_fp = camera.get_relative_fp()
            cam_rel_fp_to_idx[rel_fp] = idx
        for id_or_name in depth_map_id_or_name_str.split(" "):
            if is_int(id_or_name):
                depth_map_indices.append(int(id_or_name))
            else:
                if id_or_name in cam_rel_fp_to_idx:
                    depth_map_indices.append(cam_rel_fp_to_idx[id_or_name])
                else:
                    log_report(
                        "WARNING",
                        "Could not find depth map name "
                        + id_or_name
                        + ". "
                        + "Possible values are: "
                        + str(cam_rel_fp_to_idx.keys()),
                        op,
                    )

    # Adding cameras and image planes:
    for index, camera in enumerate(cameras):
        # camera_name = "Camera %d" % index     # original code
        # Replace the camera name so it matches the image name (without extension)
        blender_image_name_stem = _get_camera_obj_gui_str(camera)
        camera_name = blender_image_name_stem + "_cam"
        camera_object = add_camera_object(
            camera, camera_name, camera_collection
        )
        camera_object.scale *= camera_scale

        if not add_image_planes and not add_background_images:
            continue

        if camera.has_undistorted_absolute_fp():
            image_path = camera.get_undistorted_absolute_fp()
        else:
            image_path = camera.get_absolute_fp()

        if not os.path.isfile(image_path):
            log_report(
                "WARNING", "Could not find image at " + str(image_path), op
            )
            continue
        else:
            log_report("INFO", "Found image at " + str(image_path), op)

        blender_image = bpy.data.images.load(image_path)

        if add_background_images:
            load_background_image(blender_image, camera_name)

        if add_image_planes and not camera.is_panoramic():
            # Group image plane and camera:
            camera_image_plane_pair_collection_current = add_collection(
                "Camera Image Plane Pair Collection %s"
                % blender_image_name_stem,
                camera_image_plane_pair_collection,
            )

            image_plane_name = blender_image_name_stem + "_image_plane"

            image_plane_obj = add_camera_image_plane(
                camera_object.matrix_world,
                blender_image,
                camera=camera,
                name=image_plane_name,
                transparency=image_plane_transparency,
                add_image_plane_emission=add_image_plane_emission,
                image_planes_collection=image_planes_collection,
                op=op,
            )

            camera_image_plane_pair_collection_current.objects.link(
                camera_object
            )
            camera_image_plane_pair_collection_current.objects.link(
                image_plane_obj
            )

        if not add_depth_maps_as_point_cloud:
            continue

        if camera.get_depth_map_fp() is None:
            continue

        if depth_map_indices is not None:
            if index not in depth_map_indices:
                continue

        # Group image plane and camera:
        camera_depth_map_pair_collection_current = add_collection(
            "Camera Depth Map Pair Collection %s"
            % os.path.basename(camera.get_depth_map_fp()),
            camera_depth_map_pair_collection,
        )

        depth_map_world_coords = camera.convert_depth_map_to_world_coords(
            depth_map_display_sparsity=depth_map_display_sparsity
        )
        depth_map_world_coords = depth_map_world_coords.tolist()

        if use_default_depth_map_color:
            color = depth_map_default_color
        else:
            color = _color_from_value(
                val=index, min_val=0, max_val=len(cameras)
            )

        depth_map_anchor_handle = draw_coords(
            depth_map_world_coords,
            color=color,
            point_size=depth_map_point_size,
            add_points_to_point_cloud_handle=True,
            reconstruction_collection=depth_map_collection,
            object_anchor_handle_name=_get_camera_obj_gui_str(camera)
            + "_depth_point_cloud",
            op=op,
        )

        camera_depth_map_pair_collection_current.objects.link(camera_object)
        camera_depth_map_pair_collection_current.objects.link(
            depth_map_anchor_handle
        )

    log_report("INFO", "Duration: " + str(stop_watch.get_elapsed_time()), op)
    log_report("INFO", "Adding Cameras: Done", op)
Add a set of reconstructed cameras to Blender's 3D view port.
photogrammetry_importer/importers/camera_utility.py