Skip to content

Commit 6aa71a5

Browse files
cdtwiggfacebook-github-bot
authored andcommitted
Support calibrating shape in mocap tracker. (#572)
Summary: Pull Request resolved: #572 We want to experiment with calibration shape and markers simultaneously. Reviewed By: jeongseok-meta Differential Revision: D81521304 fbshipit-source-id: c46bde71708e760bcf5740b18ed254ebb98f6493
1 parent 1371148 commit 6aa71a5

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

momentum/marker_tracking/marker_tracker.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "momentum/common/log.h"
2424
#include "momentum/common/progress_bar.h"
2525
#include "momentum/marker_tracking/tracker_utils.h"
26+
#include "momentum/math/mesh.h"
2627
#include "momentum/solver/gauss_newton_solver.h"
2728
#include "momentum/solver/solver.h"
2829

@@ -210,7 +211,7 @@ Eigen::MatrixXf trackSequence(
210211
// (ie. not time varying). The input globalParams indicate which parameters within universalParams
211212
// we want to solve for. globalParams is either a subset or all of universalParams.
212213
ParameterSet poseParams = pt.getPoseParameters();
213-
ParameterSet universalParams = pt.getScalingParameters();
214+
ParameterSet universalParams = pt.getScalingParameters() | pt.getBlendShapeParameters();
214215
const auto locatorSet =
215216
pt.getParameterSet("locators", true) | pt.getParameterSet("skinnedLocators", true);
216217
poseParams &= ~locatorSet;
@@ -727,6 +728,11 @@ void calibrateModel(
727728
} else {
728729
calibBodySetExtended = transformExtended.getScalingParameters();
729730
calibBodySet = transform.getScalingParameters();
731+
732+
if (config.calibShape) {
733+
calibBodySetExtended |= transformExtended.getBlendShapeParameters();
734+
calibBodySet |= transform.getBlendShapeParameters();
735+
}
730736
}
731737

732738
// special trackingConfig for initialization: zero out smoothness and collision
@@ -852,6 +858,9 @@ void calibrateModel(
852858
// below.
853859
std::tie(identity.v, character.locators, character.skinnedLocators) =
854860
extractIdAndLocatorsFromParams(motion.col(0), solvingCharacter, character);
861+
if (config.calibShape && solvingCharacter.blendShape && character.mesh) {
862+
*character.mesh = extractBlendShapeFromParams(motion.col(0), solvingCharacter);
863+
}
855864

856865
// The sequence solve above could get stuck with euler singularity but per-frame solve could get
857866
// it out. Pass in the first frame from previous solve as a better initial guess than the zero

momentum/marker_tracking/marker_tracker.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ struct CalibrationConfig : public BaseConfig {
4545
bool enforceFloorInFirstFrame = false;
4646
/// Name of a pose constraint set to use for the first frame
4747
std::string firstFramePoseConstraintSet;
48+
/// Calibrate the character's shape
49+
bool calibShape = false;
4850
};
4951

5052
/// Configuration for pose tracking given a calibrated body and locators

momentum/marker_tracking/tracker_utils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "momentum/marker_tracking/tracker_utils.h"
99

10+
#include "momentum/character/blend_shape.h"
11+
#include "momentum/character/blend_shape_skinning.h"
1012
#include "momentum/character/character.h"
1113
#include "momentum/character/inverse_parameter_transform.h"
1214
#include "momentum/character/parameter_limits.h"
@@ -451,6 +453,15 @@ std::tuple<Eigen::VectorXf, LocatorList, SkinnedLocatorList> extractIdAndLocator
451453
skinnedLocators};
452454
}
453455

456+
Mesh extractBlendShapeFromParams(
457+
const momentum::ModelParameters& param,
458+
const momentum::Character& sourceCharacter) {
459+
Mesh result = *sourceCharacter.mesh;
460+
auto blendWeights = extractBlendWeights(sourceCharacter.parameterTransform, param);
461+
result.vertices = sourceCharacter.blendShape->computeShape<float>(blendWeights);
462+
return result;
463+
}
464+
454465
void fillIdentity(
455466
const ParameterSet& idSet,
456467
const ModelParameters& identity,

momentum/marker_tracking/tracker_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ extractIdAndLocatorsFromParams(
5858
const momentum::Character& sourceCharacter,
5959
const momentum::Character& targetCharacter);
6060

61+
Mesh extractBlendShapeFromParams(
62+
const momentum::ModelParameters& param,
63+
const momentum::Character& sourceCharacter);
64+
6165
void fillIdentity(
6266
const momentum::ParameterSet& idSet,
6367
const momentum::ModelParameters& identity,

pymomentum/marker_tracking/marker_tracking_pybind.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ PYBIND11_MODULE(marker_tracking, m) {
118118
"__repr__",
119119
[](const momentum::CalibrationConfig& self) {
120120
return fmt::format(
121-
"CalibrationConfig(min_vis_percent={}, loss_alpha={}, max_iter={}, regularization={}, debug={}, calib_frames={}, major_iter={}, global_scale_only={}, locators_only={}, greedy_sampling={}, enforce_floor_in_first_frame={}, first_frame_pose_constraint_set=\"{}\")",
121+
"CalibrationConfig(min_vis_percent={}, loss_alpha={}, max_iter={}, regularization={}, debug={}, calib_frames={}, major_iter={}, global_scale_only={}, locators_only={}, greedy_sampling={}, enforce_floor_in_first_frame={}, first_frame_pose_constraint_set=\"{}\", calib_shape={})",
122122
self.minVisPercent,
123123
self.lossAlpha,
124124
self.maxIter,
@@ -130,7 +130,8 @@ PYBIND11_MODULE(marker_tracking, m) {
130130
boolToString(self.locatorsOnly),
131131
self.greedySampling,
132132
boolToString(self.enforceFloorInFirstFrame),
133-
self.firstFramePoseConstraintSet);
133+
self.firstFramePoseConstraintSet,
134+
boolToString(self.calibShape));
134135
})
135136
.def(
136137
py::init<
@@ -145,7 +146,8 @@ PYBIND11_MODULE(marker_tracking, m) {
145146
bool,
146147
size_t,
147148
bool,
148-
std::string>(),
149+
std::string,
150+
bool>(),
149151
R"(Create a CalibrationConfig with specified parameters.
150152
151153
:param min_vis_percent: Minimum percentage of visible markers to be used
@@ -171,7 +173,8 @@ PYBIND11_MODULE(marker_tracking, m) {
171173
py::arg("locators_only") = false,
172174
py::arg("greedy_sampling") = 0,
173175
py::arg("enforce_floor_in_first_frame") = false,
174-
py::arg("first_frame_pose_constraint_set") = "")
176+
py::arg("first_frame_pose_constraint_set") = "",
177+
py::arg("calib_shape") = false)
175178
.def_readwrite(
176179
"calib_frames",
177180
&momentum::CalibrationConfig::calibFrames,
@@ -199,7 +202,11 @@ PYBIND11_MODULE(marker_tracking, m) {
199202
.def_readwrite(
200203
"first_frame_pose_constraint_set",
201204
&momentum::CalibrationConfig::firstFramePoseConstraintSet,
202-
"Name of pose constraint set to use in first frame");
205+
"Name of pose constraint set to use in first frame")
206+
.def_readwrite(
207+
"calib_shape",
208+
&momentum::CalibrationConfig::calibShape,
209+
"Calibrate shape parameters");
203210

204211
auto trackingConfig =
205212
py::class_<momentum::TrackingConfig, momentum::BaseConfig>(

0 commit comments

Comments
 (0)