diff --git a/src/psmoveconfigtool/AppStage_AdvancedSettings.cpp b/src/psmoveconfigtool/AppStage_AdvancedSettings.cpp index 2d166443..9c8dade1 100644 --- a/src/psmoveconfigtool/AppStage_AdvancedSettings.cpp +++ b/src/psmoveconfigtool/AppStage_AdvancedSettings.cpp @@ -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); @@ -287,6 +288,7 @@ TrackerConfig::ptree2config(const boost::property_tree::ptree &pt) max_tracker_position_deviation = pt.get("max_tracker_position_deviation", max_tracker_position_deviation); disable_roi = pt.get("disable_roi", disable_roi); + autoscale_roi = pt.get("autoscale_roi", autoscale_roi); optimized_roi = pt.get("optimized_roi", optimized_roi); roi_size = pt.get("roi_size", roi_size); roi_search_size = pt.get("roi_search_size", roi_search_size); @@ -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); diff --git a/src/psmoveconfigtool/AppStage_AdvancedSettings.h b/src/psmoveconfigtool/AppStage_AdvancedSettings.h index b002b20b..e1e5cda4 100644 --- a/src/psmoveconfigtool/AppStage_AdvancedSettings.h +++ b/src/psmoveconfigtool/AppStage_AdvancedSettings.h @@ -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; @@ -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; diff --git a/src/psmoveservice/Device/Manager/TrackerManager.cpp b/src/psmoveservice/Device/Manager/TrackerManager.cpp index 7006e2d3..1c36199f 100644 --- a/src/psmoveservice/Device/Manager/TrackerManager.cpp +++ b/src/psmoveservice/Device/Manager/TrackerManager.cpp @@ -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; @@ -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); @@ -162,6 +164,7 @@ TrackerManagerConfig::ptree2config(const boost::property_tree::ptree &pt) max_tracker_position_deviation = pt.get("max_tracker_position_deviation", max_tracker_position_deviation); disable_roi = pt.get("disable_roi", disable_roi); + autoscale_roi = pt.get("autoscale_roi", autoscale_roi); optimized_roi = pt.get("optimized_roi", optimized_roi); roi_size = pt.get("roi_size", roi_size); roi_search_size = pt.get("roi_search_size", roi_search_size); diff --git a/src/psmoveservice/Device/Manager/TrackerManager.h b/src/psmoveservice/Device/Manager/TrackerManager.h index 80717945..aaf02800 100644 --- a/src/psmoveservice/Device/Manager/TrackerManager.h +++ b/src/psmoveservice/Device/Manager/TrackerManager.h @@ -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; diff --git a/src/psmoveservice/Device/View/ServerTrackerView.cpp b/src/psmoveservice/Device/View/ServerTrackerView.cpp index a4d5dbe4..f4728e9a 100644 --- a/src/psmoveservice/Device/View/ServerTrackerView.cpp +++ b/src/psmoveservice/Device/View/ServerTrackerView.cpp @@ -2685,6 +2685,18 @@ static cv::Rect2i computeTrackerROIForPoseProjection( static_cast(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) @@ -2702,7 +2714,7 @@ static cv::Rect2i computeTrackerROIForPoseProjection( { bool roi_found = false; int count = 0; - int cfg_roi_search_size = static_cast(fmax(cfg.roi_search_size, 4)); + int cfg_roi_search_size = static_cast(fmax(cfg.roi_search_size * roi_res_scale, 4)); for (int x = 0; !roi_found && (x * cfg_roi_search_size) < static_cast(screenWidth); x++) { @@ -2933,7 +2945,7 @@ static cv::Rect2i computeTrackerROIForPoseProjection( const cv::Point2i roi_center(static_cast(projection_pixel_center.x), static_cast(projection_pixel_center.y)); - const int cfg_roi_size = static_cast(fmax(cfg.roi_size, 4)); + const int cfg_roi_size = static_cast(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); @@ -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) {