detectron2的read_image方法

在看代码的时候,看到一行注释:use PIL, to be consistent with evaluation

detectron2的read_image方法_第1张图片说是用PIL方法加载,却又看见了BGR这种表述,后面的调用也都是cv2格式:

detectron2的read_image方法_第2张图片

那我就要看下这里面是怎么实现的了,找到了read_image函数,如下:

def read_image(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.
    """
    with PathManager.open(file_name, "rb") as f:
        image = Image.open(f)

        # work around this bug: https://github.com/python-pillow/Pillow/issues/3973
        image = _apply_exif_orientation(image)
        return convert_PIL_to_numpy(image, format)

原来是用PIL打开后转成了numpy

做个笔记,以上。

你可能感兴趣的:(python,人工智能)