No public description

PiperOrigin-RevId: 563333271
This commit is contained in:
vrabaud 2023-09-06 23:57:58 -07:00 committed by Copybara-Service
parent 5f4a6e313e
commit 55536c4382
4 changed files with 36 additions and 81 deletions

View File

@ -150,7 +150,6 @@ void MotionAnalysis::InitPolicyOptions() {
// Better features. // Better features.
tracking_options->set_adaptive_features_levels(3); tracking_options->set_adaptive_features_levels(3);
tracking_options->set_use_cv_tracking_algorithm(true);
// Speed. // Speed.
flow_options->set_downsample_mode( flow_options->set_downsample_mode(
@ -196,7 +195,6 @@ void MotionAnalysis::InitPolicyOptions() {
tracking_options->set_fractional_tracking_distance(0.1); tracking_options->set_fractional_tracking_distance(0.1);
tracking_options->set_reuse_features_max_frame_distance(15); tracking_options->set_reuse_features_max_frame_distance(15);
tracking_options->set_max_features(500); tracking_options->set_max_features(500);
tracking_options->set_use_cv_tracking_algorithm(true);
flow_options->set_downsample_mode( flow_options->set_downsample_mode(
RegionFlowComputationOptions::DOWNSAMPLE_TO_MIN_SIZE); RegionFlowComputationOptions::DOWNSAMPLE_TO_MIN_SIZE);
@ -248,7 +246,6 @@ void MotionAnalysis::InitPolicyOptions() {
tracking_options->set_reuse_features_min_survived_frac(0.6); tracking_options->set_reuse_features_min_survived_frac(0.6);
tracking_options->set_max_features(240); tracking_options->set_max_features(240);
tracking_options->set_adaptive_tracking_distance(true); tracking_options->set_adaptive_tracking_distance(true);
tracking_options->set_use_cv_tracking_algorithm(true);
// Assumes downsampled input. // Assumes downsampled input.
flow_options->set_pre_blur_sigma(0); flow_options->set_pre_blur_sigma(0);
@ -305,7 +302,6 @@ void MotionAnalysis::InitPolicyOptions() {
tracking_options->set_adaptive_features_levels(3); tracking_options->set_adaptive_features_levels(3);
// Speed. // Speed.
tracking_options->set_use_cv_tracking_algorithm(true);
flow_options->set_downsample_mode( flow_options->set_downsample_mode(
RegionFlowComputationOptions::DOWNSAMPLE_BY_SCHEDULE); RegionFlowComputationOptions::DOWNSAMPLE_BY_SCHEDULE);

View File

@ -120,14 +120,6 @@ void InvertFeatureList(const TrackedFeatureList& list,
} }
} }
// Allocates pyramid images of sufficient size (suggested OpenCV settings,
// independent of number of pyramid levels).
void AllocatePyramid(int frame_width, int frame_height, cv::Mat* pyramid) {
const int pyramid_width = frame_width + 8;
const int pyramid_height = frame_height / 2 + 1;
pyramid->create(pyramid_height, pyramid_width, CV_8UC1);
}
namespace { namespace {
// lab_window is used as scratch space only, to avoid allocations. // lab_window is used as scratch space only, to avoid allocations.
@ -370,11 +362,7 @@ struct RegionFlowComputation::FrameTrackingData {
ORBFeatureDescriptors orb; ORBFeatureDescriptors orb;
bool use_cv_tracking = false; FrameTrackingData(int width, int height, int extraction_levels) {
FrameTrackingData(int width, int height, int extraction_levels,
bool _use_cv_tracking)
: use_cv_tracking(_use_cv_tracking) {
// Extraction pyramid. // Extraction pyramid.
extraction_pyramid.clear(); extraction_pyramid.clear();
for (int i = 0, iwidth = width, iheight = height; i < extraction_levels; for (int i = 0, iwidth = width, iheight = height; i < extraction_levels;
@ -386,21 +374,10 @@ struct RegionFlowComputation::FrameTrackingData {
ABSL_CHECK_GE(extraction_levels, 1); ABSL_CHECK_GE(extraction_levels, 1);
// Frame is the same as first extraction level. // Frame is the same as first extraction level.
frame = extraction_pyramid[0]; frame = extraction_pyramid[0];
if (!use_cv_tracking) {
// Tracking pyramid for old c-interface.
pyramid.resize(1);
AllocatePyramid(width, height, &pyramid[0]);
}
} }
void BuildPyramid(int levels, int window_size, bool with_derivative) { void BuildPyramid(int levels, int window_size, bool with_derivative) {
if (use_cv_tracking) {
#if CV_MAJOR_VERSION >= 3 #if CV_MAJOR_VERSION >= 3
// No-op if not called for opencv 3.0 (c interface computes
// pyramids in place).
// OpenCV changed how window size gets specified from our radius setting
// < 2.2 to diameter in 2.2+.
cv::buildOpticalFlowPyramid( cv::buildOpticalFlowPyramid(
frame, pyramid, cv::Size(2 * window_size + 1, 2 * window_size + 1), frame, pyramid, cv::Size(2 * window_size + 1, 2 * window_size + 1),
levels, with_derivative); levels, with_derivative);
@ -408,7 +385,6 @@ struct RegionFlowComputation::FrameTrackingData {
pyramid_levels = levels; pyramid_levels = levels;
#endif #endif
} }
}
void Reset(int frame_num_, int64_t timestamp_) { void Reset(int frame_num_, int64_t timestamp_) {
frame_num = frame_num_; frame_num = frame_num_;
@ -766,22 +742,13 @@ RegionFlowComputation::RegionFlowComputation(
<< "supported."; << "supported.";
// Tracking algorithm dependent on cv support and flag. // Tracking algorithm dependent on cv support and flag.
use_cv_tracking_ = options_.tracking_options().use_cv_tracking_algorithm();
#if CV_MAJOR_VERSION < 3 #if CV_MAJOR_VERSION < 3
if (use_cv_tracking_) { ABSL_LOG(WARNING) << "Tracking is not supported with OpenCV < 3.0";
ABSL_LOG(WARNING) return;
<< "Compiled without OpenCV 3.0 but cv_tracking_algorithm "
<< "was requested. Falling back to older algorithm";
use_cv_tracking_ = false;
}
#endif #endif
if (options_.gain_correction()) { if (options_.gain_correction()) {
gain_image_.reset(new cv::Mat(frame_height_, frame_width_, CV_8UC1)); gain_image_.reset(new cv::Mat(frame_height_, frame_width_, CV_8UC1));
if (!use_cv_tracking_) {
gain_pyramid_.reset(new cv::Mat());
AllocatePyramid(frame_width_, frame_height_, gain_pyramid_.get());
}
} }
// Determine number of levels at which to extract features. If lowest image // Determine number of levels at which to extract features. If lowest image
@ -1089,7 +1056,7 @@ bool RegionFlowComputation::AddImageAndTrack(
data_queue_.pop_front(); data_queue_.pop_front();
} else { } else {
data_queue_.push_back(MakeUnique(new FrameTrackingData( data_queue_.push_back(MakeUnique(new FrameTrackingData(
frame_width_, frame_height_, extraction_levels_, use_cv_tracking_))); frame_width_, frame_height_, extraction_levels_)));
} }
FrameTrackingData* curr_data = data_queue_.back().get(); FrameTrackingData* curr_data = data_queue_.back().get();
@ -2601,7 +2568,6 @@ void RegionFlowComputation::TrackFeatures(FrameTrackingData* from_data_ptr,
feature_track_error_.resize(num_features); feature_track_error_.resize(num_features);
feature_status_.resize(num_features); feature_status_.resize(num_features);
if (use_cv_tracking_) {
#if CV_MAJOR_VERSION >= 3 #if CV_MAJOR_VERSION >= 3
if (gain_correction) { if (gain_correction) {
if (!frame1_gain_reference) { if (!frame1_gain_reference) {
@ -2621,11 +2587,10 @@ void RegionFlowComputation::TrackFeatures(FrameTrackingData* from_data_ptr,
ABSL_LOG(ERROR) << "Tracking method unspecified."; ABSL_LOG(ERROR) << "Tracking method unspecified.";
return; return;
} }
#endif #else
} else { ABSL_LOG(ERROR) << "Only OpenCV >= 3.0 supports tracking.";
ABSL_LOG(ERROR) << "only cv tracking is supported.";
return; return;
} #endif
// Inherit corner response and octaves from extracted features. // Inherit corner response and octaves from extracted features.
corner_responses2 = corner_responses1; corner_responses2 = corner_responses1;
@ -2790,17 +2755,15 @@ void RegionFlowComputation::TrackFeatures(FrameTrackingData* from_data_ptr,
std::vector<float> verify_track_error(num_to_verify); std::vector<float> verify_track_error(num_to_verify);
feature_status_.resize(num_to_verify); feature_status_.resize(num_to_verify);
if (use_cv_tracking_) {
#if CV_MAJOR_VERSION >= 3 #if CV_MAJOR_VERSION >= 3
cv::calcOpticalFlowPyrLK(input_frame2, input_frame1, verify_features, cv::calcOpticalFlowPyrLK(input_frame2, input_frame1, verify_features,
verify_features_tracked, feature_status_, verify_features_tracked, feature_status_,
verify_track_error, cv_window_size, verify_track_error, cv_window_size,
pyramid_levels_, cv_criteria, tracking_flags); pyramid_levels_, cv_criteria, tracking_flags);
#endif #else
} else { ABSL_LOG(ERROR) << "Only OpenCV >= 3.0 supports tracking.";
ABSL_LOG(ERROR) << "only cv tracking is supported.";
return; return;
} #endif
// Check feature destinations, that when tracked back to from data1 to // Check feature destinations, that when tracked back to from data1 to
// data2, don't differ more than a threshold from their original location // data2, don't differ more than a threshold from their original location

View File

@ -448,8 +448,6 @@ class RegionFlowComputation {
// Records data for long feature tracks. // Records data for long feature tracks.
std::unique_ptr<LongTrackData> long_track_data_; std::unique_ptr<LongTrackData> long_track_data_;
bool use_cv_tracking_ = false;
// Counter used for controlling how ofter do we run descriptor extraction. // Counter used for controlling how ofter do we run descriptor extraction.
// Count from 0 to options_.extract_descriptor_every_n_frame() - 1. // Count from 0 to options_.extract_descriptor_every_n_frame() - 1.
// Extract descriptors only when counter == 0. // Extract descriptors only when counter == 0.

View File

@ -144,6 +144,8 @@ message TrackingOptions {
optional FastExtractionSettings fast_settings = 31; optional FastExtractionSettings fast_settings = 31;
// Radius of the window size so that the full window is
// 2*tracking_window_size+1
optional int32 tracking_window_size = 4 [default = 10]; optional int32 tracking_window_size = 4 [default = 10];
optional int32 tracking_iterations = 5 [default = 10]; optional int32 tracking_iterations = 5 [default = 10];
@ -226,10 +228,6 @@ message TrackingOptions {
// they are reset and extracted from scratch. // they are reset and extracted from scratch.
optional float reuse_features_min_survived_frac = 18 [default = 0.7]; optional float reuse_features_min_survived_frac = 18 [default = 0.7];
// If set uses newer OpenCV tracking algorithm.
// Recommended to be set for all new projects.
optional bool use_cv_tracking_algorithm = 30 [default = true];
enum KltTrackerImplementation { enum KltTrackerImplementation {
UNSPECIFIED = 0; UNSPECIFIED = 0;
KLT_OPENCV = 1; // Use OpenCV's implementation of KLT tracker. KLT_OPENCV = 1; // Use OpenCV's implementation of KLT tracker.
@ -240,7 +238,7 @@ message TrackingOptions {
[default = KLT_OPENCV]; [default = KLT_OPENCV];
// Deprecated fields. // Deprecated fields.
extensions 3, 11, 12; extensions 3, 11, 12, 30;
} }
// Next tag: 67 // Next tag: 67