-
Notifications
You must be signed in to change notification settings - Fork 4
MCAP databags support and use_compressed_images feature #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chrislai502
wants to merge
12
commits into
amansrf:main
Choose a base branch
from
Chrislai502:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
43ec5be
Initial Implementation
Chrislai502 c95444b
Mcap support with compressed selection feature done
Chrislai502 0e7ab4e
Merge pull request #1 from Chrislai502/chris/mcap_support
Chrislai502 46735e1
README.md
Chrislai502 39104cd
Debugging, cd into wrong folder. If topic doesn't exist, just skip
KaushikKunal 787e62e
Previous commit was also chris, please do not set global configs guys
Chrislai502 b4f5f45
Solved file descriptor issue in ffmpeg
Chrislai502 60092eb
Merge pull request #2 from FHL-VIVE-Center-for-Enhanced-Reality/main
Chrislai502 31c283a
Handling edge cases where ROSBAG does not have images, or missing cer…
Chrislai502 0a30d5e
Merge pull request #3 from FHL-VIVE-Center-for-Enhanced-Reality/main
Chrislai502 07016b4
cleanup, tested
Chrislai502 9cb592c
Merge pull request #4 from airacingtech/main
Chrislai502 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # Ignore output folder | ||
| output/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 # | ||
|
|
@@ -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 "----------------------------------------------------------------------------" | ||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| # 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 # | ||
|
|
@@ -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") | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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