Skip to content
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

RGB sensor auto-exposure region of interest #2511

Merged
merged 2 commits into from
Oct 22, 2018
Merged
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
8 changes: 8 additions & 0 deletions src/ds5/ds5-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ namespace librealsense
color_ep->register_metadata(RS2_FRAME_METADATA_POWER_LINE_FREQUENCY, make_attribute_parser(&md_rgb_control::power_line_frequency, md_rgb_control_attributes::power_line_frequency_attribute, md_prop_offset));
color_ep->register_metadata(RS2_FRAME_METADATA_LOW_LIGHT_COMPENSATION, make_attribute_parser(&md_rgb_control::low_light_comp, md_rgb_control_attributes::low_light_comp_attribute, md_prop_offset));

// Starting with firmware 5.10.9, auto-exposure ROI is available for color sensor
if (_fw_version >= firmware_version("5.10.9.0"))
{
roi_sensor_interface* roi_sensor;
if (roi_sensor = dynamic_cast<roi_sensor_interface*>(color_ep.get()))
roi_sensor->set_roi_method(std::make_shared<ds5_auto_exposure_roi_method>(*_hw_monitor, ds::fw_cmd::SETRGBAEROI));
}

return color_ep;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ds5/ds5-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ namespace librealsense
std::shared_ptr<lazy<rs2_extrinsics>> _color_extrinsic;
};

class ds5_color_sensor : public uvc_sensor, public video_sensor_interface
class ds5_color_sensor : public uvc_sensor,
public video_sensor_interface,
public roi_sensor_base
{
public:
explicit ds5_color_sensor(ds5_color* owner,
Expand Down
60 changes: 28 additions & 32 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,41 @@

namespace librealsense
{
class ds5_auto_exposure_roi_method : public region_of_interest_method
ds5_auto_exposure_roi_method::ds5_auto_exposure_roi_method(
const hw_monitor& hwm,
ds::fw_cmd cmd)
: _hw_monitor(hwm), _cmd(cmd) {}

void ds5_auto_exposure_roi_method::set(const region_of_interest& roi)
{
public:
explicit ds5_auto_exposure_roi_method(const hw_monitor& hwm) : _hw_monitor(hwm) {}
command cmd(_cmd);
cmd.param1 = roi.min_y;
cmd.param2 = roi.max_y;
cmd.param3 = roi.min_x;
cmd.param4 = roi.max_x;
_hw_monitor.send(cmd);
}

void set(const region_of_interest& roi) override
{
command cmd(ds::SETAEROI);
cmd.param1 = roi.min_y;
cmd.param2 = roi.max_y;
cmd.param3 = roi.min_x;
cmd.param4 = roi.max_x;
_hw_monitor.send(cmd);
}
region_of_interest ds5_auto_exposure_roi_method::get() const
{
region_of_interest roi;
command cmd(_cmd + 1);
auto res = _hw_monitor.send(cmd);

region_of_interest get() const override
if (res.size() < 4 * sizeof(uint16_t))
{
region_of_interest roi;
command cmd(ds::GETAEROI);
auto res = _hw_monitor.send(cmd);

if (res.size() < 4 * sizeof(uint16_t))
{
throw std::runtime_error("Invalid result size!");
}

auto words = reinterpret_cast<uint16_t*>(res.data());
throw std::runtime_error("Invalid result size!");
}

roi.min_y = words[0];
roi.max_y = words[1];
roi.min_x = words[2];
roi.max_x = words[3];
auto words = reinterpret_cast<uint16_t*>(res.data());

return roi;
}
roi.min_y = words[0];
roi.max_y = words[1];
roi.min_x = words[2];
roi.max_x = words[3];

private:
const hw_monitor& _hw_monitor;
};
return roi;
}

std::vector<uint8_t> ds5_device::send_receive_raw_data(const std::vector<uint8_t>& input)
{
Expand Down
13 changes: 13 additions & 0 deletions src/ds5/ds5-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@

namespace librealsense
{
class ds5_auto_exposure_roi_method : public region_of_interest_method
{
public:
explicit ds5_auto_exposure_roi_method(const hw_monitor& hwm,
ds::fw_cmd cmd = ds::fw_cmd::SETAEROI);

void set(const region_of_interest& roi) override;
region_of_interest get() const override;
private:
const ds::fw_cmd _cmd;
const hw_monitor& _hw_monitor;
};

class ds5_device : public virtual device, public debug_interface
{
public:
Expand Down
2 changes: 2 additions & 0 deletions src/ds5/ds5-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ namespace librealsense
GET_EXTRINSICS = 0x53, // get extrinsics
SET_CAM_SYNC = 0x69, // set Inter-cam HW sync mode [0-default, 1-master, 2-slave]
GET_CAM_SYNC = 0x6A, // fet Inter-cam HW sync mode
SETRGBAEROI = 0x75, // set RGB auto-exposure region of interest
GETRGBAEROI = 0x76, // get RGB auto-exposure region of interest
};

const int etDepthTableControl = 9; // Identifier of the depth table control
Expand Down
39 changes: 39 additions & 0 deletions wrappers/csharp/Intel.RealSense/Sensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,32 @@ public void Dispose()
#endregion
}

public struct ROI
{
public int minX, minY, maxX, maxY;
}

public class AutoExposureROI
{
internal IntPtr m_instance;

public ROI GetRegionOfInterest()
{
var result = new ROI();
object error;
NativeMethods.rs2_get_region_of_interest(m_instance, out result.minX,
out result.minY, out result.maxX, out result.maxY, out error);
return result;
}

public void SetRegionOfInterest(ROI value)
{
object error;
NativeMethods.rs2_set_region_of_interest(m_instance,
value.minX, value.minY, value.maxX, value.maxY, out error);
}
}

public class Sensor : IDisposable
{
protected readonly IntPtr m_instance;
Expand All @@ -108,6 +134,19 @@ internal Sensor(IntPtr sensor)
m_instance = sensor;
}

public AutoExposureROI AutoExposureSettings
{
get
{
object error;
if (NativeMethods.rs2_is_sensor_extendable_to(m_instance, Extension.Roi, out error) > 0)
{
return new AutoExposureROI { m_instance = m_instance };
}
return null;
}
}

public class CameraInfos
{
readonly IntPtr m_sensor;
Expand Down