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

Pass more data in board config: board name, revision, RGB FOV #9

Merged
merged 7 commits into from
Apr 25, 2020
24 changes: 22 additions & 2 deletions host/core/pipeline/host_pipeline_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ bool HostPipelineConfig::initWithJSON(const json &json_obj)
board_config.clear_eeprom = board_conf_obj.at("clear_eeprom").get<bool>();
}

if (board_conf_obj.contains("override_eeprom_calib"))
if (board_conf_obj.contains("override_eeprom"))
{
board_config.override_eeprom_calib = board_conf_obj.at("override_eeprom_calib").get<bool>();
board_config.override_eeprom = board_conf_obj.at("override_eeprom").get<bool>();
}

if (board_conf_obj.contains("stereo_center_crop"))
{
board_config.stereo_center_crop = board_conf_obj.at("stereo_center_crop").get<bool>();
}

// "blob_file_config"
Expand All @@ -144,6 +149,11 @@ bool HostPipelineConfig::initWithJSON(const json &json_obj)
board_config.left_fov_deg = board_conf_obj.at("left_fov_deg").get<float>();
}

if (board_conf_obj.contains("rgb_fov_deg"))
{
board_config.rgb_fov_deg = board_conf_obj.at("rgb_fov_deg").get<float>();
}

// "left_to_right_distance_cm"
if (board_conf_obj.contains("left_to_right_distance_cm"))
{
Expand All @@ -156,6 +166,16 @@ bool HostPipelineConfig::initWithJSON(const json &json_obj)
board_config.left_to_rgb_distance_m =
board_conf_obj.at("left_to_rgb_distance_cm").get<float>() / 100.f; // cm -> m
}

if (board_conf_obj.contains("name"))
{
board_config.name = board_conf_obj.at("name").get<std::string>();
}

if (board_conf_obj.contains("revision"))
{
board_config.revision = board_conf_obj.at("revision").get<std::string>();
}
}

result = true;
Expand Down
6 changes: 5 additions & 1 deletion host/core/pipeline/host_pipeline_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ struct HostPipelineConfig
{
bool clear_eeprom = false;
bool store_to_eeprom = false;
bool override_eeprom_calib = false;
bool override_eeprom = false;
bool swap_left_and_right_cameras = false;
float left_fov_deg = 69.f;
float rgb_fov_deg = 69.f;
float left_to_right_distance_m = 0.035f; // meters, not centimeters
float left_to_rgb_distance_m = 0;
bool stereo_center_crop = false;
std::string name;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should set these by default to : Unknown

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe some checks in the code could be a bit cleaner by using name.empty()?
But when displayed for the user, yes we could print something like this.

std::string revision;
} board_config;


Expand Down
56 changes: 53 additions & 3 deletions host/py_module/py_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,44 @@ bool init_device(
}
}

uint32_t version = g_config_d2h.at("eeprom").at("version").get<int>();
printf("EEPROM data:");
if (version == -1) {
printf(" invalid / unprogrammed\n");
} else {
printf(" valid (v%d)\n", version);
std::string board_name;
std::string board_rev;
float rgb_fov_deg = 0;
bool stereo_center_crop = false;
if (version >= 2) {
board_name = g_config_d2h.at("eeprom").at("board_name").get<std::string>();
board_rev = g_config_d2h.at("eeprom").at("board_rev").get<std::string>();
rgb_fov_deg= g_config_d2h.at("eeprom").at("rgb_fov_deg").get<float>();
}
if (version >= 3) {
stereo_center_crop = g_config_d2h.at("eeprom").at("stereo_center_crop").get<bool>();
}
float left_fov_deg = g_config_d2h.at("eeprom").at("left_fov_deg").get<float>();
float left_to_right_distance_m = g_config_d2h.at("eeprom").at("left_to_right_distance_m").get<float>();
float left_to_rgb_distance_m = g_config_d2h.at("eeprom").at("left_to_rgb_distance_m").get<float>();
bool swap_left_and_right_cameras = g_config_d2h.at("eeprom").at("swap_left_and_right_cameras").get<bool>();
std::vector<float> calib = g_config_d2h.at("eeprom").at("calib").get<std::vector<float>>();
printf(" Board name : %s\n", board_name.empty() ? "<NOT-SET>" : board_name.c_str());
printf(" Board rev : %s\n", board_rev.empty() ? "<NOT-SET>" : board_rev.c_str());
printf(" HFOV L/R : %g deg\n", left_fov_deg);
printf(" HFOV RGB : %g deg\n", rgb_fov_deg);
printf(" L-R distance : %g cm\n", 100 * left_to_right_distance_m);
printf(" L-RGB distance : %g cm\n", 100 * left_to_rgb_distance_m);
printf(" L/R swapped : %s\n", swap_left_and_right_cameras ? "yes" : "no");
printf(" L/R crop region: %s\n", stereo_center_crop ? "center" : "top");
printf(" Calibration homography:\n");
for (int i = 0; i < 9; i++) {
printf(" %11.6f,", calib.at(i));
if (i % 3 == 2) printf("\n");
}
}

// device support listener
g_device_support_listener = std::unique_ptr<DeviceSupportListener>(new DeviceSupportListener);

Expand Down Expand Up @@ -324,6 +362,7 @@ std::shared_ptr<CNNHostPipeline> create_pipeline(
-8.7650679e-03, 9.9214733e-01, -8.7952757e+00,
-8.4495878e-06, -3.6034894e-06, 1.0000000e+00
};
bool stereo_center_crop = false;

if (config.depth.calibration_file.empty())
{
Expand All @@ -338,19 +377,30 @@ std::shared_ptr<CNNHostPipeline> create_pipeline(
break;
}

const int homography_size = sizeof(float) * 9;
int sz = calibration_reader.getSize();
assert(sz == sizeof(float) * 9);
std::cout << "Read: " << calibration_reader.readData(reinterpret_cast<unsigned char*>(homography_buff.data()), sz) << std::endl;
assert(sz >= homography_size);
calibration_reader.readData(reinterpret_cast<unsigned char*>(homography_buff.data()), homography_size);
int flags_size = sz - homography_size;
if (flags_size > 0)
{
assert(flags_size == 1);
calibration_reader.readData(reinterpret_cast<unsigned char*>(&stereo_center_crop), 1);
}
}

json json_config_obj;
json_config_obj["board"]["clear-eeprom"] = config.board_config.clear_eeprom;
json_config_obj["board"]["store-to-eeprom"] = config.board_config.store_to_eeprom;
json_config_obj["board"]["override-eeprom"] = config.board_config.override_eeprom_calib;
json_config_obj["board"]["override-eeprom"] = config.board_config.override_eeprom;
json_config_obj["board"]["swap-left-and-right-cameras"] = config.board_config.swap_left_and_right_cameras;
json_config_obj["board"]["left_fov_deg"] = config.board_config.left_fov_deg;
json_config_obj["board"]["rgb_fov_deg"] = config.board_config.rgb_fov_deg;
json_config_obj["board"]["left_to_right_distance_m"] = config.board_config.left_to_right_distance_m;
json_config_obj["board"]["left_to_rgb_distance_m"] = config.board_config.left_to_rgb_distance_m;
json_config_obj["board"]["stereo_center_crop"] = config.board_config.stereo_center_crop || stereo_center_crop;
json_config_obj["board"]["name"] = config.board_config.name;
json_config_obj["board"]["revision"] = config.board_config.revision;
json_config_obj["_board"] =
{
{"_homography_right_to_left", homography_buff}
Expand Down