(path, im_path, out_path, difficult, img_reshape=None)
Converts the KITTI annotations to json file.

    Uses the below reference for the KITTI dataset:

    OO representation of label format used in Kitti dataset.

    Description of fields from Kitti dataset dev kit: (link)[]
    The label files contain the following information, which can be read and
    written using the matlab tools (readLabels.m, writeLabels.m) provided within
    this devkit. All values (numerical or strings) are separated via spaces,
    each row corresponds to one object. The 15 columns represent:
    #Values    Name      Description
    ----------------------------------------------------------------------------
       1    type         Describes the type of object: 'Car', 'Van', 'Truck',
                         'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram',
                         'Misc' or 'DontCare'
       1    truncated    Float from 0 (non-truncated) to 1 (truncated), where
                         truncated refers to the object leaving image boundaries
       1    occluded     Integer (0,1,2,3) indicating occlusion state:
                         0 = fully visible, 1 = partly occluded
                         2 = largely occluded, 3 = unknown
       1    alpha        Observation angle of object, ranging [-pi..pi]
       4    bbox         2D bounding box of object in the image (0-based index):
                         contains left, top, right, bottom pixel coordinates
       3    dimensions   3D object dimensions: height, width, length (in meters)
       3    location     3D object location x,y,z in camera coordinates (in meters)
       1    rotation_y   Rotation ry around Y-axis in camera coordinates [-pi..pi]
       1    score        Only for results: Float, indicating confidence in
                         detection, needed for p/r curves, higher is better.

    Arguments:
        path (string): path to KITTI annotation file
        im_path (string): path to image
        out_path (string): path to save the json file
        difficult (bool): include difficult objects
        img_reshape (tuple of int): if a tuple of H,W values is given, image will be reshaped
Converts the KITTI annotations to json file.
Converts the KITTI annotations to json file .
def convert_annot_to_json(path, im_path, out_path, difficult, img_reshape=None):
    """
    Converts the KITTI annotations to json file.

    Uses the below reference for the KITTI dataset:

    OO representation of label format used in Kitti dataset.

    Description of fields from Kitti dataset dev kit: (link)[]
    The label files contain the following information, which can be read and
    written using the matlab tools (readLabels.m, writeLabels.m) provided within
    this devkit. All values (numerical or strings) are separated via spaces,
    each row corresponds to one object. The 15 columns represent:
    #Values    Name      Description
    ----------------------------------------------------------------------------
       1    type         Describes the type of object: 'Car', 'Van', 'Truck',
                         'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram',
                         'Misc' or 'DontCare'
       1    truncated    Float from 0 (non-truncated) to 1 (truncated), where
                         truncated refers to the object leaving image boundaries
       1    occluded     Integer (0,1,2,3) indicating occlusion state:
                         0 = fully visible, 1 = partly occluded
                         2 = largely occluded, 3 = unknown
       1    alpha        Observation angle of object, ranging [-pi..pi]
       4    bbox         2D bounding box of object in the image (0-based index):
                         contains left, top, right, bottom pixel coordinates
       3    dimensions   3D object dimensions: height, width, length (in meters)
       3    location     3D object location x,y,z in camera coordinates (in meters)
       1    rotation_y   Rotation ry around Y-axis in camera coordinates [-pi..pi]
       1    score        Only for results: Float, indicating confidence in
                         detection, needed for p/r curves, higher is better.

    Arguments:
        path (string): path to KITTI annotation file
        im_path (string): path to image
        out_path (string): path to save the json file
        difficult (bool): include difficult objects
        img_reshape (tuple of int): if a tuple of H,W values is given, image will be reshaped
    """
    with open(path) as f:
        labels = f.readlines()

    # start empty dictionary
    annot = {'object': []}

    # load image
    im = np.array(Image.open(im_path))
    scale, (h, w) = util.get_image_scale(im.shape[:2], img_reshape)
    c = im.shape[2]
    annot['size'] = {'depth': c, 'height': h, 'width': w}

    for label in labels:
        vals = label.split()
        typeid = vals[0]
        truncated = float(vals[1])
        occluded = int(vals[2])
        bbox = [float(x) for x in vals[4:8]]
        bbox = util.scale_boxes(bbox, scale)
        bbox_int = tuple([int(math.floor(x)) for x in bbox])

        if typeid == 'DontCare':
            assert truncated == -1
            assert occluded == -1
        else:
            assert occluded in (0, 1, 2, 3)

        diff = truncated > 0.5 or occluded == 2

        # add object to annotation
        obj = {'bndbox': {'xmin': bbox_int[0], 'ymin': bbox_int[1],
               'xmax': bbox_int[2], 'ymax': bbox_int[3]},
               'difficult': diff,
               'name': typeid,
               'truncated': truncated > 0.5,
               'occluded': occluded
               }

        if not diff or difficult:
            annot['object'].append(obj)

    with open(out_path, 'w') as f:
        json.dump(annot, f, indent=4)
def convert_annot_to_json ( path , im_path , out_path , difficult , img_reshape = None ) : with open ( path ) as f : labels = f . readlines ( ) # start empty dictionary annot = { 'object' : [ ] } # load image im = np . array ( Image . open ( im_path ) ) scale , ( h , w ) = util . get_image_scale ( im . shape [ : 2 ] , img_reshape ) c = im . shape [ 2 ] annot [ 'size' ] = { 'depth' : c , 'height' : h , 'width' : w } for label in labels : vals = label . split ( ) typeid = vals [ 0 ] truncated = float ( vals [ 1 ] ) occluded = int ( vals [ 2 ] ) bbox = [ float ( x ) for x in vals [ 4 : 8 ] ] bbox = util . scale_boxes ( bbox , scale ) bbox_int = tuple ( [ int ( math . floor ( x ) ) for x in bbox ] ) if typeid == 'DontCare' : assert truncated == - 1 assert occluded == - 1 else : assert occluded in ( 0 , 1 , 2 , 3 ) diff = truncated > 0.5 or occluded == 2 # add object to annotation obj = { 'bndbox' : { 'xmin' : bbox_int [ 0 ] , 'ymin' : bbox_int [ 1 ] , 'xmax' : bbox_int [ 2 ] , 'ymax' : bbox_int [ 3 ] } , 'difficult' : diff , 'name' : typeid , 'truncated' : truncated > 0.5 , 'occluded' : occluded } if not diff or difficult : annot [ 'object' ] . append ( obj ) with open ( out_path , 'w' ) as f : json . dump ( annot , f , indent = 4 )