def _load_image(image_file, load_cv2=False):
    """Loads image using utils (PIL Image) or CV2 imdecode."""
    if not load_cv2:
        return utils.load_image(image_file)

    # Load images via cv2:
    with tf.io.gfile.GFile(image_file, 'rb') as f:
        img_bgr = cv2.imdecode(np.fromstring(f.read(), dtype=np.uint8),
                               cv2.IMREAD_COLOR)  # OpenCV reads in BGR format

    return cv2.cvtColor(img_bgr,
                        cv2.COLOR_BGR2RGB)  # Return RGB converted image
Exemplo n.º 2
0
def imread(filename):
    with tf.gfile.Open(filename, 'rb') as f:
        raw_image = np.asarray(bytearray(f.read()), dtype=np.uint8)
        image = cv2.imdecode(raw_image, cv2.IMREAD_COLOR)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    return image.astype(np.float32) / 255.0