pykitti Documentation

repository·master·Indexed 22 days ago

https://github.com/utiasstars/pykitti

A minimal Python toolkit for working with the KITTI dataset, specifically supporting raw and odometry benchmark datasets. It provides tools to access camera images, Velodyne scans, calibration data, and IMU poses through both sequential generators and random access getter methods.

Tokens
757
Snippets
3
Records
5
Agent score
29%

What's inside pykitti

  1. Install pykitti via pip or from source

    master

    You can install pykitti using pip or by installing from the source repository.

    Using pip

    pip install pykitti

    From source

    Clone the repository and run the setup script:

    git clone https://github.com/utiasSTARS/pykitti.git
    cd pykitti
    python setup.py install
    pip install pykitti
  2. Convert PIL images to OpenCV format

    master

    Since pykitti loads images as PIL.Image objects, you can convert them to OpenCV-compatible numpy arrays using numpy and cv2.cvtColor:

    import numpy as np
    import cv2
    
    # Assuming 'img' is a PIL Image object
    img_np = np.array(img)
    img_cv2 = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
    img_np = np.array(img)
    img_cv2 = cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR)
  3. Access camera and velodyne data via generators or getters

    master

    Data can be accessed in two ways:

    1. Generators: Use properties for sequential access (ideal for visual odometry).
    2. Getter methods: Use get_... methods for random access (ideal for deep learning).

    Images are returned as PIL.Image objects.

    Available Data Properties and Methods

    Data TypeGenerator PropertyRandom Access GetterDescription
    Camera Ndataset.camNdataset.get_camN(idx)Individual images from camera N
    Monochrome Stereodataset.graydataset.get_gray(idx)Stereo pair (cam0, cam1)
    RGB Stereodataset.rgbdataset.get_rgb(idx)Stereo pair (cam2, cam3)
    Velodynedataset.velodataset.get_velo(idx)Scans as [x, y, z, reflectance]

    Example

    # Sequential access via generator
    for cam0_image in data.cam0:
        pass
    
    # Random access via getter
    cam2_image, cam3_image = data.get_rgb(3)
  4. Access calibration, timestamps, and IMU data

    master

    Once a dataset is loaded, you can access metadata and calibration information:

    • dataset.calib: A named tuple containing calibration data (e.g., T_cam0_velo for transformations).
    • dataset.timestamps: A list of datetime objects representing the timestamps of the data.
    • dataset.oxts: A list of OXTS packets and 6-DOF poses as named tuples (e.g., o.T_w_imu for transformations).
  5. Load KITTI raw datasets with pykitti.raw()

    master

    To load a KITTI raw dataset, use pykitti.raw(basedir, date, drive, frames=None).

    Arguments

    • basedir: The base directory containing the dataset.
    • date: The date string (e.g., '2011_09_26').
    • drive: The drive identifier (e.g., '0019').
    • frames (optional): A range or list of frame indices to load. If None (default), the entire dataset is loaded.

    Assumptions

    • You must have downloaded the calibration data associated with the sequences.
    • The directory structure must remain unchanged from the original KITTI zip file structure.
    import pykitti
    
    basedir = '/your/dataset/dir'
    date = '2011_09_26'
    drive = '0019'
    
    # Loads specific frames; use frames=None for the whole dataset
    data = pykitti.raw(basedir, date, drive, frames=range(0, 50, 5))