예제 #1
0
def get_local_frame_names(dir):
    """Finds all the frames in a directory.

    Args:
        dir (str): Path to a local directory.

    Returns:
        list[str]: Sorted list of frame names in the directory. If an invalid directory
            is passed in, an empty result is returned.
    """
    if os.path.isdir(dir):
        log(glog.green(f"Looking for local frames in {dir}"))
        frames = list_only_visible_files(dir)
        return [get_stem(f) for f in frames if is_frame(f)]
    return []
예제 #2
0
def get_local_frame_width(dir):
    """Finds the width of an image.

    Args:
        dir (str): Path to a local directory.

    Returns:
        int: Camera image width.
    """
    if not os.path.exists(dir):
        return -1
    frames = list_only_visible_files(dir)
    if not frames:
        return -1
    img = cv2.imread(os.path.join(dir, frames[0]), cv2.IMREAD_UNCHANGED)
    return img.shape[1]
예제 #3
0
def resize_local_frame(parent, dir_full, dir_level, rig_ref):
    glog.check(
        len(parent.cameras) > 0,
        f"No cameras found. Cannot resize local frame {dir_full}",
    )
    dir_cam = posixpath.join(dir_full, parent.cameras[0])
    frames = list_only_visible_files(dir_cam)
    glog.check_gt(len(frames), 0, f"No frames found in {dir_cam}")
    if parent.s3_sample_frame and dir_full == parent.path_video_color:
        frame_name = parent.s3_sample_frame
    else:
        frame_name, _ = os.path.splitext(sorted(frames)[0])
    frame_num = int(frame_name)

    log(glog.green(f"Resizing full-size frame {frame_name} in {dir_full}..."))
    with open(rig_ref, "r") as f:
        rig = json.load(f)
        resize_frames(dir_full, dir_level, rig, frame_num, frame_num)
예제 #4
0
def get_cameras(parent, rig_fn):
    """Finds the camera names in the captured project.

    Args:
        parent: class instance
        rig_fn (str): Path to the rig. If no path is provided, cameras are determined
            by the directory structure.

    Returns:
        list[str]: Names of the cameras.
    """
    if rig_fn:
        with open(rig_fn, "r") as f:
            rig = json.load(f)
            return [camera["id"] for camera in rig["cameras"]]
    else:
        for p in parent.paths_color + parent.paths_color_levels:
            if p in parent.paths_color_levels:
                p = posixpath.join(p, "level_0")
            cameras = list_only_visible_files(p)
            if len(cameras) > 0:
                return cameras
    return []