Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Ignore output folder
output/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Use the following steps to extract data from a rosbag, remove image distortions,

# Contact
* Aman Saraf | [amansaraf99@gmail.com](mailto:amansaraf99@gmail.com)
* Chris Lai | [chris.lai@berkeley.edu](mailto:chris.lai@berkeley.edu)



Expand Down
99 changes: 76 additions & 23 deletions multi_extract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# ---------------------------------------------------------------------------- #
# DEFAULT VARIABLES #
# ---------------------------------------------------------------------------- #
DATA_DIR_DEFAULT="/media/Public/ROSBAG_BACKUPS/rosbag2_2022_09_21-12_58_49"
VERBOSE_DEFAULT=1
DATA_DIR_DEFAULT="/media/art-berk/DRIVE2_ART/rosbags/"
VERBOSE_DEFAULT=0
UNDISTORT_DEFAULT=1
CALIB_DIR_DEFAULT="/home/roar/ART/perception/Camera/Calibration_new/"
OUTPUT_BASE_DIR_DEFAULT="/media/Public/Lucas_Oil/"
# CALIB_DIR_DEFAULT="/home/roar/ART/perception/Camera/Calibration_new/"
CALIB_DIR_DEFAULT="/home/art-berk/IAC_dataset_maker/putnam_calib/"
OUTPUT_BASE_DIR_DEFAULT="/home/art-berk/IAC_dataset_maker/output/"
MAKE_VID_DEFAULT=1
USE_COMPRESSED_DEFAULT=0

# ---------------------------------------------------------------------------- #
# PARSE ENVIRONMENT VARIABLES #
Expand Down Expand Up @@ -52,6 +54,18 @@ else
echo "----------------------------------------------------------------------------"
fi

# ------------------------ USE_COMPRESSED SETTINGS --------------------------- #
if [ -z ${USE_COMPRESSED+x} ]; then
echo "----------------------------------------------------------------------------"
USE_COMPRESSED=$USE_COMPRESSED_DEFAULT
echo " USE_COMPRESSED not defined. Setting USE_COMPRESSED to $USE_COMPRESSED. "
echo "----------------------------------------------------------------------------"
else
echo "----------------------------------------------------------------------------"
echo " USE_COMPRESSED has been defined as $USE_COMPRESSED "
echo "----------------------------------------------------------------------------"
fi

# --------------------------- UNDISTORTION SETTINGS -------------------------- #
if [ -z ${UNDISTORT:+x} ]; then
echo "----------------------------------------------------------------------------"
Expand Down Expand Up @@ -90,8 +104,8 @@ else
fi
# --------------------- ENVIRONMENT VARIABLE PARSING END --------------------- #

echo "\nPausing for 10 seconds. Press Ctrl+C to quit if the above settings are not correct.\n"
for i in 1 2 3 4 5 6 7 8 9 10
echo "\nPausing for 5 seconds. Press Ctrl+C to quit if the above settings are not correct.\n"
for i in 1 2 3 4 5
do
echo "$i seconds passed"
sleep 1s
Expand All @@ -102,9 +116,20 @@ done
# Find all rosbags at datadir and extract data #
# ---------------------------------------------------------------------------- #
echo "\n\nSearching DATA_DIR for ROSBAGS now...\n"
sleep 5s
find "$DATA_DIR" -iname "*.db3" -print0 | xargs -0 -I file dirname file | sort | uniq | while read d; do
ROSBAG_NAME=$(basename "$d")
root_dir=$(pwd)
sleep 2s
# find "$DATA_DIR" \( -iname "*.db3" -o -iname "*.mcap" \) -print0 | xargs -0 -I file dirname file | while read d; do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why leave it commented? What you have added right after seems to be an improvement. If this is for backwards compatibility, either version the script or add a flag? Preference is to delete

# find "$DATA_DIR" \( -iname "*.db3" -o -iname "*.mcap" \) -print0 | xargs -0 -I file dirname file | sort -u | while IFS= read -r d; do
# echo "$d"
# done
find "$DATA_DIR" \( -iname "*.db3" -o -iname "*.mcap" \) -print0 | xargs -0 -I file dirname file | sort -u > /tmp/tempfile.txt


# find "$DATA_DIR" \( -iname "*.db3" -o -iname "*.mcap" \) -print0 | xargs -0 -I file dirname file | sort -u | while IFS= read -r d; do
while IFS= read -r line; do

ROSBAG_NAME=$(basename "$line")
# echo "ROSBAG_NAME $ROSBAG_NAME"

# ---------------------------------------------------------------------------- #
# NOTE: SPECIFY OUTPUT DIR #
Expand All @@ -115,35 +140,63 @@ find "$DATA_DIR" -iname "*.db3" -print0 | xargs -0 -I file dirname file | sort |

# ------------------------------ Debug Verbosity ----------------------------- #
echo "----------------------------------------------------------------------------"
echo "Found ROSBAG: $d"
echo "Found ROSBAG: $line"
echo "Extracting images to: $OUTPUT_DIR"
echo "----------------------------------------------------------------------------"

# -------------------------- Create output Directory ------------------------- #
mkdir -p $OUTPUT_DIR
mkdir -p "$OUTPUT_DIR"

# ------------------ Begin Extraction Based on User Setting ------------------ #
cd "$root_dir"

if [ $VERBOSE -eq 1 ]; then
if [ $UNDISTORT -eq 1 ]; then
python3 ros2bag_image_extractor.py "$d" $OUTPUT_DIR -vup $CALIB_DIR
if [ $USE_COMPRESSED -eq 1 ]; then
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -vucp "$CALIB_DIR"
else
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -vup "$CALIB_DIR"
fi
else
python3 ros2bag_image_extractor.py "$d" $OUTPUT_DIR -v
if [ $USE_COMPRESSED -eq 1 ]; then
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -vc
else
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -v
fi
fi
else
if [ $UNDISTORT -eq 1 ]; then
python3 ros2bag_image_extractor.py "$d" $OUTPUT_DIR -up $CALIB_DIR
if [ $USE_COMPRESSED -eq 1 ]; then
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -ucp "$CALIB_DIR"
else
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -up "$CALIB_DIR"
fi
else
python3 ros2bag_image_extractor.py "$d" $OUTPUT_DIR
if [ $USE_COMPRESSED -eq 1 ]; then
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR" -c
else
python3 ros2bag_image_extractor.py "$line" "$OUTPUT_DIR"
fi
fi
fi

# --------------------- Convert Extracted Images to Video -------------------- #
if [ $MAKE_VID -eq 1 ]; then
for camera_output_dir in $OUTPUT_DIR/*/; do
cd $camera_output_dir
base_name=$(basename "$camera_output_dir")
ffmpeg -framerate 50 -pattern_type glob -i '*.jpg' -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p ../$base_name.mp4
done
fi
if [ ! -d "$OUTPUT_DIR" ] || [ -z "$(ls -A $OUTPUT_DIR)" ]; then # Check if the output directory is not empty first
if [ $MAKE_VID -eq 1 ]; then
for camera_output_dir in "$OUTPUT_DIR"/*/; do
base_name=$(basename "$camera_output_dir")

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahaha. Interesting!

done
# Ah, that narrows things down a bit. The behavior you're seeing could be related to ffmpeg inadvertently reading from standard input, which affects the subsequent iterations of the loop that reads from /tmp/tempfile.txt.
# Here's a solution: redirect the standard input of ffmpeg to /dev/null. This ensures that ffmpeg won't interfere with the input being read by the loop.
# Modify the ffmpeg line as follows:
ffmpeg -framerate 50 -pattern_type glob -i "$camera_output_dir/*.jpg" -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p "./output/$ROSBAG_NAME/$base_name.mp4" > /dev/null 2>&1 < /dev/null

done
fi
fi
sleep 1s
# done
done < /tmp/tempfile.txt

rm /tmp/tempfile.txt
find $OUTPUT_BASE_DIR_DEFAULT -type d -empty -delete # Cleanup Empty Directories
27 changes: 27 additions & 0 deletions organizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil

# Define the paths
first_path = '/home/art-berk/IAC_dataset_maker/output'
second_path = '/media/art-berk/DRIVE2_ART/rosbags'

# Ensure 'rosbag_with_images_extracted' directory exists
destination_folder = os.path.join(second_path, 'rosbag_with_images_extracted')
os.makedirs(destination_folder, exist_ok=True)

# Get a set of all directory names in first path
first_path_dirs = {dir_name for dir_name in os.listdir(first_path)
if os.path.isdir(os.path.join(first_path, dir_name))}

# Iterate over all directories in the second path
for dir_name in os.listdir(second_path):
dir_path = os.path.join(second_path, dir_name)
# Check if it's a directory and not the destination directory
if dir_name not in first_path_dirs or not os.path.isdir(dir_path) or dir_path == destination_folder:
continue # Skip if no match or it's not a directory or if it is the destination directory

# Move matched directory to the 'rosbag_with_images_extracted' directory
shutil.move(dir_path, destination_folder)
print(f"Moved '{dir_name}' to '{destination_folder}'")

print("Operation completed.")
23 changes: 23 additions & 0 deletions putnam_calib/vimba_front_left.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
camera_matrix:
rows: 3
cols: 3
data:
- 243.762740
- 0.000000
- 259.440156
- 0.000000
- 244.236210
- 191.623041
- 0.000000
- 0.000000
- 1.000000

distortion_coefficients:
rows: 1
cols: 5
data:
- -0.179154
- 0.041029
- -0.001240
- 0.000456
- 0.000000
23 changes: 23 additions & 0 deletions putnam_calib/vimba_front_left_center.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
camera_matrix:
rows: 3
cols: 3
data:
- 1637.855960
- 0.000000
- 546.820824
- 0.000000
- 1629.665877
- 367.335716
- 0.000000
- 0.000000
- 1.000000

distortion_coefficients:
rows: 1
cols: 5
data:
- -0.316097
- 0.461574
- -0.001655
- 0.004033
- 0.000000
23 changes: 23 additions & 0 deletions putnam_calib/vimba_front_right.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
camera_matrix:
rows: 3
cols: 3
data:
- 241.574152
- 0.000000
- 245.622459
- 0.000000
- 240.962419
- 188.186666
- 0.000000
- 0.000000
- 1.000000

distortion_coefficients:
rows: 1
cols: 5
data:
- -0.182866
- 0.042365
- -0.001724
- -0.000473
- 0.000000
23 changes: 23 additions & 0 deletions putnam_calib/vimba_front_right_center.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
camera_matrix:
rows: 3
cols: 3
data:
- 1669.803681
- 0.000000
- 550.637949
- 0.000000
- 1667.774209
- 261.517346
- 0.000000
- 0.000000
- 1.000000

distortion_coefficients:
rows: 1
cols: 5
data:
- -0.285679
- -0.003097
- -0.007689
- -0.000588
- 0.000000
Loading