Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
marker_tracker.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <momentum/camera/camera.h>
16
17namespace momentum {
18
25 size_t locatorIndex{};
26 Eigen::Vector2f target = Eigen::Vector2f::Zero();
27 float confidence = 1.0f;
28};
29
37 Camera camera;
38 std::vector<std::vector<KeypointObservation>> frameData;
39};
40
42struct BaseConfig {
45 float minVisPercent = 0.f;
48 float lossAlpha = 2.0;
50 size_t maxIter = 30;
52 float regularization = 0.05f;
54 bool debug = false;
55};
56
60 size_t calibFrames = 100;
63 size_t majorIter = 3;
65 bool globalScaleOnly = false;
67 bool locatorsOnly = false;
69 size_t greedySampling = 0;
80 bool calibShape = false;
82 float targetHeightCm = 0.0f;
87 float projectionWeight = 0.0f;
91 float floorContactPercentile = 1.0f / 3.0f;
92};
93
95struct TrackingConfig : public BaseConfig {
97 float smoothing = 0;
102 float markerWeight = 1.0f;
105 Eigen::VectorXf smoothingWeights{};
110 std::optional<ParameterSet> activeParams;
115 float projectionWeight = 0.0f;
120};
121
127 float regularizer = 0.0;
129 bool calibId = false;
131 bool calibLocators = false;
132};
133
151Eigen::MatrixXf trackSequence(
152 std::span<const std::vector<momentum::Marker>> markerData,
153 const momentum::Character& character,
154 const momentum::ParameterSet& globalParams,
155 const Eigen::MatrixXf& initialMotion,
156 const TrackingConfig& config,
157 float regularizer = 0.0,
158 size_t frameStride = 1,
159 bool enforceFloorInFirstFrame = false,
160 const std::string& firstFramePoseConstraintSet = "",
161 float targetHeightCm = 0.0f,
162 std::span<const GloveFrameData> leftGloveData = {},
163 std::span<const GloveFrameData> rightGloveData = {},
164 const std::optional<GloveConfig>& gloveConfig = std::nullopt,
165 std::span<const CameraKeypointData> cameraKeypointData = {});
166
183Eigen::MatrixXf trackSequence(
184 std::span<const std::vector<momentum::Marker>> markerData,
185 const momentum::Character& character,
186 const momentum::ParameterSet& globalParams,
187 const Eigen::MatrixXf& initialMotion,
188 const TrackingConfig& config,
189 const std::vector<size_t>& frames,
190 float regularizer = 0.0,
191 bool enforceFloorInFirstFrame = false,
192 const std::string& firstFramePoseConstraintSet = "",
193 float targetHeightCm = 0.0f,
194 std::span<const GloveFrameData> leftGloveData = {},
195 std::span<const GloveFrameData> rightGloveData = {},
196 const std::optional<GloveConfig>& gloveConfig = std::nullopt,
197 std::span<const CameraKeypointData> cameraKeypointData = {},
198 std::span<const std::vector<PlaneDataT<float>>> perFrameFloorContacts = {});
199
211Eigen::MatrixXf trackPosesPerframe(
212 std::span<const std::vector<momentum::Marker>> markerData,
213 const momentum::Character& character,
214 const momentum::ModelParameters& globalParams,
215 const TrackingConfig& config,
216 size_t frameStride = 1,
217 std::span<const GloveFrameData> leftGloveData = {},
218 std::span<const GloveFrameData> rightGloveData = {},
219 const std::optional<GloveConfig>& gloveConfig = std::nullopt);
220
233Eigen::MatrixXf trackPosesForFrames(
234 std::span<const std::vector<momentum::Marker>> markerData,
235 const momentum::Character& character,
236 const Eigen::MatrixXf& initialMotion,
237 const TrackingConfig& config,
238 const std::vector<size_t>& frameIndices,
239 bool isContinuous = false,
240 std::span<const GloveFrameData> leftGloveData = {},
241 std::span<const GloveFrameData> rightGloveData = {},
242 const std::optional<GloveConfig>& gloveConfig = std::nullopt,
243 const std::string& progressLabel = "Tracking per-frame");
244
263 std::span<const std::vector<momentum::Marker>> markerData,
264 const CalibrationConfig& config,
265 momentum::Character& character,
267 const std::array<float, 3>& regularizerWeights = {0.0f, 0.0f, 0.0f},
268 std::span<const GloveFrameData> leftGloveData = {},
269 std::span<const GloveFrameData> rightGloveData = {},
270 const std::optional<GloveConfig>& gloveConfig = std::nullopt,
271 std::span<const CameraKeypointData> cameraKeypointData = {},
272 std::vector<size_t>* selectedFrameIndices = nullptr,
273 Eigen::MatrixXf* selectedFrameMotion = nullptr);
274
284 std::span<const std::vector<momentum::Marker>> markerData,
285 const CalibrationConfig& config,
286 const momentum::ModelParameters& identity,
287 momentum::Character& character);
288
289Eigen::MatrixXf refineMotion(
290 std::span<const std::vector<momentum::Marker>> markerData,
291 const Eigen::MatrixXf& motion,
292 const RefineConfig& config,
293 momentum::Character& character);
294
301std::pair<float, float> getLocatorError(
302 std::span<const std::vector<momentum::Marker>> markerData,
303 const Eigen::MatrixXf& motion,
304 momentum::Character& character);
305
306} // namespace momentum
Eigen::MatrixXf trackSequence(const std::span< const std::vector< Marker > > markerData, const Character &character, const ParameterSet &globalParams, const MatrixXf &initialMotion, const TrackingConfig &config, float regularizer, const size_t frameStride, bool enforceFloorInFirstFrame, const std::string &firstFramePoseConstraintSet, float targetHeightCm, std::span< const GloveFrameData > leftGloveData, std::span< const GloveFrameData > rightGloveData, const std::optional< GloveConfig > &gloveConfig, std::span< const CameraKeypointData > cameraKeypointData)
Track motion across multiple frames simultaneously with temporal constraints.
Eigen::MatrixXf trackPosesForFrames(const std::span< const std::vector< Marker > > markerData, const Character &character, const MatrixXf &initialMotion, const TrackingConfig &config, const std::vector< size_t > &frameIndices, bool isContinuous, std::span< const GloveFrameData > leftGloveData, std::span< const GloveFrameData > rightGloveData, const std::optional< GloveConfig > &gloveConfig, const std::string &progressLabel)
Track poses independently for specific frame indices with fixed character identity.
std::pair< float, float > getLocatorError(std::span< const std::vector< momentum::Marker > > markerData, const MatrixXf &motion, momentum::Character &character)
Compute average and maximum marker tracking errors across all frames.
Eigen::MatrixXf trackPosesPerframe(const std::span< const std::vector< Marker > > markerData, const Character &character, const ModelParameters &globalParams, const TrackingConfig &config, const size_t frameStride, std::span< const GloveFrameData > leftGloveData, std::span< const GloveFrameData > rightGloveData, const std::optional< GloveConfig > &gloveConfig)
Track poses independently per frame with fixed character identity.
MatrixXf refineMotion(std::span< const std::vector< momentum::Marker > > markerData, const MatrixXf &motion, const RefineConfig &config, momentum::Character &character)
Refine existing motion by smoothing and optionally recalibrating identity/locators.
void calibrateLocators(const std::span< const std::vector< Marker > > markerData, const CalibrationConfig &config, const ModelParameters &identity, Character &character)
Calibrate only locator positions with fixed character identity parameters.
void calibrateModel(const std::span< const std::vector< Marker > > markerData, const CalibrationConfig &config, Character &character, ModelParameters &identity, const std::array< float, 3 > &regularizerWeights, std::span< const GloveFrameData > leftGloveData, std::span< const GloveFrameData > rightGloveData, const std::optional< GloveConfig > &gloveConfig, std::span< const CameraKeypointData > cameraKeypointData, std::vector< size_t > *selectedFrameIndices, Eigen::MatrixXf *selectedFrameMotion)
ModelParametersT< float > ModelParameters
Definition types.h:105
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Definition types.h:430
Common configuration for a tracking problem.
float regularization
Regularization parameter (lambda) for Levenberg-Marquardt solver.
size_t maxIter
Max number of solver iterations to run.
float minVisPercent
Minimum percentage of visible markers in a frame to consider for tracking.
float lossAlpha
Parameter to control what loss function to use.
bool debug
True to print and save debug information.
Configuration for running body and/or locator calibration.
float floorContactPercentile
Percentile threshold for adaptive floor contact detection (0-1).
bool locatorsOnly
True to calibrate only the locators and not the body.
bool enforceFloorInFirstFrame
Force all floor locators to y=0 on frame 0 with high weight.
float meshConstraintWeight
Multiplier for the mesh surface constraint weight on skinned locators during shape calibration.
float projectionWeight
Base weight for 2D keypoint projection constraints. Set to 0 to disable.
std::string firstFramePoseConstraintSet
Name of a pose constraint set to use for the first frame.
size_t majorIter
Number of iterations to run the main calibration loop.
float targetHeightCm
Target height in cm for the character, if set to 0, no height constraint is applied.
size_t greedySampling
Sample uniformly or do a greedy importance sampling.
bool adaptiveFloorContact
Enable adaptive floor contact detection during calibration.
bool calibShape
Calibrate the character's shape.
size_t calibFrames
Number of frames used in calibration. It will be a uniform sample from the input.
bool globalScaleOnly
True to only solve for a global body scale without changing individual bone length.
Per-camera 2D keypoint data for all frames.
std::vector< std::vector< KeypointObservation > > frameData
Per-frame keypoint observations.
Camera camera
Camera intrinsics and extrinsics (world-space).
A character model with skeletal structure, mesh, and optional components.
Definition character.h:32
Configuration for marker gap filling and blend-off.
A single 2D keypoint observation from a camera view.
float confidence
Detection confidence, used as weight multiplier.
Eigen::Vector2f target
Target 2D pixel coordinates.
size_t locatorIndex
Index into the character's locator list.
Configuration for refining an already tracked motion, eg.
bool calibLocators
Calibrate locators when refining the motion.
bool calibId
Calibrate identity parameters when refining the motion.
float regularizer
Minimize changes to calibration parameters when in calibration mode, by regularizing towards the inpu...
Configuration for pose tracking given a calibrated body and locators.
GapFillConfig gapFillConfig
Configuration for pre-processing marker gaps before constraint creation.
float markerWeight
Multiplier for the marker position constraint weight.
float projectionWeight
Base weight for 2D keypoint projection constraints. Default 0 (disabled).
float collisionErrorWeight
The weight for the collision error function.
float smoothing
The weight for the smoothness error function.
Eigen::VectorXf smoothingWeights
Smoothing weights per model parameter.
std::optional< ParameterSet > activeParams
Optional mask to restrict which parameters are optimized during tracking.
float meshConstraintWeight
Multiplier for the mesh surface constraint weight on skinned locators.