def read_image_from_stream(stream):
    try:
        arr = np.asarray(bytearray(stream.read()), dtype=np.uint8)
        image = cv2.imdecode(arr, cv2.IMREAD_COLOR)
        height, width = image.shape[:2]
        if height <= 0 or width <= 0:
            raise Exception('Invalid image file from stream')
    except:
        raise Exception('Invalid image file from stream')

    return image