Access images from within a ROSBAG

조회 수: 4 (최근 30일)
MP
MP 2018년 6월 28일
댓글: Joseph Seklawy 2022년 4월 20일
I have a rosbag which contains several sets of images from an Intel D435 camera (I have it in both compressed and uncompressed form (compressed data shown))
BAG =
BagSelection with properties:
FilePath: '/home/Documents/20180628_212236.orig.bag'
StartTime: 1.0000e-09
EndTime: 8.0653
NumMessages: 2619
AvailableTopics: [75×3 table]
AvailableFrames: {0×1 cell}
MessageList: [2619×4 table]
I think I want the data stored in
/device_0/sensor_0/Depth_0/image/data (see below)
Can anyone please advise how I access the image data. Thanks
>>BAG.AvailableTopics
ans =
75×3 table
NumMessages MessageType MessageDefinition
___________ _________________________ ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
/device_0/info 7 diagnostic_msgs/KeyValue 'char Key↵char Value↵'
/device_0/sensor_0/Depth_0/image/data 71 sensor_msgs/Image 'std_msgs/Header Header↵ uint32 Seq↵ Time Stamp↵ char FrameId↵uint32 Height↵uint32 Width↵char Encoding↵uint8 IsBigendian↵uint32 Step↵uint8[] Data↵'
/device_0/sensor_0/Depth_0/image/metadata 781 diagnostic_msgs/KeyValue 'char Key↵char Value↵'
/device_0/sensor_0/Depth_0/info 1 realsense_msgs/StreamInfo 'uint32 Fps↵char Encoding↵logical IsRecommended↵'
/device_0/sensor_0/Depth_0/info/camera_info 1 sensor_msgs/CameraInfo 'std_msgs/Header Header↵ uint32 Seq↵ Time Stamp↵ char FrameId↵uint32 Height↵uint32 Width↵char DistortionModel↵double[] D↵double[9] K↵double[9] R↵double[12] P↵uint32 BinningX↵uint32 BinningY↵sensor_msgs/RegionOfInterest Roi↵ uint32 XOffset↵ uint32 YOffset↵ uint32 Height↵ uint32 Width↵ logical DoRectify↵'
/device_0/sensor_0/Depth_0/tf/0 1 geometry_msgs/Transform 'geometry_msgs/Vector3 Translation↵ double X↵ double Y↵ double Z↵geometry_msgs/Quaternion Rotation↵ double X↵ double Y↵ double Z↵ double W↵'
/device_0/sensor_0/Infrared_1/image/data 71 sensor_msgs/Image 'std_msgs/Header Header↵ uint32 Seq↵ Time Stamp↵ char FrameId↵uint32 Height↵uint32 Width↵char Encoding↵uint8 IsBigendian↵uint32 Step↵uint8[] Data↵'
/device_0/sensor_0/Infrared_1/image/metadata 781 diagnostic_msgs/KeyValue 'char Key↵char Value↵'
/device_0/sensor_0/Infrared_1/info 1 realsense_msgs/StreamInfo 'uint32 Fps↵char Encoding↵logical IsRecommended↵'
/device_0/sensor_0/Infrared_1/info/camera_info 1 sensor_msgs/CameraInfo 'std_msgs/Header Header↵ uint32 Seq↵ Time Stamp↵ char FrameId↵uint32 Height↵uint32 Width↵char DistortionModel↵double[] D↵double[9] K↵double[9] R↵double[12] P↵uint32 BinningX↵uint32 BinningY↵sensor_msgs/RegionOfInterest Roi↵ uint32 XOffset↵ uint32 YOffset↵ uint32 Height↵ uint32 Width↵ logical DoRectify↵'
/device_0/sensor_0/Infrared_1/tf/0 1 geometry_msgs/Transform 'geometry_msgs/Vector3 Translation↵ double X↵ double Y↵ double Z↵geometry_msgs/Quaternion Rotation↵ double X↵ double Y↵ double Z↵ double W↵'
/device_0/sensor_0/info 1 diagnostic_msgs/KeyValue 'char Key↵char Value↵'
/device_0/sensor_0/option/Asic Temperature/description 1 std_msgs/String 'char Data↵'
/device_0/sensor_0/option/Asic Temperature/value 1 std_msgs/Float32 'single Data↵'
/device_0/sensor_0/option/Depth Units/description 1 std_msgs/String 'char Data↵'
/device_0/sensor_0/option/Depth Units/value 1 std_msgs/Float32 'single Data↵'
/device_0/sensor_0/option/Emitter Enabled/description 1 std_msgs/String 'char Data↵'
/device_0/sensor_0/option/Emitter Enabled/value 1 std_msgs/Float32 'single Data↵'
/device_0/sensor_0/option/Enable Auto Exposure/description 1 std_msgs/String 'char Data↵'
/device_0/sensor_0/option/Enable Auto Exposure/value 1 std_msgs/Float32 'single Data↵'
/device_0/sensor_0/option/Error Polling Enabled/description 1 std_msgs/String 'char Data↵'

답변 (1개)

MP
MP 2018년 7월 13일
To answer my own question (just in case anyone is interested) -------------------------------
function ROSBAG_Reader
%%%%%%%%%% Hard coded bits %%%%%%%%%%%%%%%%%%%%%%%
startT = 5 %start time for image extraction
endT = 6 % end time for image extraction
depthLim =1000; %remove all depth data greater than depthLim
fn = ('test.bag');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%image data stored in the following
dataType = {'/device_0/sensor_0/Depth_0/image/data';...
'/device_0/sensor_0/Infrared_1/image/data';...
'/device_0/sensor_1/Color_0/image/data'};
% not interested in infrared data
for i=1:2:3
dataT=dataType{i}
bag = rosbag(fn)
bagselect1 = select(bag, 'Topic', dataT)
bagselect2 = select(bag, 'Time', [startT endT], 'Topic', dataT)
bagselect2.AvailableTopics{1,end}
bagselect3 = select(bagselect2, 'Time', [startT endT])
msgs = readMessages(bagselect3);
msgs{1}
for j=1:size(msgs,1)
[img,alpha] = readImage(msgs{1});
try
figure(1)
imshow(img,[min(min(img)) max(max(img))/10]);colormap(jet)
img=double(img);
img(img>depthLim)=0;
img(img==0)=NaN; % get rid of spurious daa from mesh plot
figure(2); mesh(img)
catch
figure(3)
imshow(img)
end
clear img
end
end

카테고리

Help CenterFile Exchange에서 ROS Log Files and Transformations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by