コード例 #1
0
 def count_frames(self):
     # Count total frames 
     for file_name in self.__file_names:
         dataset = WaymoDataFileReader(file_name)
         for frame in tqdm.tqdm(dataset):
             self._total_frames+=1
     print("[LOG] Total frames: ", self._total_frames)
コード例 #2
0
 def __getitem__(self, idx):
     self._curr_counter = idx
     # Get the next dataset if frame number is more than table count
     if self._frame_counter == -1 or not len(self._dataset_nums) or self._frame_counter >= self._dataset_nums[self._file_counter]-1: 
         self.current_file = self.__file_names.pop() # get one filename
         dataset = WaymoDataFileReader(self.current_file) # get Dataloader
         self._sample_list = dataset.get_record_table() # get number of record table
         self._dataset_itr = iter(dataset) # Get next record iterator
         if self._frame_counter == -1:
             self._file_counter +=1
             self._dataset_nums.append(len(self._sample_list))
         self._frame_counter = 1
     else:
         self._frame_counter+=1
     self._num_frames+=1
     self._idx_to_frame.append((self._file_counter, self._frame_counter))
     return next(self.dataset_itr) # Send next frame from record 
コード例 #3
0
def export_file(filename):
    print('[{}] Porting: {}'.format(threading.get_ident(), filename))
    head, tail = os.path.split(filename)
    m = re.search('(.*)(_with_camera_labels)?\.tfrecord$', tail)
    if m is None:
        exit(1)
    filename_without_tfrecord = m.group(1)

    _start_time = time.time()
    # waymo data file reader
    datafile = WaymoDataFileReader(filename)

    # Generate a table of the offset of all frame records in the file.
    table = datafile.get_record_table()

    print("There are %d frames in this file." % len(table))

    # Loop through the whole file
    ## and display 3D labels.
    frame_id = 0
    for frame in datafile:
        camera_name = dataset_pb2.CameraName.FRONT
        camera_calibration = utils.get(frame.context.camera_calibrations,
                                       camera_name)
        camera = utils.get(frame.images, camera_name)

        camera_labels = None
        if len(frame.camera_labels) != 0:
            camera_labels = utils.get(frame.camera_labels, camera_name)
            camera_labels = camera_labels.labels

        exporter.export(camera_calibration,
                        camera,
                        frame.laser_labels,
                        camera_labels,
                        frame_id=frame_id,
                        sequence_id=filename_without_tfrecord)
        frame_id += 1
    print('[{}] Processed file in {}'.format(threading.get_ident(),
                                             time.time() - _start_time))
コード例 #4
0
def parse_record(
    output_dir: str,
    save_images: bool,
    use_lidar_labels: bool,
    record_name: str,
) -> Tuple[List[Frame], List[FrameGroup]]:
    """Parse data into List of Scalabel format annotations."""
    datafile = WaymoDataFileReader(record_name)
    table = datafile.get_record_table()
    frames, groups = [], []
    for frame_id, offset in enumerate(table):
        # jump to correct place, read frame
        datafile.seek(offset)
        frame = datafile.read_record()

        # add images and annotations to coco
        frame, group = parse_frame(frame, frame_id, output_dir, save_images,
                                   use_lidar_labels)
        frames.extend(frame)
        groups.extend(group)

    return frames, groups
    # Colour code the points based on distance.
    coloured_intensity = 255*cmap(proj_pcl_attr[:,0]/30)

    # Draw a circle for each point.
    for i in range(proj_pcl.shape[0]):
        cv2.circle(img, (int(proj_pcl[i,0]),int(proj_pcl[i,1])), 1, coloured_intensity[i])

if len(sys.argv) != 2:
    print("""Usage: python display_laser_on_image.py <datafile>
Display the groundtruth 3D bounding boxes and LIDAR points on the front camera video stream.""")
    sys.exit(0)

# Open a .tfrecord
filename = sys.argv[1]
datafile = WaymoDataFileReader(filename)

# Generate a table of the offset of all frame records in the file.
table = datafile.get_record_table()

print("There are %d frames in this file." % len(table))


# Loop through the whole file
## and display 3D labels.
for frameno,frame in enumerate(datafile):

    # Get the top laser information
    laser_name = dataset_pb2.LaserName.TOP
    laser = utils.get(frame.lasers, laser_name)
    laser_calibration = utils.get(frame.context.laser_calibrations, laser_name)
コード例 #6
0
import numpy as np
import math
import io
import sys
from simple_waymo_open_dataset_reader import WaymoDataFileReader
from simple_waymo_open_dataset_reader import dataset_pb2, label_pb2
from simple_waymo_open_dataset_reader import utils
import cv2
import matplotlib.pyplot as plt

# file for the tfrecord data
data_file_path = '/home/sambit/WAYMO/segment-1208303279778032257_1360_000_1380_000_with_camera_labels.tfrecord'

if __name__ == "__main__":
    print("============= generating training labels ===============")
    print(np.__version__)

    # read in the tfrecord data file
    datafile = WaymoDataFileReader(data_file_path)
    print(datafile)

    for frame in datafile:
        # we are only interested in the top laser and front camera
        # get top lidar info
        laser_name = dataset_pb2.LaserName.TOP  # lidar name for top lidar from the dataset
        laser = utils.get(frame.lasers, laser_name)
        laser_calibration = utils.get(frame.context.laser_calibrations,
                                      laser_name)

        print(laser_calibration)