-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rosbag viewing and converting tools
- Loading branch information
Showing
6 changed files
with
242 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -9,3 +9,4 @@ keras>=2.0.0 | |
tensorflow-gpu>=1.0.0 | ||
h5py | ||
pygame | ||
moviepy |
This file contains 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 |
---|---|---|
|
@@ -9,3 +9,4 @@ keras>=2.0.0 | |
tensorflow>=1.0.0 | ||
h5py | ||
pygame | ||
moviepy |
This file contains 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,70 @@ | ||
#!/usr/bin/python | ||
""" | ||
view_rosbag_video.py: version 0.1.0 | ||
Note: | ||
Part of this code was copied and modified from github.com/comma.ai/research (code: BSD License) | ||
Todo: | ||
Update steering angle projection. Current version is a hack from comma.ai's version | ||
Update enable left, center and right camera selection. Currently all three cameras are displayed. | ||
Update to enable display of trained steering data (green) as compared to actual (blue projection). | ||
History: | ||
2016/10/06: Update to add --skip option to skip the first X seconds of data from rosbag. | ||
2016/10/02: Initial version to display left, center, right cameras and steering angle. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
import re | ||
import os | ||
import cv2 | ||
import numpy as np | ||
import rosbag | ||
import datetime | ||
import serialrosbags | ||
from cv_bridge import CvBridge | ||
import moviepy.editor as mpy | ||
|
||
bridge = CvBridge() | ||
bags = None | ||
|
||
def make_frame(t): | ||
global bridge | ||
global bags | ||
while bags.has_data(): | ||
try: | ||
topic, msg, t = bags.read_messages() | ||
if topic == '/image_raw': | ||
return cv2.resize(bridge.imgmsg_to_cv2(msg, "rgb8"), (800, 600), interpolation=cv2.INTER_AREA) | ||
except: | ||
pass | ||
return None | ||
|
||
# ***** main loop ***** | ||
if __name__ == "__main__": | ||
defaultOutput = 'out.gif' | ||
parser = argparse.ArgumentParser(description='Udacity SDC Challenge-2 Video viewer 2') | ||
parser.add_argument('--datasets', type=str, default="dataset1.bag:dataset2.bag:dataset3.bag:dataset4.bag", help='Dataset/ROS Bag name') | ||
parser.add_argument('outfilename', type=str, default=defaultOutput, help='video output file') | ||
args = parser.parse_args() | ||
videopattern = re.compile("^.+\.gif$") | ||
|
||
if videopattern.match(args.outfilename): | ||
if os.path.exists(args.outfilename): | ||
print("Video output file: %s exists. %s" % ( | ||
args.outfilename, pleaseRemove)) | ||
sys.exit(2) | ||
else: | ||
videoout = args.outfilename | ||
valid = True | ||
else: | ||
print(invalidExt % ("video", validVideoExt)) | ||
sys.exit(3) | ||
|
||
datasets = args.datasets | ||
bags = serialrosbags.Bags(datasets, ['/current_pose','/image_raw']) | ||
|
||
clip = mpy.VideoClip(make_frame, duration=14) | ||
clip.write_gif(videoout, fps=24) | ||
|
This file contains 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,70 @@ | ||
#!/usr/bin/python | ||
""" | ||
view_rosbag_video.py: version 0.1.0 | ||
Note: | ||
Part of this code was copied and modified from github.com/comma.ai/research (code: BSD License) | ||
Todo: | ||
Update steering angle projection. Current version is a hack from comma.ai's version | ||
Update enable left, center and right camera selection. Currently all three cameras are displayed. | ||
Update to enable display of trained steering data (green) as compared to actual (blue projection). | ||
History: | ||
2016/10/06: Update to add --skip option to skip the first X seconds of data from rosbag. | ||
2016/10/02: Initial version to display left, center, right cameras and steering angle. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
import re | ||
import os | ||
import cv2 | ||
import numpy as np | ||
import rosbag | ||
import datetime | ||
import serialrosbags | ||
from cv_bridge import CvBridge | ||
import moviepy.editor as mpy | ||
|
||
bridge = CvBridge() | ||
bags = None | ||
|
||
def make_frame(t): | ||
global bridge | ||
global bags | ||
while bags.has_data(): | ||
try: | ||
topic, msg, t = bags.read_messages() | ||
if topic == '/image_raw': | ||
return cv2.resize(bridge.imgmsg_to_cv2(msg, "rgb8"), (800, 600), interpolation=cv2.INTER_AREA) | ||
except: | ||
pass | ||
return None | ||
|
||
# ***** main loop ***** | ||
if __name__ == "__main__": | ||
defaultOutput = 'out.mp4' | ||
parser = argparse.ArgumentParser(description='Udacity SDC Challenge-2 Video viewer 2') | ||
parser.add_argument('--datasets', type=str, default="dataset1.bag:dataset2.bag:dataset3.bag:dataset4.bag", help='Dataset/ROS Bag name') | ||
parser.add_argument('outfilename', type=str, default=defaultOutput, help='video output file') | ||
args = parser.parse_args() | ||
videopattern = re.compile("^.+\.mp4$") | ||
|
||
if videopattern.match(args.outfilename): | ||
if os.path.exists(args.outfilename): | ||
print("Video output file: %s exists. %s" % ( | ||
args.outfilename, pleaseRemove)) | ||
sys.exit(2) | ||
else: | ||
videoout = args.outfilename | ||
valid = True | ||
else: | ||
print(invalidExt % ("video", validVideoExt)) | ||
sys.exit(3) | ||
|
||
datasets = args.datasets | ||
bags = serialrosbags.Bags(datasets, ['/current_pose','/image_raw']) | ||
|
||
clip = mpy.VideoClip(make_frame, duration=14) | ||
clip.write_videofile(videoout, fps=24, audio=False) | ||
|
This file contains 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,88 @@ | ||
#!/usr/bin/python | ||
""" | ||
view_rosbag_video.py: version 0.1.0 | ||
Note: | ||
Part of this code was copied and modified from github.com/comma.ai/research (code: BSD License) | ||
Todo: | ||
Update steering angle projection. Current version is a hack from comma.ai's version | ||
Update enable left, center and right camera selection. Currently all three cameras are displayed. | ||
Update to enable display of trained steering data (green) as compared to actual (blue projection). | ||
History: | ||
2016/10/06: Update to add --skip option to skip the first X seconds of data from rosbag. | ||
2016/10/02: Initial version to display left, center, right cameras and steering angle. | ||
""" | ||
|
||
import argparse | ||
import sys | ||
import numpy as np | ||
import pygame | ||
import rosbag | ||
import datetime | ||
import cStringIO | ||
import serialrosbags | ||
from cv_bridge import CvBridge | ||
|
||
#from keras.models import model_from_json | ||
|
||
pygame.init() | ||
size = None | ||
width = None | ||
height = None | ||
screen = None | ||
|
||
# ***** main loop ***** | ||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Udacity SDC Challenge-2 Video viewer 2') | ||
parser.add_argument('--datasets', type=str, default="dataset1.bag:dataset2.bag:dataset3.bag:dataset4.bag", help='Dataset/ROS Bag name') | ||
parser.add_argument('--skip', type=int, default="0", help='skip seconds') | ||
args = parser.parse_args() | ||
|
||
datasets = args.datasets | ||
skip = args.skip | ||
startsec = 0 | ||
angle_steers = 0.0 | ||
blue = (0, 0, 255) | ||
green = (0, 255, 0) | ||
|
||
bridge = CvBridge() | ||
bags = serialrosbags.Bags(datasets, ['/current_pose','/image_raw']) | ||
|
||
while bags.has_data(): | ||
try: | ||
topic, msg, t = bags.read_messages() | ||
if startsec == 0: | ||
startsec = t.to_sec() | ||
if skip < 24*60*60: | ||
skipping = t.to_sec() + skip | ||
print "skipping ", skip, " seconds from ", startsec, " to ", skipping, " ..." | ||
else: | ||
skipping = skip | ||
print "skipping to ", skip, " from ", startsec, " ..." | ||
else: | ||
if t.to_sec() > skipping: | ||
if topic in ['/current_pose', '/image_raw']: | ||
blue = (255, 0, 0) | ||
print(topic, msg.header.seq, t-msg.header.stamp, t) | ||
|
||
if topic == '/image_raw': | ||
|
||
height = int(msg.height) | ||
width = int(msg.width) | ||
if size is None: | ||
size = (width, height) | ||
pygame.display.set_caption("Udacity SDC ROSBAG: camera video viewer") | ||
screen = pygame.display.set_mode(size, pygame.DOUBLEBUF) | ||
print "size: ", size | ||
|
||
img = bridge.imgmsg_to_cv2(msg, "rgb8") | ||
sim_img = pygame.image.fromstring(img.tobytes(), size, 'RGB') | ||
|
||
screen.blit(sim_img, (0,0)) | ||
pygame.display.flip() | ||
|
||
else: | ||
print "skipping ", skip, " seconds from ", t.to_sec(), " to ", skipping, " ..." | ||
except: | ||
pass |