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

made gain/exposuretime optional with enable_control #240

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
63 changes: 44 additions & 19 deletions src/bb/image-io/bb.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,11 @@ class U3VCameraN : public ion::BuildingBlock<U3VCameraN<T, D>> {
public:
BuildingBlockParam<int32_t> num_devices{"num_devices", 2};
BuildingBlockParam<bool> frame_sync{"frame_sync", false};

BuildingBlockParam<std::string> gain_key_ptr{"gain_key", "Gain"};
BuildingBlockParam<std::string> exposure_key_ptr{"exposure_key", "Exposure"};

BuildingBlockParam<bool> realtime_diaplay_mode{"realtime_diaplay_mode", false};

BuildingBlockParam<bool> enable_control{"enable_control", false};
BuildingBlockParam<std::string> gain_key_ptr{"gain_key", "Gain"};
BuildingBlockParam<std::string> exposure_key_ptr{"exposure_key", "Exposure"};

Output<Halide::Func[]> output{ "output", Halide::type_of<T>(), D};
Output<Halide::Func[]> device_info{ "device_info", Halide::type_of<uint8_t>(), 1};
Expand Down Expand Up @@ -874,7 +872,9 @@ class U3VCameraN : public ion::BuildingBlock<U3VCameraN<T, D>> {

std::vector<ExternFuncArgument> params{
id_buf,
static_cast<bool>(frame_sync), static_cast<bool>(realtime_diaplay_mode), static_cast<bool>(enable_control),
static_cast<bool>(frame_sync),
static_cast<bool>(realtime_diaplay_mode),
static_cast<bool>(enable_control),
gain_key_buf, exposure_key_buf
};

Expand Down Expand Up @@ -951,28 +951,38 @@ using U3VCameraN_U16x2 = U3VCameraN<uint16_t, 2>;
class U3VGenDC : public ion::BuildingBlock<U3VGenDC> {
public:
BuildingBlockParam<int32_t> num_devices{"num_devices", 2};

BuildingBlockParam<bool> frame_sync{"frame_sync", false};
BuildingBlockParam<std::string> gain_key_ptr{"gain_key", "Gain"};
BuildingBlockParam<std::string> exposure_key_ptr{"exposure_key", "Exposure"};
BuildingBlockParam<bool> realtime_diaplay_mode{"realtime_diaplay_mode", false};

Input<Halide::Func> gain{ "gain", Halide::type_of<double>(), 1};
Input<Halide::Func> exposure{ "exposure", Halide::type_of<double>(), 1};
BuildingBlockParam<bool> enable_control{"enable_control", false};
BuildingBlockParam<std::string> gain_key_ptr{"gain_key", "Gain"};
BuildingBlockParam<std::string> exposure_key_ptr{"exposure_key", "Exposure"};

Output<Halide::Func[]> gendc{ "gendc", Halide::type_of<uint8_t>(), 1};
Output<Halide::Func[]> device_info{ "device_info", Halide::type_of<uint8_t>(), 1};

std::vector<Input<double> *> gain;
std::vector<Input<double> *> exposure;

void configure() {
if (enable_control) {
for (auto i=0; i<num_devices; ++i) {
gain.push_back(Halide::Internal::GeneratorBase::add_input<double>("gain_" + std::to_string(i)));
exposure.push_back(Halide::Internal::GeneratorBase::add_input<double>("exposure_" + std::to_string(i)));
}
}
}

void generate() {
using namespace Halide;

Func gain_func;
gain_func(_) = gain(_);
gain_func.compute_root();
// Func gain_func;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed on a5cb2cf

// gain_func(_) = gain(_);
// gain_func.compute_root();

Func exposure_func;
exposure_func(_) = exposure(_);
exposure_func.compute_root();
// Func exposure_func;
// exposure_func(_) = exposure(_);
// exposure_func.compute_root();

Func u3v_gendc("u3v_gendc");
{
Expand All @@ -989,11 +999,26 @@ class U3VGenDC : public ion::BuildingBlock<U3VGenDC> {
std::memcpy(exposure_key_buf.data(), exposure_key.c_str(), exposure_key.size());

std::vector<ExternFuncArgument> params{
static_cast<bool>(frame_sync), static_cast<bool>(realtime_diaplay_mode),
gain_func, exposure_func,
id_buf, gain_key_buf, exposure_key_buf
id_buf,
static_cast<bool>(frame_sync),
static_cast<bool>(realtime_diaplay_mode),
static_cast<bool>(enable_control),
gain_key_buf, exposure_key_buf
};

for (int i = 0; i<num_devices; i++) {
if (i < gain.size()) {
params.push_back(*gain[i]);
} else {
params.push_back(Internal::make_const(type_of<double>(), 0.0));
}
if (i < exposure.size()) {
params.push_back(*exposure[i]);
} else {
params.push_back(Internal::make_const(type_of<double>(), 0.0));
}
}

gendc.resize(num_devices);
std::vector<Halide::Type> output_type;
for (int i = 0; i < gendc.size(); i++) {
Expand Down
62 changes: 30 additions & 32 deletions src/bb/image-io/rt_u3v.h
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ extern "C"
int ION_EXPORT ion_bb_image_io_u3v_camera2_frame_count(
halide_buffer_t *,
halide_buffer_t *,
int32_t num_sensor, bool frame_sync, bool realtime_display_mode,
int32_t num_sensor, bool frame_sync, bool realtime_display_mode,
halide_buffer_t * id_buf, halide_buffer_t* out)
{ const std::string id(reinterpret_cast<const char *>(id_buf->host));
return ion::bb::image_io::u3v_camera_frame_count(id, num_sensor, frame_sync, realtime_display_mode, out);
Expand All @@ -1256,9 +1256,10 @@ ION_REGISTER_EXTERN(ion_bb_image_io_u3v_camera2_frame_count);

extern "C"
int ION_EXPORT ion_bb_image_io_u3v_gendc_camera1(
bool frame_sync, bool realtime_display_mode,
halide_buffer_t* gain, halide_buffer_t* exposure,
halide_buffer_t * id_buf, halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf,
halide_buffer_t * id_buf,
bool frame_sync, bool realtime_display_mode, bool enable_control,
halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf,
double gain0, double exposure0,
halide_buffer_t * out_gendc
)
{
Expand All @@ -1269,22 +1270,17 @@ int ION_EXPORT ion_bb_image_io_u3v_gendc_camera1(
const std::string gain_key(reinterpret_cast<const char*>(gain_key_buf->host));
const std::string exposure_key(reinterpret_cast<const char*>(exposure_key_buf->host));
auto &u3v(ion::bb::image_io::U3V::get_instance(id, num_output, false, realtime_display_mode));
if (out_gendc->is_bounds_query() || gain->is_bounds_query() || exposure->is_bounds_query()) {
gain->dim[0].min = 0;
gain->dim[0].extent = num_output;
exposure->dim[0].min = 0;
exposure->dim[0].extent = num_output;
if (out_gendc->is_bounds_query()) {
return 0;
}else{
// set gain & exposure
for (int i = 0; i < num_output; ++i){
u3v.SetGain(i, gain_key, (reinterpret_cast<double*>(gain->host))[i]);
u3v.SetExposure(i, exposure_key, (reinterpret_cast<double*>(exposure->host))[i]);
}
std::vector<void *> obufs{out_gendc->host};
u3v.get_gendc(obufs);

}
// set gain & exposure
if (enable_control){
ion::log::debug("Setting gain0:{} exposure0:{}", gain0, exposure0);
u3v.SetGain(0, gain_key, gain0);
u3v.SetExposure(0, exposure_key, exposure0);
}
std::vector<void *> obufs{out_gendc->host};
u3v.get_gendc(obufs);

return 0;
} catch (const std::exception &e) {
Expand All @@ -1299,33 +1295,35 @@ ION_REGISTER_EXTERN(ion_bb_image_io_u3v_gendc_camera1);

extern "C"
int ION_EXPORT ion_bb_image_io_u3v_gendc_camera2(
bool frame_sync, bool realtime_display_mode,
halide_buffer_t* gain, halide_buffer_t* exposure,
halide_buffer_t * id_buf, halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf,
halide_buffer_t * gendc0, halide_buffer_t * gendc1
halide_buffer_t * id_buf,
bool frame_sync, bool realtime_display_mode, bool enable_control,
halide_buffer_t * gain_key_buf, halide_buffer_t * exposure_key_buf,
double gain0, double exposure0,
double gain1, double exposure1,
halide_buffer_t * out_gendc0, halide_buffer_t * out_gendc1
)
{
using namespace Halide;
try {
int num_output = 2;
const std::string id(reinterpret_cast<const char *>(id_buf->host));
const std::string gain_key(reinterpret_cast<const char*>(gain_key_buf->host));
const std::string exposure_key(reinterpret_cast<const char*>(exposure_key_buf->host));
auto &u3v(ion::bb::image_io::U3V::get_instance(id, 2, frame_sync, realtime_display_mode));
if (gendc0->is_bounds_query() || gendc1->is_bounds_query() || gain->is_bounds_query() || exposure->is_bounds_query()) {
gain->dim[0].min = 0;
gain->dim[0].extent = num_output;
exposure->dim[0].min = 0;
exposure->dim[0].extent = num_output;
if (out_gendc0->is_bounds_query() || out_gendc1->is_bounds_query() ) {
return 0;
}else{
// set gain & exposure
for (int i = 0; i < num_output; ++i){
u3v.SetGain(i, gain_key, (reinterpret_cast<double*>(gain->host))[i]);
u3v.SetExposure(i, exposure_key, (reinterpret_cast<double*>(exposure->host))[i]);
if (enable_control) {
ion::log::debug("Setting gain0:{} exposure0:{}", gain0, exposure0);
u3v.SetGain(0, gain_key, gain0);
u3v.SetExposure(0, exposure_key, exposure0);

ion::log::debug("Setting gain1:{} exposure1:{}", gain1, exposure1);
u3v.SetGain(1, gain_key, gain1);
u3v.SetExposure(1, exposure_key, exposure1);
}

std::vector<void *> obufs{gendc0->host, gendc1->host};
std::vector<void *> obufs{out_gendc0->host, out_gendc1->host};
u3v.get_gendc(obufs);

}
Expand Down
Loading