Skip to content

Commit

Permalink
lots of work on matlab half of the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Lior Ramati committed Aug 14, 2018
1 parent 30e7fc9 commit 7ecf0a5
Show file tree
Hide file tree
Showing 24 changed files with 574 additions and 92 deletions.
15 changes: 15 additions & 0 deletions wrappers/matlab/camera_info.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
classdef camera_info < int64
enumeration
name ( 0)
serial_number ( 1)
firmware_version ( 2)
recommended_firmware_version ( 3)
physical_port ( 4)
debug_op_code ( 5)
advanced_mode ( 6)
product_id ( 7)
camera_locked ( 8)
usb_type_descriptor ( 9)
count (10)
end
end
7 changes: 5 additions & 2 deletions wrappers/matlab/depth_frame.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
% Destructor (uses base class destructor)

% Functions
function width = get_distance(this, x, y)
realsense.librealsense_mex('rs2::depth_frame', 'get_distance', this.objectHandle, int64(x), int64(y));
function distance = get_distance(this, x, y)
narginchk(3, 3);
validateattributes(x, {'numeric'}, {'scalar', 'nonnegative', 'real', 'integer'}, '', 'x', 2);
validateattributes(y, {'numeric'}, {'scalar', 'nonnegative', 'real', 'integer'}, '', 'y', 2);
distance = realsense.librealsense_mex('rs2::depth_frame', 'get_distance', this.objectHandle, int64(x), int64(y));
end
end
end
16 changes: 16 additions & 0 deletions wrappers/matlab/depth_sensor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% Wraps librealsense2 depth_sensor class
classdef depth_sensor < sensor
methods
% Constructor
function this = depth_sensor(handle)
this = [email protected](handle);
end

% Destructor (uses base class destructor)

% Functions
function scale = get_depth_scale(this)
scale = realsense.librealsense_mex('rs2::depth_sensor', 'get_depth_scale', this.objectHandle);
end
emd
end
16 changes: 16 additions & 0 deletions wrappers/matlab/depth_stereo_sensor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% Wraps librealsense2 depth_stereo_sensor class
classdef depth_stereo_sensor < depth_sensor
methods
% Constructor
function this = depth_stereo_sensor(handle)
this = [email protected]_sensor(handle);
end

% Destructor (uses base class destructor)

% Functions
function scale = get_stereo_baseline(this)
scale = realsense.librealsense_mex('rs2::depth_stereo_sensor', 'get_stereo_baseline', this.objectHandle);
end
emd
end
56 changes: 35 additions & 21 deletions wrappers/matlab/device.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ function do_init(this)
methods
% Constructor
function this = device(handle, index)
narginchk(1, 2);
validateattributes(handle, {'uint64'}, {'scalar'});
this.objectHandle = handle;
if (nargin == 1) % constructed from device
this.id = -1;
else % lazily "constructed" from device_list
this.id = index;
validateattributes(index, {'numeric'}, {'scalar', 'real', 'integer'});
this.id = int64(index);
end
end
% Destructor
Expand All @@ -40,37 +43,48 @@ function delete(this)
[sensor_array{1:nargout}] = arrayfun(@realsense.sensor, arr, 'UniformOutput', false);
end
function sensor = first(this, type)
narginchk(2, 2);
% C++ function validates contents of type
validateattributes(type, {'char', 'string'}, {'scalartext'}, '', 'type', 2);
this.do_init();
out = realsense.librealsense_mex('rs2::device', 'first', this.objectHandle, type);
switch (type)
case 'sensor'
sensor = realsense.sensor(out);
case 'roi_sensor'
sensor = realsense.roi_sensor(out);
case 'depth_sensor'
sensor = realsense.depth_sensor(out);
end
sensor = realsense.sensor(out).as(type);
end
function value = supports(this, info)
narginchk(2, 2);
validateattributes(info, {'realsense.camera_info', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.camera_info.count}, '', 'info', 2);
this.do_init();
value = realsense.librealsense_mex('rs2::device', 'supports', this.objectHandle, int64(info));
end
function value = get_info(this, info)
narginchk(2, 2);
validateattributes(info, {'realsense.camera_info', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.camera_info.count}, '', 'info', 2);
this.do_init();
info = realsense.librealsense_mex('rs2::device', 'get_info', this.objectHandle, int64(info));
end
% function value = supports(this, info)
% this.do_init();
% value = realsense.librealsense_mex('rs2::device', 'supports', this.objectHandle, info);
% end
% function info = get_info(this, info) % TODO: name output var
% this.do_init();
% info = realsense.librealsense_mex('rs2::device', 'get_info', this.objectHandle, info);
% end
function hardware_reset(this)
this.do_init();
realsense.librealsense_mex('rs2::device', 'hardware_reset', this.objectHandle);
end
function value = is(this, type)
narginchk(2, 2);
% C++ function validates contents of type
validateattributes(type, {'char', 'string'}, {'scalartext'}, '', 'type', 2);
this.do_init();
out = realsense.librealsense_mex('rs2::device', 'is', this.objectHandle, type);
end
% function dev = as(this, type)
% this.do_init();
% out = realsense.librealsense_mex('rs2::device', 'as', this.objectHandle, type);
% switch (type)
% case ''
% % validation and initialization done in is
% if ~this.is(type)
% error('cannot downcast dev to requested type');
% end
% switch type
% case 'debug_protocol'
% case 'advanced_mode'
% case 'recorder'
% realsense.recorder(this)
% case 'playback'
% end
% end
end
end
16 changes: 16 additions & 0 deletions wrappers/matlab/disparity_frame.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% Wraps librealsense2 disparity_frame class
classdef disparity_frame < realsense.depth_frame
methods
% Constructor
function this = disparity_frame(handle)
this = [email protected]_frame(handle);
end

% Destructor (uses base class destructor)

% Functions
function baseline = get_baseline(this)
baseline = realsense.librealsense_mex('rs2::disparity_frame', 'get_baseline', this.objectHandle);
end
end
end
25 changes: 25 additions & 0 deletions wrappers/matlab/format.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
classdef format < int64
enumeration
any ( 0)
z16 ( 1)
disparity16 ( 2)
xyz32f ( 3)
yuyv ( 4)
rgb8 ( 5)
bgr8 ( 6)
rgba8 ( 7)
bgra8 ( 8)
y8 ( 9)
y16 (10)
raw10 (11)
raw16 (12)
raw8 (13)
uyvy (14)
motion_raw (15)
motion_xyz32f (16)
gpio_raw (17)
six_dof (18)
disparity32 (19)
count (20)
end
end
30 changes: 16 additions & 14 deletions wrappers/matlab/frame.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
methods
% Constructor
function this = frame(handle)
if nargin == 0
handle = 0;
end
validateattributes(handle, {'uint64'}, {'scalar'});
this.objectHandle = handle;
end
% Destructor
Expand All @@ -19,32 +17,36 @@ function delete(this)
end

% Functions
% TODO: keep
function timestamp = get_timestamp(this)
timestamp = realsense.librealsense_mex('rs2::frame', 'get_timestamp', this.objectHandle);
end
function domain = get_frame_timestamp_domain(this)
domain = realsense.frame_timestamp_domain(realsense.librealsense_mex('rs2::frame', 'get_frame_timestamp_domain', this.objectHandle));
ret = realsense.librealsense_mex('rs2::frame', 'get_frame_timestamp_domain', this.objectHandle);
domain = realsense.timestamp_domain(ret);
end
function metadata = get_frame_metadata(this, frame_metadata)
if (~isa(frame_metadata, 'frame_metadata'))
error('frame_metadata must be a frame_metadata');
end
metadata = realsense.librealsense_mex('rs2::frame', 'get_frame_metadata', this.objectHandle, uint64(frame_metadata));
narginchk(2, 2);
validateattributes(frame_metadata, {'realsense.frame_metadata_value', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.frame_metadata_value.count}, '', 'frame_metadata', 2);
metadata = realsense.librealsense_mex('rs2::frame', 'get_frame_metadata', this.objectHandle, int64(frame_metadata));
end
function value = supports_frame_metadata(this, frame_metadata)
if (~isa(frame_metadata, 'frame_metadata'))
error('frame_metadata must be a frame_metadata');
end
value = realsense.librealsense_mex('rs2::frame', 'supports_frame_metadata', this.objectHandle, uint64(frame_metadata));
narginchk(2, 2);
validateattributes(frame_metadata, {'realsense.frame_metadata_value', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.frame_metadata_value.count}, '', 'frame_metadata', 2);
value = realsense.librealsense_mex('rs2::frame', 'supports_frame_metadata', this.objectHandle, int64(frame_metadata));
end
function frame_number = get_frame_number(this)
timestamp = realsense.librealsense_mex('rs2::frame', 'get_frame_number', this.objectHandle);
frame_number = realsense.librealsense_mex('rs2::frame', 'get_frame_number', this.objectHandle);
end
function data = get_data(this)
data = realsense.librealsense_mex('rs2::frame', 'get_data', this.objectHandle);
end
function profile = get_profile(this)
profile = realsense.stream_profile(realsense.librealsense_mex('rs2::frame', 'get_profile', this.objectHandle));
ret = realsense.librealsense_mex('rs2::frame', 'get_profile', this.objectHandle);
% TODO: stream_profile takes two args
profile = realsense.stream_profile(ret);
end
% TODO: is [frame, video_frame, points, depth_frame, disparity_frame, motion_frame, pose_frame, frameset]
% TODO: as [frame, video_frame, points, depth_frame, disparity_frame, motion_frame, pose_frame, frameset]
end
end
41 changes: 31 additions & 10 deletions wrappers/matlab/frame_metadata_value.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
classdef frame_metadata_value < uint64
classdef frame_metadata_value < int64
enumeration
Frame_Counter (0)
Frame_Timestamp (1)
Sensor_Timestamp (2)
Actual_Exposure (3)
Gain_Level (4)
Auto_Exposure (5)
White_Balance (6)
Time_Of_Arrival (7)
Count (8)
frame_counter ( 0)
frame_timestamp ( 1)
sensor_timestamp ( 2)
actual_exposure ( 3)
gain_level ( 4)
auto_exposure ( 5)
white_balance ( 6)
time_of_arrival ( 7)
temperature ( 8)
backend_timestamp ( 9)
actual_fps (10)
frame_laser_power (11)
frame_laser_power_mode (12)
exposure_priority (13)
exposure_roi_left (14)
exposure_roi_right (15)
exposure_roi_top (16)
exposure_roi_bottom (17)
brightness (18)
contrast (19)
saturation (20)
sharpness (21)
auto_white_balance_temperature (22)
backlight_compensation (23)
hue (24)
gamma (25)
manual_white_balance (26)
power_line_frequency (27)
low_light_compensation (28)
count (29)
end
end
31 changes: 19 additions & 12 deletions wrappers/matlab/frameset.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Wraps librealsense2 video_frame class
% Wraps librealsense2 frameset class
classdef frameset < realsense.frame
methods
% Constructor
Expand All @@ -10,25 +10,32 @@

% Functions
function frame = first_or_default(this, s)
if (~isa(s, 'stream'))
error('s must be a stream');
end
frame = realsense.frame(realsense.librealsense_mex('rs2::frameset', 'first_or_default', this.objectHandle, uint64_t(s)));
narginchk(2, 2);
validateattributes(s, {'realsense.stream', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.stream.count}, '', 's', 2);
ret = realsense.librealsense_mex('rs2::frameset', 'first_or_default', this.objectHandle, int64_t(s));
frame = realsense.frame(ret);
end
function frame = first(this, s)
if (~isa(s, 'stream'))
error('s must be a stream');
end
frame = realsense.frame(realsense.librealsense_mex('rs2::frameset', 'first', this.objectHandle, uint64_t(s)));
narginchk(2, 2);
validateattributes(s, {'realsense.stream', 'numeric'}, {'scalar', 'nonnegative', 'real', 'integer', '<=', realsense.stream.count}, '', 's', 2);
ret = realsense.librealsense_mex('rs2::frameset', 'first', this.objectHandle, int64_t(s));
frame = realsense.frame(ret);
end
function depth_frame = get_depth_frame(this)
depth_frame = realsense.depth_frame(realsense.librealsense_mex('rs2::frameset', 'get_depth_frame', this.objectHandle));
ret = realsense.librealsense_mex('rs2::frameset', 'get_depth_frame', this.objectHandle);
depth_frame = realsense.depth_frame(ret);
end
function video_frame = get_color_frame(this)
video_frame = realsense.video_frame(realsense.librealsense_mex('rs2::frameset', 'get_color_frame', this.objectHandle));
function color_frame = get_color_frame(this)
ret = realsense.librealsense_mex('rs2::frameset', 'get_color_frame', this.objectHandle);
color_frame = realsense.video_frame(ret);
end
function infrared_frame = get_infrared_frame(this)
ret = realsense.librealsense_mex('rs2::frameset', 'get_infrared_frame', this.objectHandle);
infrared_frame = realsense.video_frame(ret);
enda
function size = get_size(this)
size = realsense.librealsense_mex('rs2::frameset', 'get_size', this.objectHandle);
end
% TODO: iterator protocol?
end
end
12 changes: 12 additions & 0 deletions wrappers/matlab/librealsense_mex.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,33 @@
<ClInclude Include="types.h" />
</ItemGroup>
<ItemGroup>
<None Include="camera_info.m" />
<None Include="context.m" />
<None Include="depth_frame.m" />
<None Include="depth_sensor.m" />
<None Include="depth_stereo_sensor.m" />
<None Include="device.m" />
<None Include="device_hub.m" />
<None Include="disparity_frame.m" />
<None Include="example1.m" />
<None Include="format.m" />
<None Include="frame.m" />
<None Include="frameset.m" />
<None Include="frame_metadata_value.m" />
<None Include="motion_frame.m" />
<None Include="motion_stream_profile.m" />
<None Include="option.m" />
<None Include="options.m" />
<None Include="pipeline.m" />
<None Include="points.m" />
<None Include="pose_frame.m" />
<None Include="roi_sensor.m" />
<None Include="sensor.m" />
<None Include="stream.m" />
<None Include="stream_profile.m" />
<None Include="timestamp_domain.m" />
<None Include="video_frame.m" />
<None Include="video_stream_profile.m" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\build\realsense2.vcxproj">
Expand Down
Loading

0 comments on commit 7ecf0a5

Please sign in to comment.