From 363cc06818eacf28eaf99750a84dfade06917bda Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Wed, 15 Apr 2020 17:37:28 -0400 Subject: [PATCH] gitignore & Read Velodyne Data - Add gitignore so VS Code and dataset files are not committed - Add python functions provided by NCLT dataset for reading velodyne data --- .gitignore | 6 + src/localization/localization.py | 16 +++ src/localization/project_vel_to_cam.py | 166 +++++++++++++++++++++++++ src/localization/read_vel_hits.py | 90 ++++++++++++++ src/localization/read_vel_sync.py | 81 ++++++++++++ 5 files changed, 359 insertions(+) create mode 100644 .gitignore create mode 100644 src/localization/localization.py create mode 100644 src/localization/project_vel_to_cam.py create mode 100644 src/localization/read_vel_hits.py create mode 100644 src/localization/read_vel_sync.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad13b3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Visual Studio Code +.vscode + +# Ignore downloaded dataset files +src/dataset/* +!src/dataset/*.py diff --git a/src/localization/localization.py b/src/localization/localization.py new file mode 100644 index 0000000..6f19cb4 --- /dev/null +++ b/src/localization/localization.py @@ -0,0 +1,16 @@ +# localization.py + +import numpy as np +import matplotlib.pyplot as plt +import csv +import os +from PoseList import PoseList +from scipy.spatial import distance + + +def main(): + pass + + +if __name__ == '__main__': + main() diff --git a/src/localization/project_vel_to_cam.py b/src/localization/project_vel_to_cam.py new file mode 100644 index 0000000..0356d4e --- /dev/null +++ b/src/localization/project_vel_to_cam.py @@ -0,0 +1,166 @@ +# !/usr/bin/python +# +# Demonstrates how to project velodyne points to camera imagery. Requires a binary +# velodyne sync file, undistorted image, and assumes that the calibration files are +# in the directory. +# +# To use: +# +# python project_vel_to_cam.py vel img cam_num +# +# vel: The velodyne binary file (timestamp.bin) +# img: The undistorted image (timestamp.tiff) +# cam_num: The index (0 through 5) of the camera +# + +import sys +import struct +import matplotlib.pyplot as plt +import matplotlib.image as mpimg +import numpy as np + +#from undistort import * + +def convert(x_s, y_s, z_s): + + scaling = 0.005 # 5 mm + offset = -100.0 + + x = x_s * scaling + offset + y = y_s * scaling + offset + z = z_s * scaling + offset + + return x, y, z + +def load_vel_hits(filename): + + f_bin = open(filename, "r") + + hits = [] + + while True: + + x_str = f_bin.read(2) + if x_str == '': # eof + break + + x = struct.unpack('0 + x_im = x_im[idx_infront] + y_im = y_im[idx_infront] + z_im = z_im[idx_infront] + + plt.figure(1) + plt.imshow(image) + plt.hold(True) + plt.scatter(x_im, y_im, c=z_im, s=5, linewidths=0) + plt.xlim(0, 1616) + plt.ylim(0, 1232) + plt.show() + + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/src/localization/read_vel_hits.py b/src/localization/read_vel_hits.py new file mode 100644 index 0000000..de1e6e1 --- /dev/null +++ b/src/localization/read_vel_hits.py @@ -0,0 +1,90 @@ +# !/usr/bin/python +# +# Example code to go through the velodyne_hits.bin +# file and read timestamps, number of hits, and the +# hits in each packet. +# +# +# To call: +# +# python read_vel_hits.py velodyne.bin +# + +import sys +import struct + +def convert(x_s, y_s, z_s): + + scaling = 0.005 # 5 mm + offset = -100.0 + + x = x_s * scaling + offset + y = y_s * scaling + offset + z = z_s * scaling + offset + + return x, y, z + +def verify_magic(s): + + magic = 44444 + + m = struct.unpack('=4 and m[0] == magic and m[1] == magic and m[2] == magic and m[3] == magic + +def main(args): + + if len(sys.argv) < 2: + print "Please specifiy input bin file" + return 1 + + f_bin = open(sys.argv[1], "r") + + total_hits = 0 + first_utime = -1 + last_utime = -1 + + while True: + + magic = f_bin.read(8) + if magic == '': # eof + break + + if not verify_magic(magic): + print "Could not verify magic" + + num_hits = struct.unpack('= 3: + print('Writing to ', sys.argv[2]) + f_csv = open(sys.argv[2], "w") + else: + f_csv = None + + hits = [] + + while True: + + x_str = f_bin.read(2) + if x_str == b'': # eof + break + + x = struct.unpack('