(
    fb, grayscale: bool = False, unchanged: bool = False, anydepth: bool = False
)
return image
Load image as an array ignoring EXIF orientation.
Load image as an array ignoring EXIF orientation.
Load image as an array ignoring EXIF orientation .
def imread_from_fileobject(
    fb, grayscale: bool = False, unchanged: bool = False, anydepth: bool = False
) -> np.ndarray:
    """Load image as an array ignoring EXIF orientation."""
    if context.OPENCV3:
        if grayscale:
            flags = cv2.IMREAD_GRAYSCALE
        elif unchanged:
            flags = cv2.IMREAD_UNCHANGED
        else:
            flags = cv2.IMREAD_COLOR

        try:
            flags |= cv2.IMREAD_IGNORE_ORIENTATION
        except AttributeError:
            logger.warning(
                "OpenCV version {} does not support loading images without "
                "rotating them according to EXIF. Please upgrade OpenCV to "
                "version 3.2 or newer.".format(cv2.__version__)
            )

        if anydepth:
            flags |= cv2.IMREAD_ANYDEPTH
    else:
        if grayscale:
            flags = cv2.CV_LOAD_IMAGE_GRAYSCALE
        elif unchanged:
            flags = cv2.CV_LOAD_IMAGE_UNCHANGED
        else:
            flags = cv2.CV_LOAD_IMAGE_COLOR

        if anydepth:
            flags |= cv2.CV_LOAD_IMAGE_ANYDEPTH

    im_buffer = np.asarray(bytearray(fb.read()), dtype=np.uint8)
    image = cv2.imdecode(im_buffer, flags)

    if image is None:
        raise IOError("Unable to load image")

    if len(image.shape) == 3:
        image[:, :, :3] = image[:, :, [2, 1, 0]]  # Turn BGR to RGB (or BGRA to RGBA)
    return image

    @classmethod
    def imwrite(cls, path: str, image: np.ndarray) -> None:
        with cls.open(path, "wb") as fwb:
            imwrite(fwb, image, path)
def imread_from_fileobject ( fb , grayscale : bool = False , unchanged : bool = False , anydepth : bool = False ) -> np . ndarray : if context . OPENCV3 : if grayscale : flags = cv2 . IMREAD_GRAYSCALE elif unchanged : flags = cv2 . IMREAD_UNCHANGED else : flags = cv2 . IMREAD_COLOR try : flags |= cv2 . IMREAD_IGNORE_ORIENTATION except AttributeError : logger . warning ( "OpenCV version {} does not support loading images without " "rotating them according to EXIF. Please upgrade OpenCV to " "version 3.2 or newer." . format ( cv2 . __version__ ) ) if anydepth : flags |= cv2 . IMREAD_ANYDEPTH else : if grayscale : flags = cv2 . CV_LOAD_IMAGE_GRAYSCALE elif unchanged : flags = cv2 . CV_LOAD_IMAGE_UNCHANGED else : flags = cv2 . CV_LOAD_IMAGE_COLOR if anydepth : flags |= cv2 . CV_LOAD_IMAGE_ANYDEPTH im_buffer = np . asarray ( bytearray ( fb . read ( ) ) , dtype = np . uint8 ) image = cv2 . imdecode ( im_buffer , flags ) if image is None : raise IOError ( "Unable to load image" ) if len ( image . shape ) == 3 : image [ : , : , : 3 ] = image [ : , : , [ 2 , 1 , 0 ] ] # Turn BGR to RGB (or BGRA to RGBA) return image @ classmethod def imwrite ( cls , path : str , image : np . ndarray ) -> None : with cls . open ( path , "wb" ) as fwb : imwrite ( fwb , image , path )