diff --git a/download/downloader.sh b/download/downloader.sh new file mode 100755 index 0000000..db22666 --- /dev/null +++ b/download/downloader.sh @@ -0,0 +1,205 @@ +#!/bin/bash + +files=( +# 2011_09_26_calib.zip +2011_09_26_drive_0001,t +2011_09_26_drive_0002,v +2011_09_26_drive_0005,v +2011_09_26_drive_0009,t +2011_09_26_drive_0011,t +2011_09_26_drive_0013,v +2011_09_26_drive_0014,t +2011_09_26_drive_0015,t +2011_09_26_drive_0017,t +2011_09_26_drive_0018,t +2011_09_26_drive_0019,t +2011_09_26_drive_0020,v +2011_09_26_drive_0022,t +2011_09_26_drive_0023,v +2011_09_26_drive_0027,t +2011_09_26_drive_0028,t +2011_09_26_drive_0029,t +2011_09_26_drive_0032,t +2011_09_26_drive_0035,t +2011_09_26_drive_0036,v +2011_09_26_drive_0039,t +2011_09_26_drive_0046,t +2011_09_26_drive_0048,t +2011_09_26_drive_0051,t +2011_09_26_drive_0052,t +2011_09_26_drive_0056,t +2011_09_26_drive_0057,t +2011_09_26_drive_0059,t +2011_09_26_drive_0060,t +2011_09_26_drive_0061,t +2011_09_26_drive_0064,t +2011_09_26_drive_0070,t +2011_09_26_drive_0079,v +2011_09_26_drive_0084,t +2011_09_26_drive_0086,t +2011_09_26_drive_0087,t +2011_09_26_drive_0091,t +2011_09_26_drive_0093,t +2011_09_26_drive_0095,v +2011_09_26_drive_0096,t +2011_09_26_drive_0101,t +2011_09_26_drive_0104,t +2011_09_26_drive_0106,t +2011_09_26_drive_0113,v +2011_09_26_drive_0117,t +2011_09_26_drive_0119,v +# 2011_09_28_calib.zip,v +2011_09_28_drive_0001,t +2011_09_28_drive_0002,t +2011_09_28_drive_0016,t +2011_09_28_drive_0021,t +2011_09_28_drive_0034,t +2011_09_28_drive_0035,t +2011_09_28_drive_0037,v +2011_09_28_drive_0038,t +2011_09_28_drive_0039,t +2011_09_28_drive_0043,t +2011_09_28_drive_0045,t +2011_09_28_drive_0047,t +2011_09_28_drive_0053,t +2011_09_28_drive_0054,t +2011_09_28_drive_0057,t +2011_09_28_drive_0065,t +2011_09_28_drive_0066,t +2011_09_28_drive_0068,t +2011_09_28_drive_0070,t +2011_09_28_drive_0071,t +2011_09_28_drive_0075,t +2011_09_28_drive_0077,t +2011_09_28_drive_0078,t +2011_09_28_drive_0080,t +2011_09_28_drive_0082,t +2011_09_28_drive_0086,t +2011_09_28_drive_0087,t +2011_09_28_drive_0089,t +2011_09_28_drive_0090,t +2011_09_28_drive_0094,t +2011_09_28_drive_0095,t +2011_09_28_drive_0096,t +2011_09_28_drive_0098,t +2011_09_28_drive_0100,t +2011_09_28_drive_0102,t +2011_09_28_drive_0103,t +2011_09_28_drive_0104,t +2011_09_28_drive_0106,t +2011_09_28_drive_0108,t +2011_09_28_drive_0110,t +2011_09_28_drive_0113,t +2011_09_28_drive_0117,t +2011_09_28_drive_0119,t +2011_09_28_drive_0121,t +2011_09_28_drive_0122,t +2011_09_28_drive_0125,t +2011_09_28_drive_0126,t +2011_09_28_drive_0128,t +2011_09_28_drive_0132,t +2011_09_28_drive_0134,t +2011_09_28_drive_0135,t +2011_09_28_drive_0136,t +2011_09_28_drive_0138,t +2011_09_28_drive_0141,t +2011_09_28_drive_0143,t +2011_09_28_drive_0145,t +2011_09_28_drive_0146,t +2011_09_28_drive_0149,t +2011_09_28_drive_0153,t +2011_09_28_drive_0154,t +2011_09_28_drive_0155,t +2011_09_28_drive_0156,t +2011_09_28_drive_0160,t +2011_09_28_drive_0161,t +2011_09_28_drive_0162,t +2011_09_28_drive_0165,t +2011_09_28_drive_0166,t +2011_09_28_drive_0167,t +2011_09_28_drive_0168,t +2011_09_28_drive_0171,t +2011_09_28_drive_0174,t +2011_09_28_drive_0177,t +2011_09_28_drive_0179,t +2011_09_28_drive_0183,t +2011_09_28_drive_0184,t +2011_09_28_drive_0185,t +2011_09_28_drive_0186,t +2011_09_28_drive_0187,t +2011_09_28_drive_0191,t +2011_09_28_drive_0192,t +2011_09_28_drive_0195,t +2011_09_28_drive_0198,t +2011_09_28_drive_0199,t +2011_09_28_drive_0201,t +2011_09_28_drive_0204,t +2011_09_28_drive_0205,t +2011_09_28_drive_0208,t +2011_09_28_drive_0209,t +2011_09_28_drive_0214,t +2011_09_28_drive_0216,t +2011_09_28_drive_0220,t +2011_09_28_drive_0222,t +2011_09_28_drive_0225,v +# 2011_09_29_calib.zip +2011_09_29_drive_0004,t +2011_09_29_drive_0026,v +2011_09_29_drive_0071,t +2011_09_29_drive_0108,v +# 2011_09_30_calib.zip +2011_09_30_drive_0016,v +2011_09_30_drive_0018,t +2011_09_30_drive_0020,t +2011_09_30_drive_0027,t +2011_09_30_drive_0028,t +2011_09_30_drive_0033,t +2011_09_30_drive_0034,t +2011_09_30_drive_0072,v +# 2011_10_03_calib.zip +2011_10_03_drive_0027,t +2011_10_03_drive_0034,t +2011_10_03_drive_0042,t +2011_10_03_drive_0047,v +2011_10_03_drive_0058,v +) + + +mkdirmv () { + mkdir -p $2 + mv $1 $2 +} + + +basedir='../data/' +rgbdir=$basedir'data_rgb/' +oxtsdir=$basedir'data_oxts/' +velodir=$basedir'data_velo/' +echo "Saving to "$basedir +for f in ${files[@]}; do + t=${f:22:23} #v or t + i=${f:0:21} + datadate="${i%%_drive_*}" + shortname=$i'_sync.zip' + fullname=$i'/'$i'_sync.zip' + type="other" + if [ $t == "v" ]; then + type="val" + elif [ $t == "t" ]; then + type="train" + fi + echo "Downloading: "$shortname + rm -f $shortname # remove previous zip file + wget 's3.eu-central-1.amazonaws.com/avg-kitti/raw_data/'$fullname + unzip -o $shortname + echo "moving "$datadate" as "$type + unzipdir=$datadate'/'$i'_sync/' + enddir=$type'/'$i'_sync' + mkdirmv $unzipdir'/image_0[2-3]' $rgbdir'/'$enddir + mkdirmv $unzipdir'/oxts' $oxtsdir'/'$enddir + mkdirmv $unzipdir'/velodyne_points' $velodir'/'$enddir + rm -r $datadate #remove unzipped folder + rm $shortname # remove zip file +done + + diff --git a/download/rgb_train_downloader.sh b/download/rgb_train_downloader.sh deleted file mode 100755 index 7f43060..0000000 --- a/download/rgb_train_downloader.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/bin/bash - -files=( -# 2011_09_26_calib.zip -2011_09_26_drive_0001 -# 2011_09_26_drive_0002 -# 2011_09_26_drive_0005 -2011_09_26_drive_0009 -2011_09_26_drive_0011 -# 2011_09_26_drive_0013 -2011_09_26_drive_0014 -2011_09_26_drive_0015 -2011_09_26_drive_0017 -2011_09_26_drive_0018 -2011_09_26_drive_0019 -# 2011_09_26_drive_0020 -2011_09_26_drive_0022 -# 2011_09_26_drive_0023 -2011_09_26_drive_0027 -2011_09_26_drive_0028 -2011_09_26_drive_0029 -2011_09_26_drive_0032 -2011_09_26_drive_0035 -# 2011_09_26_drive_0036 -2011_09_26_drive_0039 -2011_09_26_drive_0046 -2011_09_26_drive_0048 -2011_09_26_drive_0051 -2011_09_26_drive_0052 -2011_09_26_drive_0056 -2011_09_26_drive_0057 -2011_09_26_drive_0059 -2011_09_26_drive_0060 -2011_09_26_drive_0061 -2011_09_26_drive_0064 -2011_09_26_drive_0070 -# 2011_09_26_drive_0079 -2011_09_26_drive_0084 -2011_09_26_drive_0086 -2011_09_26_drive_0087 -2011_09_26_drive_0091 -2011_09_26_drive_0093 -# 2011_09_26_drive_0095 -2011_09_26_drive_0096 -2011_09_26_drive_0101 -2011_09_26_drive_0104 -2011_09_26_drive_0106 -# 2011_09_26_drive_0113 -2011_09_26_drive_0117 -# 2011_09_26_drive_0119 -# 2011_09_28_calib.zip -2011_09_28_drive_0001 -2011_09_28_drive_0002 -2011_09_28_drive_0016 -2011_09_28_drive_0021 -2011_09_28_drive_0034 -2011_09_28_drive_0035 -# 2011_09_28_drive_0037 -2011_09_28_drive_0038 -2011_09_28_drive_0039 -2011_09_28_drive_0043 -2011_09_28_drive_0045 -2011_09_28_drive_0047 -2011_09_28_drive_0053 -2011_09_28_drive_0054 -2011_09_28_drive_0057 -2011_09_28_drive_0065 -2011_09_28_drive_0066 -2011_09_28_drive_0068 -2011_09_28_drive_0070 -2011_09_28_drive_0071 -2011_09_28_drive_0075 -2011_09_28_drive_0077 -2011_09_28_drive_0078 -2011_09_28_drive_0080 -2011_09_28_drive_0082 -2011_09_28_drive_0086 -2011_09_28_drive_0087 -2011_09_28_drive_0089 -2011_09_28_drive_0090 -2011_09_28_drive_0094 -2011_09_28_drive_0095 -2011_09_28_drive_0096 -2011_09_28_drive_0098 -2011_09_28_drive_0100 -2011_09_28_drive_0102 -2011_09_28_drive_0103 -2011_09_28_drive_0104 -2011_09_28_drive_0106 -2011_09_28_drive_0108 -2011_09_28_drive_0110 -2011_09_28_drive_0113 -2011_09_28_drive_0117 -2011_09_28_drive_0119 -2011_09_28_drive_0121 -2011_09_28_drive_0122 -2011_09_28_drive_0125 -2011_09_28_drive_0126 -2011_09_28_drive_0128 -2011_09_28_drive_0132 -2011_09_28_drive_0134 -2011_09_28_drive_0135 -2011_09_28_drive_0136 -2011_09_28_drive_0138 -2011_09_28_drive_0141 -2011_09_28_drive_0143 -2011_09_28_drive_0145 -2011_09_28_drive_0146 -2011_09_28_drive_0149 -2011_09_28_drive_0153 -2011_09_28_drive_0154 -2011_09_28_drive_0155 -2011_09_28_drive_0156 -2011_09_28_drive_0160 -2011_09_28_drive_0161 -2011_09_28_drive_0162 -2011_09_28_drive_0165 -2011_09_28_drive_0166 -2011_09_28_drive_0167 -2011_09_28_drive_0168 -2011_09_28_drive_0171 -2011_09_28_drive_0174 -2011_09_28_drive_0177 -2011_09_28_drive_0179 -2011_09_28_drive_0183 -2011_09_28_drive_0184 -2011_09_28_drive_0185 -2011_09_28_drive_0186 -2011_09_28_drive_0187 -2011_09_28_drive_0191 -2011_09_28_drive_0192 -2011_09_28_drive_0195 -2011_09_28_drive_0198 -2011_09_28_drive_0199 -2011_09_28_drive_0201 -2011_09_28_drive_0204 -2011_09_28_drive_0205 -2011_09_28_drive_0208 -2011_09_28_drive_0209 -2011_09_28_drive_0214 -2011_09_28_drive_0216 -2011_09_28_drive_0220 -2011_09_28_drive_0222 -# 2011_09_28_drive_0225 -# 2011_09_29_calib.zip -2011_09_29_drive_0004 -# 2011_09_29_drive_0026 -2011_09_29_drive_0071 -# 2011_09_29_drive_0108 -# 2011_09_30_calib.zip -# 2011_09_30_drive_0016 -2011_09_30_drive_0018 -2011_09_30_drive_0020 -2011_09_30_drive_0027 -2011_09_30_drive_0028 -2011_09_30_drive_0033 -2011_09_30_drive_0034 -# 2011_09_30_drive_0072 -# 2011_10_03_calib.zip -2011_10_03_drive_0027 -2011_10_03_drive_0034 -2011_10_03_drive_0042 -# 2011_10_03_drive_0047 -# 2011_10_03_drive_0058 -) - -basedir='../data/data_rgb/train/' -mkdir -p $basedir -echo "Saving to "$basedir -for i in ${files[@]}; do - datadate="${i%%_drive_*}" - echo $datadate - shortname=$i'_sync.zip' - fullname=$i'/'$i'_sync.zip' - rm -f $shortname # remove zip file - echo "Downloading: "$shortname - - wget 's3.eu-central-1.amazonaws.com/avg-kitti/raw_data/'$fullname - unzip -o $shortname - mv $datadate'/'$i'_sync' $basedir$i'_sync' - rmdir $datadate - rm -rf $basedir$i'_sync/image_00' $basedir$i'_sync/image_01' $basedir$i'_sync/velodyne_points' $basedir$i'_sync/oxts' - rm $shortname # remove zip file -done - - diff --git a/download/rgb_val_downloader.sh b/download/rgb_val_downloader.sh deleted file mode 100755 index 743a905..0000000 --- a/download/rgb_val_downloader.sh +++ /dev/null @@ -1,186 +0,0 @@ -#!/bin/bash - -files=( -# 2011_09_26_calib.zip -# 2011_09_26_drive_0001 -2011_09_26_drive_0002 -2011_09_26_drive_0005 -# 2011_09_26_drive_0009 -# 2011_09_26_drive_0011 -2011_09_26_drive_0013 -# 2011_09_26_drive_0014 -# 2011_09_26_drive_0015 -# 2011_09_26_drive_0017 -# 2011_09_26_drive_0018 -# 2011_09_26_drive_0019 -2011_09_26_drive_0020 -# 2011_09_26_drive_0022 -2011_09_26_drive_0023 -# 2011_09_26_drive_0027 -# 2011_09_26_drive_0028 -# 2011_09_26_drive_0029 -# 2011_09_26_drive_0032 -# 2011_09_26_drive_0035 -2011_09_26_drive_0036 -# 2011_09_26_drive_0039 -# 2011_09_26_drive_0046 -# 2011_09_26_drive_0048 -# 2011_09_26_drive_0051 -# 2011_09_26_drive_0052 -# 2011_09_26_drive_0056 -# 2011_09_26_drive_0057 -# 2011_09_26_drive_0059 -# 2011_09_26_drive_0060 -# 2011_09_26_drive_0061 -# 2011_09_26_drive_0064 -# 2011_09_26_drive_0070 -2011_09_26_drive_0079 -# 2011_09_26_drive_0084 -# 2011_09_26_drive_0086 -# 2011_09_26_drive_0087 -# 2011_09_26_drive_0091 -# 2011_09_26_drive_0093 -2011_09_26_drive_0095 -# 2011_09_26_drive_0096 -# 2011_09_26_drive_0101 -# 2011_09_26_drive_0104 -# 2011_09_26_drive_0106 -2011_09_26_drive_0113 -# 2011_09_26_drive_0117 -2011_09_26_drive_0119 -# 2011_09_28_calib.zip -# 2011_09_28_drive_0001 -# 2011_09_28_drive_0002 -# 2011_09_28_drive_0016 -# 2011_09_28_drive_0021 -# 2011_09_28_drive_0034 -# 2011_09_28_drive_0035 -2011_09_28_drive_0037 -# 2011_09_28_drive_0038 -# 2011_09_28_drive_0039 -# 2011_09_28_drive_0043 -# 2011_09_28_drive_0045 -# 2011_09_28_drive_0047 -# 2011_09_28_drive_0053 -# 2011_09_28_drive_0054 -# 2011_09_28_drive_0057 -# 2011_09_28_drive_0065 -# 2011_09_28_drive_0066 -# 2011_09_28_drive_0068 -# 2011_09_28_drive_0070 -# 2011_09_28_drive_0071 -# 2011_09_28_drive_0075 -# 2011_09_28_drive_0077 -# 2011_09_28_drive_0078 -# 2011_09_28_drive_0080 -# 2011_09_28_drive_0082 -# 2011_09_28_drive_0086 -# 2011_09_28_drive_0087 -# 2011_09_28_drive_0089 -# 2011_09_28_drive_0090 -# 2011_09_28_drive_0094 -# 2011_09_28_drive_0095 -# 2011_09_28_drive_0096 -# 2011_09_28_drive_0098 -# 2011_09_28_drive_0100 -# 2011_09_28_drive_0102 -# 2011_09_28_drive_0103 -# 2011_09_28_drive_0104 -# 2011_09_28_drive_0106 -# 2011_09_28_drive_0108 -# 2011_09_28_drive_0110 -# 2011_09_28_drive_0113 -# 2011_09_28_drive_0117 -# 2011_09_28_drive_0119 -# 2011_09_28_drive_0121 -# 2011_09_28_drive_0122 -# 2011_09_28_drive_0125 -# 2011_09_28_drive_0126 -# 2011_09_28_drive_0128 -# 2011_09_28_drive_0132 -# 2011_09_28_drive_0134 -# 2011_09_28_drive_0135 -# 2011_09_28_drive_0136 -# 2011_09_28_drive_0138 -# 2011_09_28_drive_0141 -# 2011_09_28_drive_0143 -# 2011_09_28_drive_0145 -# 2011_09_28_drive_0146 -# 2011_09_28_drive_0149 -# 2011_09_28_drive_0153 -# 2011_09_28_drive_0154 -# 2011_09_28_drive_0155 -# 2011_09_28_drive_0156 -# 2011_09_28_drive_0160 -# 2011_09_28_drive_0161 -# 2011_09_28_drive_0162 -# 2011_09_28_drive_0165 -# 2011_09_28_drive_0166 -# 2011_09_28_drive_0167 -# 2011_09_28_drive_0168 -# 2011_09_28_drive_0171 -# 2011_09_28_drive_0174 -# 2011_09_28_drive_0177 -# 2011_09_28_drive_0179 -# 2011_09_28_drive_0183 -# 2011_09_28_drive_0184 -# 2011_09_28_drive_0185 -# 2011_09_28_drive_0186 -# 2011_09_28_drive_0187 -# 2011_09_28_drive_0191 -# 2011_09_28_drive_0192 -# 2011_09_28_drive_0195 -# 2011_09_28_drive_0198 -# 2011_09_28_drive_0199 -# 2011_09_28_drive_0201 -# 2011_09_28_drive_0204 -# 2011_09_28_drive_0205 -# 2011_09_28_drive_0208 -# 2011_09_28_drive_0209 -# 2011_09_28_drive_0214 -# 2011_09_28_drive_0216 -# 2011_09_28_drive_0220 -# 2011_09_28_drive_0222 -2011_09_28_drive_0225 -# 2011_09_29_calib.zip -# 2011_09_29_drive_0004 -2011_09_29_drive_0026 -# 2011_09_29_drive_0071 -2011_09_29_drive_0108 -# 2011_09_30_calib.zip -2011_09_30_drive_0016 -# 2011_09_30_drive_0018 -# 2011_09_30_drive_0020 -# 2011_09_30_drive_0027 -# 2011_09_30_drive_0028 -# 2011_09_30_drive_0033 -# 2011_09_30_drive_0034 -2011_09_30_drive_0072 -# 2011_10_03_calib.zip -# 2011_10_03_drive_0027 -# 2011_10_03_drive_0034 -# 2011_10_03_drive_0042 -2011_10_03_drive_0047 -2011_10_03_drive_0058 -) - -basedir='../data/data_rgb/val/' -mkdir -p $basedir -echo "Saving to "$basedir -for i in ${files[@]}; do - datadate="${i%%_drive_*}" - echo $datadate - shortname=$i'_sync.zip' - fullname=$i'/'$i'_sync.zip' - rm -f $shortname # remove zip file - echo "Downloading: "$shortname - - wget 's3.eu-central-1.amazonaws.com/avg-kitti/raw_data/'$fullname - unzip -o $shortname - mv $datadate'/'$i'_sync' $basedir$i'_sync' - rmdir $datadate - rm -rf $basedir$i'_sync/image_00' $basedir$i'_sync/image_01' $basedir$i'_sync/velodyne_points' $basedir$i'_sync/oxts' - rm $shortname # remove zip file -done - - diff --git a/reduce/calib_velo_to_cam.txt b/reduce/calib_velo_to_cam.txt new file mode 100755 index 0000000..f80c46a --- /dev/null +++ b/reduce/calib_velo_to_cam.txt @@ -0,0 +1,5 @@ +calib_time: 15-Mar-2012 11:37:16 +R: 7.533745e-03 -9.999714e-01 -6.166020e-04 1.480249e-02 7.280733e-04 -9.998902e-01 9.998621e-01 7.523790e-03 1.480755e-02 +T: -4.069766e-03 -7.631618e-02 -2.717806e-01 +delta_f: 0.000000e+00 0.000000e+00 +delta_c: 0.000000e+00 0.000000e+00 diff --git a/reduce/generate.py b/reduce/generate.py new file mode 100755 index 0000000..e2b8d7d --- /dev/null +++ b/reduce/generate.py @@ -0,0 +1,65 @@ +import os +from os import path +import sys +sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) +import glob + +from multiprocessing import Pool as ThreadPool + +from vis_utils import save_depth_as_uint16png +from reducer import create_downsampled + + + +def handle_downsampled(velo_filename, camera, factor): + l_velo_filename = os.sep.join(velo_filename.split(os.sep)[-6:]) + print("downsampling %dx into camera %d: " % (factor, camera), l_velo_filename) + + downs, d_filename = create_downsampled(velo_filename, camera, factor) + if(downs is None): + print("skip: no d") + return + + output_filename = d_filename.replace("data_depth_annotated", + "data_depth_downsampled_%dx"%factor) + if os.path.exists(output_filename): + print("skip: already exists") + return + try: + os.makedirs(os.path.dirname(output_filename)) + except OSError: + pass + + save_depth_as_uint16png(downs, output_filename) + + +def main(): + print("=> creating data loaders ...") + data_folder = os.path.join( + os.path.dirname(os.path.dirname(path.abspath(__file__))), + "data" + ) + glob_velo = os.path.join( + data_folder, "data_velo", "*", "*_sync", "velodyne_points", + "data", "*.bin" + ) + + velo_files = sorted(glob.glob(glob_velo)) + downsample_factors = [2,4,8,16,32,64] + cameras = [2,3] + parameters = [[filename, cam, factor] + for factor in downsample_factors + for cam in cameras + for filename in velo_files + ] + + pool = ThreadPool(4) + pool.starmap(handle_downsampled, parameters) + + pool.close() + pool.join() + + print("=> finished") + +if __name__ == "__main__": + main() diff --git a/reduce/reducer.py b/reduce/reducer.py new file mode 100755 index 0000000..ce02634 --- /dev/null +++ b/reduce/reducer.py @@ -0,0 +1,211 @@ +import os +from os import path +import sys +sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) + +import numpy as np +from pykitti.utils import load_oxts_packets_and_poses, load_velo_scan + +from dataloaders.kitti_loader import depth_read +from collections import namedtuple + + +def create_downsampled(velo_filename, camera, factor): + assert camera in [2, 3], "unsupported camera: {}. must be either 2 or 3".format(camera) + + d_filename = get_d_filename(velo_filename, camera) + if(not os.path.exists(d_filename)): + return None, d_filename + d, d_filename, oxts1, oxts2 = get_correct_d_oxts(d_filename, velo_filename, camera) + tx, ty, tz, roll, pitch, yaw = get_relative_motion(oxts1, oxts2) + velo_raw = load_velo_scan(velo_filename) + downsampled_velo = downsample_scan(velo_raw, factor, tx, ty, tz, roll, pitch, yaw) + height, width, _ = d.shape + calib = get_calib_downs() + near = create_near_image(calib, camera, downsampled_velo, height, width) + output = np.zeros_like(d) + output[near>0] = d[near>0] + return output, d_filename + +def get_d_filename(velo_filename, camera): + old_part = os.path.join("velodyne_points","data") + new_part = os.path.join("proj_depth", "velodyne_raw", "image_{:02d}".format(camera)) + d_filename = velo_filename\ + .replace("_velo", "_depth_annotated")\ + .replace(old_part, new_part)\ + .replace(".bin", ".png") + return d_filename + + +def get_correct_d_oxts(d_filename, velo_filename, camera): + # some velodyne raw files are missing, and PyKitti is not able to handle this + basename = os.path.basename(velo_filename) + real_id = int(os.path.splitext(basename)[0]) + d = depth_read(d_filename) + + oxts1_filename = velo_filename.replace("velodyne_points", "oxts").replace("bin", "txt") + oxts1_filename = oxts1_filename.replace("_velo", "_oxts") + assert os.path.exists(oxts1_filename), "file not found: {}".format(oxts1_filename) + oxt2_id = real_id+1 + oxts2_filename = oxts1_filename.replace(os.path.basename(oxts1_filename), "{:010d}.txt".format(oxt2_id)) + assert os.path.exists(oxts2_filename), "file not found: {}".format(oxts2_filename) + + oxts0_filename = oxts1_filename.replace(os.path.basename(oxts1_filename), "{:010d}.txt".format(0)) + assert os.path.exists(oxts0_filename), "file not found: {}".format(oxts0_filename) + + oxts1 = load_oxts_packets_and_poses([oxts0_filename, oxts1_filename])[1] + oxts2 = load_oxts_packets_and_poses([oxts0_filename, oxts2_filename])[1] + + + return d, d_filename, oxts1, oxts2 + +def get_calib_downs(): + """ + Returns calibrations parameters necessary to downsample + """ + def parse_line(lines, num, shape): + l_str = lines[num].split(":")[1].split(" ")[1:] + return np.reshape(np.array([float(p) for p in l_str]), + shape).astype(np.float32) + path.dirname(path.abspath(__file__)) + lines_v2c = open("reduce/calib_velo_to_cam.txt", "r").readlines() + R = parse_line(lines_v2c, 1, (3,3)) + T = parse_line(lines_v2c, 2, (3,1)) + T_cam0_velo_unrect = np.vstack((np.hstack([R, T]), [0, 0, 0, 1])) + lines_c2c = open("dataloaders/calib_cam_to_cam.txt", "r").readlines() + P_rect_02 = parse_line(lines_c2c, 25, (3,4)) + P_rect_03 = parse_line(lines_c2c, 33, (3,4)) + R_rect_00 = np.eye(4) + R_rect_00[0:3,0:3] = parse_line(lines_c2c, 8, (3,3)) + Calib = namedtuple('Calib',' P_rect_02 P_rect_03 R_rect_00 T_cam0_velo_unrect') + return Calib(P_rect_02, P_rect_03, R_rect_00, T_cam0_velo_unrect) + +def inverse_rigid_transformation(T_a_b): + """ + Computes the inverse transformation T_b_a from T_a_b + """ + R_a_b = T_a_b[0:3, 0:3] + t_a_b = T_a_b[0:3, 3] + R_b_a = np.transpose(R_a_b) + t_b_a = - R_b_a.dot(t_a_b).reshape(3, 1) + T_b_a = np.vstack((np.hstack([R_b_a, t_b_a]), [0, 0, 0, 1])) + return T_b_a + +def get_relative_motion(oxts1, oxts2): + """ + Gets the relative dx, dy, dz, dyaw of b2 relative to b1 + dyaw is represented in radians, not degrees + """ + T_b1_w = inverse_rigid_transformation(oxts1.T_w_imu) + T_b1_b2 = T_b1_w.dot(oxts2.T_w_imu) + tx, ty, tz = T_b1_b2[0,3], T_b1_b2[1,3], T_b1_b2[2,3] + roll = oxts2.packet.roll - oxts1.packet.roll + pitch = oxts2.packet.pitch - oxts1.packet.pitch + yaw = oxts2.packet.yaw - oxts1.packet.yaw + return tx, ty, tz, roll, pitch, yaw + +def transform_from_xyz_euler(tx, ty, tz, roll, pitch, yaw): + s = np.sin(yaw) + c = np.cos(yaw) + R = np.array([[c, -s, 0], + [s, c, 0], + [0, 0, 1]] + ) + t = np.array([tx, ty, tz]) + return R, t + +def wrap_to_0_360(deg): + while True: + indices = np.nonzero(deg<0)[0] + if len(indices)>0: + deg[indices] = deg[indices] + 360 + else: + break + + deg = ((100*deg).astype(int) % 36000) / 100.0 + return deg + +def compensate_motion(scanline, scan_time, tx, ty, tz, roll, pitch, yaw): + # x: positive forward + # y: positive to the left + # rotation angle: the lidar is spinning counter-clockwise. + # need to compensate for both positional change and angular change of the vehicle over time + for j in range(len(scanline)): + ratio = 0.5 - scan_time[j] + R, t = transform_from_xyz_euler(tx*ratio, ty*ratio, tz*ratio, roll*ratio, pitch*ratio, yaw*ratio) + raw_coordinate = scanline[j,:3].reshape(3,1) + scanline[j,:3] = R.dot(raw_coordinate).reshape(3) + t + return scanline + +def downsample_scan(velo, downsample_factor, tx, ty, tz, roll, pitch, yaw): + """ + Downsample HDL-64 scans to the target_scan + """ + x, y, z, r = velo[:,0], velo[:,1], velo[:,2], velo[:,3] + dist_horizontal = (x**2 + y**2) ** 0.5 + # angles between the start of the scan (towards the rear) + horizontal_degree = np.rad2deg(np.arctan2(y, x)) + horizontal_degree = wrap_to_0_360(horizontal_degree) + + scan_breakpoints = np.nonzero(np.diff(horizontal_degree) < -180)[0]+1 + scan_breakpoints = np.insert(scan_breakpoints, 0, 0) + scan_breakpoints = np.append(scan_breakpoints, len(horizontal_degree)-1) + num_scans = len(scan_breakpoints)-1 + + # note that sometimes not all 64 scans show up in the image space + indices = None + if downsample_factor>1: + indices = range(num_scans-downsample_factor//2, -1, -downsample_factor) + else: + indices = range(num_scans-1, -1, -1) + + assert num_scans <= 65, \ + "invalid number of scanlines: {}".format(num_scans) + + downsampled_velo = np.zeros(shape=[0, 4]) + for i in indices: + start_index = scan_breakpoints[i] + end_index = scan_breakpoints[i+1] + scanline = velo[start_index:end_index, :] + # the start of a scan is triggered at 180 degree + scan_time = wrap_to_0_360(horizontal_degree[start_index:end_index] + 180)/360 + scanline = compensate_motion(scanline, scan_time, tx, ty, tz, roll, pitch, yaw) + downsampled_velo = np.vstack((downsampled_velo, scanline)) + assert downsampled_velo.shape[0]>0, "downsampled velodyne has 0 measurements" + + return downsampled_velo + +def create_near_image(calib, cam, velo, height, width): + # velodyne->image plane + N = velo.shape[0] + p_in = np.hstack((velo[:,0:3], np.ones((N,1)))) + if cam==2: + P_velo_to_img = calib.P_rect_02.dot(calib.R_rect_00.dot(calib.T_cam0_velo_unrect)) + elif cam==3: + P_velo_to_img = calib.P_rect_03.dot(calib.R_rect_00.dot(calib.T_cam0_velo_unrect)) + else: + assert False, "invalid camera: {}".format(cam) + + p_out = np.dot(P_velo_to_img, p_in.transpose()) + + # normalize to get pixel location + Z = p_out[2] + U = p_out[0] / Z + V = p_out[1] / Z + + # create near depth image + distMax = 1 + near_image = np.zeros((height, width)) + [-1, 0 , 1] + for u,v,z in zip(U,V,Z): + if z<0: + continue + uv = [u,v] + uvlim = np.array((width, height)) + uvmin = [int(max(np.ceil(uv[i]-distMax),0)) for i in [0,1]] + uvmax = [int(min(max(np.floor(uv[i]+distMax),-1),uvlim[i])) for i in [0,1]] + near_image[uvmin[1]:uvmax[1]+1, uvmin[0]:uvmax[0]+1] = 1 + + assert np.sum(near_image>0)>0, "near image has no near points" + return near_image +