Skip to content

aigve.utils

read_image_detectron2(file_name, format=None)

Read an image into the given format. Will apply rotation and flipping if the image has such exif information.

Parameters:

Name Type Description Default
file_name str

image file path

required
format str

one of the supported image modes in PIL, or "BGR" or "YUV-BT.601".

None

Returns:

Name Type Description
image ndarray

an HWC image in the given format, which is 0-255, uint8 for supported image modes in PIL or "BGR"; float (0-1 for Y) for YUV-BT.601.

Source code in aigve/utils/image_reading.py
def read_image_detectron2(file_name, format=None):
    """
    Read an image into the given format.
    Will apply rotation and flipping if the image has such exif information.

    Args:
        file_name (str): image file path
        format (str): one of the supported image modes in PIL, or "BGR" or "YUV-BT.601".

    Returns:
        image (np.ndarray):
            an HWC image in the given format, which is 0-255, uint8 for
            supported image modes in PIL or "BGR"; float (0-1 for Y) for YUV-BT.601.
    """
    try:
        import detectron2
    except ImportError:
        print("detectron2 is not installed. Installing...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", "detectron2"])

        return detectron2.data.detection_utils.read_image(img_src, format="BGR")