-
Notifications
You must be signed in to change notification settings - Fork 3
/
extractor.sh
executable file
·77 lines (63 loc) · 3.18 KB
/
extractor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
#Usage: bash extractor input_directory output_directory
use_cpp_extractor=true
if [ "$#" -ne 1 ] && [ "$#" -ne 2 ]; then
echo "Usage: extractor input_directory or extractor input_directory output_directory"
exit
fi
#This block is to get exact path of the current script since internal structure of the repo path assumed to be constant
#and Azure tools are inside
SOURCE=${BASH_SOURCE[0]}
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
TIMESTAMPS_EXTRACTOR_EXE="Azure-Kinect-Sensor-SDK/build/bin/mrob_timestamps_extractor"
IMU_DATA_EXTRACTOR_EXE="Azure-Kinect-Sensor-SDK/build/bin/mrob_imu_data_extractor"
CALIB_PARAMS_EXTRACTOR_EXE="Azure-Kinect-Sensor-SDK/build/bin/mrob_calibration_params_extractor"
IMAGES_EXTRACTOR_EXE=Azure-Kinect-Sensor-SDK/build/bin/mrob_images_extractor
input_path="$1"
if [ "$#" -eq 1 ]; then
output_path="$DIR/extracted-data/$(basename -- $1)"
else
output_path="$2/$(basename -- $1)"
fi
rm -rf $output_path
for mkv_path in $(find $input_path -name '*.mkv' | sed 's,.*/,,' | sed 's,.mkv,,');
do
mkdir -p $output_path/$mkv_path/{color,depth}
#,point_cloud}
cp $input_path/$mkv_path'.csv' $output_path/$mkv_path/global_timestamps.csv
if [ $use_cpp_extractor = true ]; then
$IMAGES_EXTRACTOR_EXE --mode 1 $input_path/$mkv_path'.mkv' $output_path/$mkv_path
$TIMESTAMPS_EXTRACTOR_EXE $input_path/$mkv_path'.mkv' $output_path/$mkv_path
$IMU_DATA_EXTRACTOR_EXE $input_path/$mkv_path'.mkv' $output_path/$mkv_path/imu.csv
$CALIB_PARAMS_EXTRACTOR_EXE $input_path/$mkv_path'.mkv' $output_path/$mkv_path/calib_params.json
else
ffmpeg -i $input_path/$mkv_path'.mkv' -map 0:0 -vsync 0 $output_path/$mkv_path/color/%d.png
ffmpeg -i $input_path/$mkv_path'.mkv' -map 0:1 -vsync 0 $output_path/$mkv_path/depth/%d.png
#ffmpeg -i $input_path/$mkv_path'.mkv' -map 0:2 -vsync 0 $output_path/$mkv_path/ir/%d.png
$TIMESTAMPS_EXTRACTOR_EXE $input_path/$mkv_path'.mkv' $output_path/$mkv_path
$IMU_DATA_EXTRACTOR_EXE $input_path/$mkv_path'.mkv' $output_path/$mkv_path/imu.csv
$CALIB_PARAMS_EXTRACTOR_EXE $input_path/$mkv_path'.mkv' $output_path/$mkv_path/calib_params.json
sed -i '1d' $output_path/$mkv_path/color_timestamps.csv
N=1
while read new_name;
do
new_name_formatted=$(printf "%012d" $new_name)
mv $output_path/$mkv_path'/color/'$N'.png' $output_path/$mkv_path'/color/'$new_name_formatted'.png'
((N++))
done < $output_path/$mkv_path/color_timestamps.csv;
sed -i '1d' $output_path/$mkv_path/depth_timestamps.csv;
N=1
while read new_name
do
new_name_formatted=$(printf "%012d" $new_name)
mv $output_path/$mkv_path'/depth/'$N'.png' $output_path/$mkv_path'/depth/'$new_name_formatted'.png'
((N++))
done < $output_path/$mkv_path/depth_timestamps.csv;
#rm $output_path/$mkv_path/color_timestamps.csv $output_path/$mkv_path/depth_timestamps.csv
fi
done