def getKITTIGroundTruth(labels, categories, categoriesOpt, mode='moderate'):
    """Get mandatory and optional ground truth out of a list of labels

    The KITTI dataset defines criteria which labels have to be detected in order to avoid a false negative. There are three evaluation
    modes 'easy', 'moderate' and 'hard'. To avoid penalizing good detection algorithms labels which are hard to detect become optional
    ground truth so their detection will not result in a false positive. The harder the mode the more labels become mandatory ground truth.

    The category 'dontcare' is always included in optional ground truth.

    :Parameters:
        labels: list of dicts
            List with labels provided by dataset reader
        categories: list of strings
            Mandatory categories
        categoriesOpt: list of strings
            Optional categories
        mode: string, optional
            Evaluation mode, 'moderate' by default

    :Returns: mandatory and optional ground truth
    :Returntype: tuple(groundTruth: list, groundTruthOpt: list)
    """
    MODES = {'easy': {'minHeight': 40, 'maxOcclusion': 0, 'maxTruncation': 
        0.15}, 'moderate': {'minHeight': 25, 'maxOcclusion': 1,
        'maxTruncation': 0.3}, 'hard': {'minHeight': 25, 'maxOcclusion': 2,
        'maxTruncation': 0.5}}
    mode = MODES[mode]
    groundTruth = []
    groundTruthOpt = []
    for label in labels:
        if label['category'] in categoriesOpt or label['category'
            ] == 'dontcare':
            groundTruthOpt.append(label)
        elif label['category'] in categories:
            if label['info']['occluded'] > mode['maxOcclusion']:
                groundTruthOpt.append(label)
            elif label['info']['truncated'] > mode['maxTruncation']:
                groundTruthOpt.append(label)
            elif label['box2D']['bottom'] - label['box2D']['top'] < mode[
                'minHeight']:
                groundTruthOpt.append(label)
            else:
                groundTruth.append(label)
    return groundTruth, groundTruthOpt
