Skip to content

Commit

Permalink
Add setting for ROI scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Timocop committed Mar 23, 2024
1 parent fdb10c4 commit a85bb86
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/psmoveconfigtool/AppStage_AdvancedSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ TrackerConfig::config2ptree()
pt.put("max_tracker_position_deviation", max_tracker_position_deviation);

pt.put("disable_roi", disable_roi);
pt.put("autoscale_roi", autoscale_roi);
pt.put("optimized_roi", optimized_roi);
pt.put("roi_size", roi_size);
pt.put("roi_search_size", roi_search_size);
Expand Down Expand Up @@ -287,6 +288,7 @@ TrackerConfig::ptree2config(const boost::property_tree::ptree &pt)
max_tracker_position_deviation = pt.get<float>("max_tracker_position_deviation", max_tracker_position_deviation);

disable_roi = pt.get<bool>("disable_roi", disable_roi);
autoscale_roi = pt.get<bool>("autoscale_roi", autoscale_roi);
optimized_roi = pt.get<bool>("optimized_roi", optimized_roi);
roi_size = pt.get<int>("roi_size", roi_size);
roi_search_size = pt.get<int>("roi_search_size", roi_search_size);
Expand Down Expand Up @@ -901,6 +903,18 @@ void AppStage_AdvancedSettings::renderUI()

ImGui::Indent();
{
{
ImGui::Text("Scale ROI (region of interest) by tracker resolution:");
ImGui::SameLine(ImGui::GetWindowWidth() - 150.f);
ImGui::Checkbox("##ROIAutoscale", &cfg_tracker.autoscale_roi);

if (ImGui::IsItemHovered())
ImGui::SetTooltip(
"Scales the ROI (region of interest) uniformly between trackers running with different resolutions.\n"
"(The default value is TRUE)"
);
}

{
ImGui::Text("ROI (region of interest) size:");
ImGui::SameLine(ImGui::GetWindowWidth() - 150.f);
Expand Down
2 changes: 2 additions & 0 deletions src/psmoveconfigtool/AppStage_AdvancedSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TrackerConfig : public PSMoveConfig
min_points_in_contour = 4;
max_tracker_position_deviation = 15.0f;
disable_roi = false;
autoscale_roi = true;
optimized_roi = true;
roi_size = 32;
roi_search_size = 164;
Expand Down Expand Up @@ -91,6 +92,7 @@ class TrackerConfig : public PSMoveConfig
int min_points_in_contour;
float max_tracker_position_deviation;
bool disable_roi;
bool autoscale_roi;
bool optimized_roi;
int roi_size;
int roi_search_size;
Expand Down
3 changes: 3 additions & 0 deletions src/psmoveservice/Device/Manager/TrackerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TrackerManagerConfig::TrackerManagerConfig(const std::string &fnamebase)
min_points_in_contour = 4;
max_tracker_position_deviation = 15.0f;
disable_roi = false;
autoscale_roi = true;
optimized_roi = true;
roi_size = 32;
roi_search_size = 164;
Expand Down Expand Up @@ -101,6 +102,7 @@ TrackerManagerConfig::config2ptree()
pt.put("max_tracker_position_deviation", max_tracker_position_deviation);

pt.put("disable_roi", disable_roi);
pt.put("autoscale_roi", autoscale_roi);
pt.put("optimized_roi", optimized_roi);
pt.put("roi_size", roi_size);
pt.put("roi_search_size", roi_search_size);
Expand Down Expand Up @@ -162,6 +164,7 @@ TrackerManagerConfig::ptree2config(const boost::property_tree::ptree &pt)
max_tracker_position_deviation = pt.get<float>("max_tracker_position_deviation", max_tracker_position_deviation);

disable_roi = pt.get<bool>("disable_roi", disable_roi);
autoscale_roi = pt.get<bool>("autoscale_roi", autoscale_roi);
optimized_roi = pt.get<bool>("optimized_roi", optimized_roi);
roi_size = pt.get<int>("roi_size", roi_size);
roi_search_size = pt.get<int>("roi_search_size", roi_search_size);
Expand Down
1 change: 1 addition & 0 deletions src/psmoveservice/Device/Manager/TrackerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class TrackerManagerConfig : public PSMoveConfig
int min_points_in_contour;
float max_tracker_position_deviation;
bool disable_roi;
bool autoscale_roi;
bool optimized_roi;
int roi_size;
int roi_search_size;
Expand Down
18 changes: 15 additions & 3 deletions src/psmoveservice/Device/View/ServerTrackerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,18 @@ static cv::Rect2i computeTrackerROIForPoseProjection(
static_cast<int>(screenHeight)
);

bool auto_scale_roi = cfg.autoscale_roi;
float roi_res_scale = 1.f;

// Auto-scale ROI by resolution.
// Default is 480p for the settings.
if (auto_scale_roi)
{
roi_res_scale = (screenWidth / 640.f);
if (roi_res_scale < 0.1f)
roi_res_scale = 0.1;
}

int trackerId = tracker->getDeviceID();

while (true)
Expand All @@ -2702,7 +2714,7 @@ static cv::Rect2i computeTrackerROIForPoseProjection(
{
bool roi_found = false;
int count = 0;
int cfg_roi_search_size = static_cast<int>(fmax(cfg.roi_search_size, 4));
int cfg_roi_search_size = static_cast<int>(fmax(cfg.roi_search_size * roi_res_scale, 4));

for (int x = 0; !roi_found && (x * cfg_roi_search_size) < static_cast<int>(screenWidth); x++)
{
Expand Down Expand Up @@ -2933,7 +2945,7 @@ static cv::Rect2i computeTrackerROIForPoseProjection(

const cv::Point2i roi_center(static_cast<int>(projection_pixel_center.x), static_cast<int>(projection_pixel_center.y));

const int cfg_roi_size = static_cast<int>(fmax(cfg.roi_size, 4));
const int cfg_roi_size = static_cast<int>(fmax(cfg.roi_size * roi_res_scale, 4));

const int safe_proj_width = std::max(proj_width, cfg_roi_size);
const int safe_proj_height = std::max(proj_height, cfg_roi_size);
Expand All @@ -2942,7 +2954,7 @@ static cv::Rect2i computeTrackerROIForPoseProjection(
// Increase ROI size if the projection is moving
// This help fast controller movements on lower tracker Hz
float scale_axis = 0.f;
float scale_max = 4.f;
float scale_max = (2.f * roi_res_scale);

if (roi_index > -1)
{
Expand Down

0 comments on commit a85bb86

Please sign in to comment.