Internal change
PiperOrigin-RevId: 523632081
This commit is contained in:
parent
a7c6910625
commit
2eefc862c2
|
@ -6,7 +6,7 @@ namespace mediapipe {
|
||||||
namespace autoflip {
|
namespace autoflip {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
int Median(const std::deque<std::pair<uint64, int>>& positions_raw) {
|
int Median(const std::deque<std::pair<uint64_t, int>>& positions_raw) {
|
||||||
std::deque<int> positions;
|
std::deque<int> positions;
|
||||||
for (const auto& position : positions_raw) {
|
for (const auto& position : positions_raw) {
|
||||||
positions.push_back(position.second);
|
positions.push_back(position.second);
|
||||||
|
@ -31,7 +31,7 @@ bool KinematicPathSolver::IsMotionTooSmall(double delta_degs) {
|
||||||
void KinematicPathSolver::ClearHistory() { raw_positions_at_time_.clear(); }
|
void KinematicPathSolver::ClearHistory() { raw_positions_at_time_.clear(); }
|
||||||
|
|
||||||
absl::Status KinematicPathSolver::PredictMotionState(int position,
|
absl::Status KinematicPathSolver::PredictMotionState(int position,
|
||||||
const uint64 time_us,
|
const uint64_t time_us,
|
||||||
bool* state) {
|
bool* state) {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
*state = false;
|
*state = false;
|
||||||
|
@ -41,10 +41,10 @@ absl::Status KinematicPathSolver::PredictMotionState(int position,
|
||||||
auto raw_positions_at_time_copy = raw_positions_at_time_;
|
auto raw_positions_at_time_copy = raw_positions_at_time_;
|
||||||
|
|
||||||
raw_positions_at_time_copy.push_front(
|
raw_positions_at_time_copy.push_front(
|
||||||
std::pair<uint64, int>(time_us, position));
|
std::pair<uint64_t, int>(time_us, position));
|
||||||
while (raw_positions_at_time_copy.size() > 1) {
|
while (raw_positions_at_time_copy.size() > 1) {
|
||||||
if (static_cast<int64>(raw_positions_at_time_copy.back().first) <
|
if (static_cast<int64_t>(raw_positions_at_time_copy.back().first) <
|
||||||
static_cast<int64>(time_us) - options_.filtering_time_window_us()) {
|
static_cast<int64_t>(time_us) - options_.filtering_time_window_us()) {
|
||||||
raw_positions_at_time_copy.pop_back();
|
raw_positions_at_time_copy.pop_back();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -78,7 +78,7 @@ absl::Status KinematicPathSolver::PredictMotionState(int position,
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status KinematicPathSolver::AddObservation(int position,
|
absl::Status KinematicPathSolver::AddObservation(int position,
|
||||||
const uint64 time_us) {
|
const uint64_t time_us) {
|
||||||
if (!initialized_) {
|
if (!initialized_) {
|
||||||
if (position < min_location_) {
|
if (position < min_location_) {
|
||||||
current_position_px_ = min_location_;
|
current_position_px_ = min_location_;
|
||||||
|
@ -92,7 +92,7 @@ absl::Status KinematicPathSolver::AddObservation(int position,
|
||||||
motion_state_ = false;
|
motion_state_ = false;
|
||||||
mean_delta_t_ = -1;
|
mean_delta_t_ = -1;
|
||||||
raw_positions_at_time_.push_front(
|
raw_positions_at_time_.push_front(
|
||||||
std::pair<uint64, int>(time_us, position));
|
std::pair<uint64_t, int>(time_us, position));
|
||||||
current_time_ = time_us;
|
current_time_ = time_us;
|
||||||
initialized_ = true;
|
initialized_ = true;
|
||||||
current_velocity_deg_per_s_ = 0;
|
current_velocity_deg_per_s_ = 0;
|
||||||
|
@ -131,10 +131,11 @@ absl::Status KinematicPathSolver::AddObservation(int position,
|
||||||
RET_CHECK(current_time_ < time_us)
|
RET_CHECK(current_time_ < time_us)
|
||||||
<< "Observation added before a prior observations.";
|
<< "Observation added before a prior observations.";
|
||||||
|
|
||||||
raw_positions_at_time_.push_front(std::pair<uint64, int>(time_us, position));
|
raw_positions_at_time_.push_front(
|
||||||
|
std::pair<uint64_t, int>(time_us, position));
|
||||||
while (raw_positions_at_time_.size() > 1) {
|
while (raw_positions_at_time_.size() > 1) {
|
||||||
if (static_cast<int64>(raw_positions_at_time_.back().first) <
|
if (static_cast<int64_t>(raw_positions_at_time_.back().first) <
|
||||||
static_cast<int64>(time_us) - options_.filtering_time_window_us()) {
|
static_cast<int64_t>(time_us) - options_.filtering_time_window_us()) {
|
||||||
raw_positions_at_time_.pop_back();
|
raw_positions_at_time_.pop_back();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -220,7 +221,7 @@ absl::Status KinematicPathSolver::AddObservation(int position,
|
||||||
return UpdatePrediction(time_us);
|
return UpdatePrediction(time_us);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status KinematicPathSolver::UpdatePrediction(const int64 time_us) {
|
absl::Status KinematicPathSolver::UpdatePrediction(const int64_t time_us) {
|
||||||
RET_CHECK(current_time_ < time_us)
|
RET_CHECK(current_time_ < time_us)
|
||||||
<< "Prediction time added before a prior observation or prediction.";
|
<< "Prediction time added before a prior observation or prediction.";
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "mediapipe/framework/port/status.h"
|
#include "mediapipe/framework/port/status.h"
|
||||||
#include "mediapipe/framework/port/status_matchers.h"
|
#include "mediapipe/framework/port/status_matchers.h"
|
||||||
|
|
||||||
constexpr int64 kMicroSecInSec = 1000000;
|
constexpr int64_t kMicroSecInSec = 1000000;
|
||||||
constexpr float kWidthFieldOfView = 60;
|
constexpr float kWidthFieldOfView = 60;
|
||||||
|
|
||||||
namespace mediapipe {
|
namespace mediapipe {
|
||||||
|
@ -43,7 +43,7 @@ TEST(KinematicPathSolverTest, FailNotInitializedState) {
|
||||||
TEST(KinematicPathSolverTest, FailNotInitializedPrediction) {
|
TEST(KinematicPathSolverTest, FailNotInitializedPrediction) {
|
||||||
KinematicOptions options;
|
KinematicOptions options;
|
||||||
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
|
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
|
||||||
int64 timestamp = 0;
|
int64_t timestamp = 0;
|
||||||
EXPECT_FALSE(solver.UpdatePrediction(timestamp).ok());
|
EXPECT_FALSE(solver.UpdatePrediction(timestamp).ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ using ::testing::HasSubstr;
|
||||||
const int kNumKeyFrames = 5;
|
const int kNumKeyFrames = 5;
|
||||||
const int kNumSceneFrames = 30;
|
const int kNumSceneFrames = 30;
|
||||||
|
|
||||||
const int64 kKeyFrameTimestampDiff = 1e6 / kNumKeyFrames;
|
const int64_t kKeyFrameTimestampDiff = 1e6 / kNumKeyFrames;
|
||||||
const int64 kSceneFrameTimestampDiff = 1e6 / kNumSceneFrames;
|
const int64_t kSceneFrameTimestampDiff = 1e6 / kNumSceneFrames;
|
||||||
// Default time span of a scene in seconds.
|
// Default time span of a scene in seconds.
|
||||||
const double kSceneTimeSpanSec = 1.0;
|
const double kSceneTimeSpanSec = 1.0;
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ Rect MakeRect(const int x, const int y, const int width, const int height) {
|
||||||
|
|
||||||
// Returns default values for scene frame timestamps. Populates timestamps using
|
// Returns default values for scene frame timestamps. Populates timestamps using
|
||||||
// the default spacing kSceneFrameTimestampDiff starting from 0.
|
// the default spacing kSceneFrameTimestampDiff starting from 0.
|
||||||
std::vector<int64> GetDefaultSceneFrameTimestamps() {
|
std::vector<int64_t> GetDefaultSceneFrameTimestamps() {
|
||||||
std::vector<int64> scene_frame_timestamps(kNumSceneFrames);
|
std::vector<int64_t> scene_frame_timestamps(kNumSceneFrames);
|
||||||
for (int i = 0; i < kNumSceneFrames; ++i) {
|
for (int i = 0; i < kNumSceneFrames; ++i) {
|
||||||
scene_frame_timestamps[i] = kSceneFrameTimestampDiff * i;
|
scene_frame_timestamps[i] = kSceneFrameTimestampDiff * i;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,7 @@ TEST(SceneCameraMotionAnalyzerTest,
|
||||||
SceneCameraMotionAnalyzerOptions options;
|
SceneCameraMotionAnalyzerOptions options;
|
||||||
TestableSceneCameraMotionAnalyzer analyzer(options);
|
TestableSceneCameraMotionAnalyzer analyzer(options);
|
||||||
SceneCameraMotion camera_motion;
|
SceneCameraMotion camera_motion;
|
||||||
std::vector<int64> scene_frame_timestamps(0);
|
std::vector<int64_t> scene_frame_timestamps(0);
|
||||||
std::vector<FocusPointFrame> focus_point_frames;
|
std::vector<FocusPointFrame> focus_point_frames;
|
||||||
|
|
||||||
const auto status = analyzer.PopulateFocusPointFrames(
|
const auto status = analyzer.PopulateFocusPointFrames(
|
||||||
|
@ -624,7 +624,7 @@ TEST(SceneCameraMotionAnalyzerTest, PopulateFocusPointFramesSweeping) {
|
||||||
55, 65, 75, 85, 95};
|
55, 65, 75, 85, 95};
|
||||||
const std::vector<float> positions_y = {50, 50, 50, 50, 50,
|
const std::vector<float> positions_y = {50, 50, 50, 50, 50,
|
||||||
50, 50, 50, 50, 50};
|
50, 50, 50, 50, 50};
|
||||||
std::vector<int64> scene_frame_timestamps(num_frames);
|
std::vector<int64_t> scene_frame_timestamps(num_frames);
|
||||||
std::iota(scene_frame_timestamps.begin(), scene_frame_timestamps.end(), 0);
|
std::iota(scene_frame_timestamps.begin(), scene_frame_timestamps.end(), 0);
|
||||||
std::vector<FocusPointFrame> focus_point_frames;
|
std::vector<FocusPointFrame> focus_point_frames;
|
||||||
|
|
||||||
|
@ -691,7 +691,7 @@ TEST(SceneCameraMotionAnalyzerTest,
|
||||||
// Aligns timestamps of scene frames with key frames.
|
// Aligns timestamps of scene frames with key frames.
|
||||||
scene_summary.mutable_key_frame_compact_infos(0)->set_timestamp_ms(10);
|
scene_summary.mutable_key_frame_compact_infos(0)->set_timestamp_ms(10);
|
||||||
scene_summary.mutable_key_frame_compact_infos(1)->set_timestamp_ms(20);
|
scene_summary.mutable_key_frame_compact_infos(1)->set_timestamp_ms(20);
|
||||||
std::vector<int64> scene_frame_timestamps = {10, 20};
|
std::vector<int64_t> scene_frame_timestamps = {10, 20};
|
||||||
|
|
||||||
std::vector<FocusPointFrame> focus_point_frames;
|
std::vector<FocusPointFrame> focus_point_frames;
|
||||||
MP_EXPECT_OK(analyzer.PopulateFocusPointFrames(scene_summary, camera_motion,
|
MP_EXPECT_OK(analyzer.PopulateFocusPointFrames(scene_summary, camera_motion,
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace autoflip {
|
||||||
|
|
||||||
absl::Status SceneCropper::ProcessKinematicPathSolver(
|
absl::Status SceneCropper::ProcessKinematicPathSolver(
|
||||||
const SceneKeyFrameCropSummary& scene_summary,
|
const SceneKeyFrameCropSummary& scene_summary,
|
||||||
const std::vector<int64>& scene_timestamps,
|
const std::vector<int64_t>& scene_timestamps,
|
||||||
const std::vector<bool>& is_key_frames,
|
const std::vector<bool>& is_key_frames,
|
||||||
const std::vector<FocusPointFrame>& focus_point_frames,
|
const std::vector<FocusPointFrame>& focus_point_frames,
|
||||||
const bool continue_last_scene, std::vector<cv::Mat>* all_xforms) {
|
const bool continue_last_scene, std::vector<cv::Mat>* all_xforms) {
|
||||||
|
@ -82,7 +82,7 @@ absl::Status SceneCropper::ProcessKinematicPathSolver(
|
||||||
|
|
||||||
absl::Status SceneCropper::CropFrames(
|
absl::Status SceneCropper::CropFrames(
|
||||||
const SceneKeyFrameCropSummary& scene_summary,
|
const SceneKeyFrameCropSummary& scene_summary,
|
||||||
const std::vector<int64>& scene_timestamps,
|
const std::vector<int64_t>& scene_timestamps,
|
||||||
const std::vector<bool>& is_key_frames,
|
const std::vector<bool>& is_key_frames,
|
||||||
const std::vector<cv::Mat>& scene_frames_or_empty,
|
const std::vector<cv::Mat>& scene_frames_or_empty,
|
||||||
const std::vector<FocusPointFrame>& focus_point_frames,
|
const std::vector<FocusPointFrame>& focus_point_frames,
|
||||||
|
|
|
@ -71,8 +71,8 @@ std::vector<FocusPointFrame> GetDefaultFocusPointFrames() {
|
||||||
return GetFocusPointFrames(kNumSceneFrames);
|
return GetFocusPointFrames(kNumSceneFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int64> GetTimestamps(const int num_frames) {
|
std::vector<int64_t> GetTimestamps(const int num_frames) {
|
||||||
std::vector<int64> timestamps;
|
std::vector<int64_t> timestamps;
|
||||||
for (int i = 0; i < num_frames; ++i) {
|
for (int i = 0; i < num_frames; ++i) {
|
||||||
timestamps.push_back(i * 100000);
|
timestamps.push_back(i * 100000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ void RectUnion(const Rect& rect_to_add, Rect* rect) {
|
||||||
rect->set_height(y2 - y1);
|
rect->set_height(y2 - y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status PackKeyFrameInfo(const int64 frame_timestamp_ms,
|
absl::Status PackKeyFrameInfo(const int64_t frame_timestamp_ms,
|
||||||
const DetectionSet& detections,
|
const DetectionSet& detections,
|
||||||
const int original_frame_width,
|
const int original_frame_width,
|
||||||
const int original_frame_height,
|
const int original_frame_height,
|
||||||
|
@ -378,7 +378,7 @@ absl::Status ComputeSceneStaticBordersSize(
|
||||||
|
|
||||||
absl::Status FindSolidBackgroundColor(
|
absl::Status FindSolidBackgroundColor(
|
||||||
const std::vector<StaticFeatures>& static_features,
|
const std::vector<StaticFeatures>& static_features,
|
||||||
const std::vector<int64>& static_features_timestamps,
|
const std::vector<int64_t>& static_features_timestamps,
|
||||||
const double min_fraction_solid_background_color,
|
const double min_fraction_solid_background_color,
|
||||||
bool* has_solid_background,
|
bool* has_solid_background,
|
||||||
PiecewiseLinearFunction* background_color_l_function,
|
PiecewiseLinearFunction* background_color_l_function,
|
||||||
|
@ -395,7 +395,7 @@ absl::Status FindSolidBackgroundColor(
|
||||||
if (static_features[i].has_solid_background()) {
|
if (static_features[i].has_solid_background()) {
|
||||||
solid_background_frames++;
|
solid_background_frames++;
|
||||||
const auto& color = static_features[i].solid_background();
|
const auto& color = static_features[i].solid_background();
|
||||||
const int64 timestamp = static_features_timestamps[i];
|
const int64_t timestamp = static_features_timestamps[i];
|
||||||
// BorderDetectionCalculator sets color assuming the input frame is
|
// BorderDetectionCalculator sets color assuming the input frame is
|
||||||
// BGR, but in reality we have RGB, so we need to revert it here.
|
// BGR, but in reality we have RGB, so we need to revert it here.
|
||||||
// TODO remove this custom logic in BorderDetectionCalculator,
|
// TODO remove this custom logic in BorderDetectionCalculator,
|
||||||
|
|
|
@ -31,12 +31,12 @@ namespace {
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using ::testing::HasSubstr;
|
||||||
|
|
||||||
const int64 kTimestamp = 0;
|
const int64_t kTimestamp = 0;
|
||||||
const int kOriginalWidth = 100;
|
const int kOriginalWidth = 100;
|
||||||
const int kOriginalHeight = 100;
|
const int kOriginalHeight = 100;
|
||||||
const double kTargetAspectRatio = 1.5;
|
const double kTargetAspectRatio = 1.5;
|
||||||
const int kNumKeyFrames = 5;
|
const int kNumKeyFrames = 5;
|
||||||
const int64 kKeyFrameTimestampDiff = 1e6 / kNumKeyFrames;
|
const int64_t kKeyFrameTimestampDiff = 1e6 / kNumKeyFrames;
|
||||||
const int kTargetWidth = 50;
|
const int kTargetWidth = 50;
|
||||||
const int kTargetHeight = 50;
|
const int kTargetHeight = 50;
|
||||||
|
|
||||||
|
@ -874,7 +874,7 @@ TEST(UtilTest, ComputeSceneStaticBordersSizeHasBorders) {
|
||||||
// Checks that FindSolidBackgroundColor checks output not null.
|
// Checks that FindSolidBackgroundColor checks output not null.
|
||||||
TEST(UtilTest, FindSolidBackgroundColorChecksOutputNotNull) {
|
TEST(UtilTest, FindSolidBackgroundColorChecksOutputNotNull) {
|
||||||
std::vector<StaticFeatures> static_features;
|
std::vector<StaticFeatures> static_features;
|
||||||
std::vector<int64> static_features_timestamps;
|
std::vector<int64_t> static_features_timestamps;
|
||||||
const double min_fraction_solid_background_color = 0.8;
|
const double min_fraction_solid_background_color = 0.8;
|
||||||
bool has_solid_background_color;
|
bool has_solid_background_color;
|
||||||
PiecewiseLinearFunction l_function, a_function, b_function;
|
PiecewiseLinearFunction l_function, a_function, b_function;
|
||||||
|
@ -903,7 +903,7 @@ TEST(UtilTest, FindSolidBackgroundColorReturnsTrue) {
|
||||||
color->set_r(255);
|
color->set_r(255);
|
||||||
color->set_g(255);
|
color->set_g(255);
|
||||||
color->set_b(255);
|
color->set_b(255);
|
||||||
std::vector<int64> static_features_timestamps(1);
|
std::vector<int64_t> static_features_timestamps(1);
|
||||||
static_features_timestamps[0] = 0;
|
static_features_timestamps[0] = 0;
|
||||||
const double min_fraction_solid_background_color = 0.8;
|
const double min_fraction_solid_background_color = 0.8;
|
||||||
bool has_solid_background_color;
|
bool has_solid_background_color;
|
||||||
|
@ -920,7 +920,7 @@ TEST(UtilTest, FindSolidBackgroundColorReturnsTrue) {
|
||||||
// background color.
|
// background color.
|
||||||
TEST(UtilTest, FindSolidBackgroundColorReturnsFalse) {
|
TEST(UtilTest, FindSolidBackgroundColorReturnsFalse) {
|
||||||
std::vector<StaticFeatures> static_features(1);
|
std::vector<StaticFeatures> static_features(1);
|
||||||
std::vector<int64> static_features_timestamps(1);
|
std::vector<int64_t> static_features_timestamps(1);
|
||||||
static_features_timestamps[0] = 0;
|
static_features_timestamps[0] = 0;
|
||||||
const double min_fraction_solid_background_color = 0.8;
|
const double min_fraction_solid_background_color = 0.8;
|
||||||
bool has_solid_background_color;
|
bool has_solid_background_color;
|
||||||
|
@ -935,12 +935,12 @@ TEST(UtilTest, FindSolidBackgroundColorReturnsFalse) {
|
||||||
|
|
||||||
// Checks that FindSolidBackgroundColor sets the interpolation functions.
|
// Checks that FindSolidBackgroundColor sets the interpolation functions.
|
||||||
TEST(UtilTest, FindSolidBackgroundColorSetsInterpolationFunctions) {
|
TEST(UtilTest, FindSolidBackgroundColorSetsInterpolationFunctions) {
|
||||||
const uint8 rgb1[] = {255, 255, 0}; // cyan in bgr
|
const uint8_t rgb1[] = {255, 255, 0}; // cyan in bgr
|
||||||
const double lab1[] = {91.1133, -48.0938, -14.125};
|
const double lab1[] = {91.1133, -48.0938, -14.125};
|
||||||
const int64 time1 = 0;
|
const int64_t time1 = 0;
|
||||||
const uint8 rgb2[] = {255, 0, 255}; // magenta in bgr
|
const uint8_t rgb2[] = {255, 0, 255}; // magenta in bgr
|
||||||
const double lab2[] = {60.321, 98.2344, -60.8281};
|
const double lab2[] = {60.321, 98.2344, -60.8281};
|
||||||
const int64 time2 = 2000;
|
const int64_t time2 = 2000;
|
||||||
std::vector<StaticFeatures> static_features(2);
|
std::vector<StaticFeatures> static_features(2);
|
||||||
auto* color1 = static_features[0].mutable_solid_background();
|
auto* color1 = static_features[0].mutable_solid_background();
|
||||||
color1->set_r(rgb1[0]);
|
color1->set_r(rgb1[0]);
|
||||||
|
@ -950,7 +950,7 @@ TEST(UtilTest, FindSolidBackgroundColorSetsInterpolationFunctions) {
|
||||||
color2->set_r(rgb2[0]);
|
color2->set_r(rgb2[0]);
|
||||||
color2->set_g(rgb2[1]);
|
color2->set_g(rgb2[1]);
|
||||||
color2->set_b(rgb2[2]);
|
color2->set_b(rgb2[2]);
|
||||||
std::vector<int64> static_features_timestamps(2);
|
std::vector<int64_t> static_features_timestamps(2);
|
||||||
static_features_timestamps[0] = time1;
|
static_features_timestamps[0] = time1;
|
||||||
static_features_timestamps[1] = time2;
|
static_features_timestamps[1] = time2;
|
||||||
const double min_fraction_solid_background_color = 0.8;
|
const double min_fraction_solid_background_color = 0.8;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user