def get_template(img, bbox):
    """
    Cutting template out of image by using the bbox informations
    bbox format: [bb_left,bb_top,bb_width,bb_height]
    """
    bbox = [int(i) for i in bbox]

    bbox[0] = max(0, bbox[0])
    bbox[1] = max(0, bbox[1])

    if bbox[0]+bbox[2] > img.shape[1]:
        bbox[2] = img.shape[1] - bbox[0]
    if bbox[1]+bbox[3] > img.shape[0]:
        bbox[3] = img.shape[0] - bbox[1]

    template = img[bbox[1]:bbox[1]+bbox[3],bbox[0]:bbox[0]+bbox[2]]
    
    return template