import base64


def base64_to_image(str):
    """Helper function for conversion of base64 image to opencv image

    :param str: input image in base64 format
    :type str: str
    :return: output image
    :rtype: numpy opencv image

    """

    str = str.replace("data:image/png;base64,", "")  # Stripping the metadata
    str = str.replace("data:image/jpeg;base64,", "")  # Stripping the metadata
    image = base64.b64decode(str)  # Decoding

    return image