Python functions to import and display the images and labels from the Kitty Object Detection Evaluation 2012 Dataset.
- python ≥ v2.7.6
- scipy ≥ v0.19.1
- matplotlib ≥ v1.5.2
- numpy ≥ v1.13.3
- Copy the file
kittipy.py
in the same directory as the python script or Jupyter notebook you want to use it with. - (Optional) Modify the
kittipy.py
global parameters at the begining - At the begining of your file, add the line:
from kittipy import *
- Enjoy!
To get the numpy array containing all the ids of the images contained in a folder, use the function:
get_data_list(im_set, db_absolute_path = ABSOLUTE_PATH)
Arguments | Default | Description |
---|---|---|
im_set |
[string] 'train' or 'test' to chose the type of set | |
db_absolute_path |
ABSOLUTE_PATH | [string] absolute path to the Kitti root folder |
To import images as a numpy array, use the function:
import_im(im_id, im_set, db_absolute_path = ABSOLUTE_PATH)
Arguments | Default | Description |
---|---|---|
im_id |
[int] corresponding to the image id in the kitti dataset | |
im_set |
[string] 'train' or 'test' to chose the type of set | |
db_absolute_path |
ABSOLUTE_PATH | [string] absolute path to the Kitti root folder |
To import the labels as a list of python dictionaries, use the function:
import_labels(im_id, im_set, db_absolute_path = ABSOLUTE_PATH)
Arguments | Default | Description |
---|---|---|
im_id |
[int] corresponding to the image id in the kitti dataset | |
im_set |
[string] 'train' or 'test' to chose the type of set | |
db_absolute_path |
ABSOLUTE_PATH | [string] absolute path to the Kitti root folder |
Fields | Description |
---|---|
type |
[string] 'Car', 'Van', 'Truck', 'Pedestrian', 'Person_sitting', 'Cyclist', 'Tram', 'Misc' or 'DontCare' |
truncated |
[float] Float from 0 (non-truncated) to 1 (truncated), where truncated refers to the object leaving the image boundaries |
occluded |
[int] Integer (0,1,2,3) indicating occlusion state: 0 = fully visible, 1 = partly occluded, 2 = largely occluded, 3 = unknown |
alpha |
[float] Observation angle of an object [-pi..pi] |
bbox |
[dict][float] x_min , y_min , x_max , y_max pixel coordinates (0-based index) |
3D_dim |
[dict][float] height , width , length (in meters) |
3D_loc |
[dict][float] x , y , z in camera coordinates (in meters) |
rotation_y |
[float] around Y-axis in camera coordinates [-pi..pi] |
score (Optional) |
[float] Only for results, indicating confidence in detection, needed for p/r curves, higher is better. |
To display a image and its labels in a Jupyter Notebook, use the function:
display_im(im, labels = [], display_boxes = True, display_info = True,
types_to_display = DEFAULT_TYPES_TO_DISPLAY,
info_to_display = DEFAULT_INFO_TO_DISPLAY,
db_absolute_path = ABSOLUTE_PATH, im_width = FIG_WIDTH,
im_height = FIG_HEIGHT, display_axis = False,
title = '', display_center_boxes = True, num_cell_grid = 0)
Arguments | Default | Description |
---|---|---|
im |
[numpy.array] Image to display | |
labels |
[] | [list][dict] List of dictionaries containing the labels of the image |
display_boxes |
True | [bool] Display the boxes around the objects |
display_info |
True | [bool] Write the info_to_display under the image |
types_to_display |
DEFAULT_TYPES_TO_DISPLAY | [list] List of types of object to consider |
info_to_display |
DEFAULT_INFO_TO_DISPLAY | [list] List of characteritics of object to display |
im_width |
FIG_WIDTH | [int] Width of the image to display |
im_height |
FIG_HEIGHT | [int] Height of the image to display |
display_axis |
False | [bool] Display the axis of the image |
title |
'' | [string] Title to write before the image |
display_center_boxes |
True | [bool] Display the center of the boxes |
num_cell_grid |
0 | [int] Display a num_cell_grid x num_cell_grid over the image |
Remarks: To change FIG_FONT_SIZE_TITLE
, COLOR_GRID
and COLOR_TYPE
do it in the global variables at the begining of the kittipy.py
file.
Code (Jupyter Notebook)
list_ids = get_data_list('train')
image = import_im(list_ids[3], 'train')
labels = import_labels(list_ids[3], 'train')
display_im(image, labels, num_cell_grid = 10)
Output
- Lucas Vandroux (冯凯) 【Github】 【LinkedIn】
I started this project to help me during my Master Thesis at Tsinghua University in China. If you find it useful, don't hesitate to use it and improve it.