EasyMocap

repository·master·Indexed 26 days ago

https://github.com/zju3dv/easymocap

An open-source toolbox for markerless human motion capture and novel view synthesis using RGB videos. It supports single-person and multi-person multi-view setups, internet video processing (including mirrored sources), and fitting SMPL, SMPL+H, SMPL-X, or MANO models. The toolkit includes features for camera calibration (intrinsic and extrinsic), 3D realtime visualization of skeletons and meshes, and an annotation system for bounding boxes, keypoints, and masks.

Tokens
40.1K
Snippets
111
Records
199
Agent score
87%

What's inside EasyMocap

  1. Overview of EasyMocap features

    master

    EasyMocap is an open-source toolbox for markerless human motion capture and novel view synthesis from RGB videos. Key capabilities include:

    • Multiple views of a single person: Fitting SMPL, SMPL+H, SMPL-X, or MANO models to capture body, hand, and face poses from multiple calibrated camera views.
    • Internet video motion capture: Fitting SMPL models using 2D keypoint estimation and CNN initialization from single internet videos.
    • Internet video with a mirror: Specialized support for motion capture from mirrored video sources.
    • Multiple views of multiple people: Capturing multiple subjects simultaneously from multiple camera views.
    • Novel view synthesis: Generating novel views from sparse views for human motion.
    • 3D Realtime visualization: Real-time visualization of skeletons and meshes (SMPL, SMPL-X, MANO).
    • Camera calibration: Tools for determining intrinsic and extrinsic camera parameters.
    • Annotator: A tool for annotating bounding boxes, keypoints, and masks.
  2. Overview of pybind11

    master
    pybind11 is a lightweight, header-only C++ library used to expose C++ types in Python and vice versa. It is primarily used to create Python bindings for existing C++ code by using compile-time introspection to minimize boilerplate. It is designed as a compact, self-contained alternative to Boost.Python, leveraging C++11 features like tuples, lambda functions, and variadic templates.
  3. Understand the mv1p.py Pipeline Workflow

    master

    The pipeline follows this execution logic:

    1. Argument Parsing & Dataset Creation: load_parser() and parse_parser() define arguments and automatically detect camera subdirectories (e.g., ['1','2','3','4']) from the images/ directory. Results are saved to exp.yml.
    2. Dataset Initialization (MV1PMF): Scans images/{cam}/ and annots/{cam}/ for each camera, determines the minimum frame count across all views, and reads camera parameters (intri.yml and extri.yml) to compute projection matrices $P = K @ [R | T]$.
    3. Stage 1: Triangulation (mv1pmf_skel):
      • Reads 2D keypoints.
      • Performs SVD triangulation via simple_recon_person.
      • Checks reprojection error; if error $> 50$ pixels, the keypoint is zeroed and re-triangulated.
      • Outputs 3D keypoints to {out}/keypoints3d/{:06d}.json.
    4. Stage 2: SMPL Fitting (mv1pmf_smpl):
      • Loads SMPL model and 3D/2D keypoints.
      • Optimizes Shape, then 3D Pose (Global RT + Body Pose), then 2D Pose.
      • Outputs SMPL parameters to {out}/smpl/{:06d}.json.
  4. Understand C++11 clock types for conversions

    master

    When performing conversions, be aware of the differences between C++11 clock types, as they affect the resulting Python types:

    • std::chrono::system_clock: Measures current date and time. It can change based on OS updates (e.g., NTP synchronization). Converting this to Python results in datetime.datetime objects.
    • std::chrono::steady_clock: Ticks at a steady rate and is never adjusted. It is ideal for timing but does not correspond to the current date/time. Converting this to Python results in datetime.timedelta objects.
    • std::chrono::high_resolution_clock: Provides the highest resolution available. It may be a typedef of system_clock (resulting in datetime.datetime in Python) or steady_clock (resulting in datetime.timedelta in Python), depending on the system.
  5. Understand the mv1p.py data flow

    master

    The mv1p.py pipeline operates in two main phases:

    Phase 1: Triangulation

    Converts multi-view 2D keypoints to 3D keypoints using SVD/DLT.

    • Input: Images, 2D annotations (Body25), and camera parameters (intri.yml, extri.yml).
    • Output: keypoints3d/*.json.

    Phase 2: SMPL Fitting

    Optimizes SMPL parameters based on the 3D and 2D data.

    1. optimizeShape: Estimates body shape from bone lengths.
    2. optimizePose3D: Optimizes global rotation (Rh), translation (Th), and 3D poses from 3D keypoints.
    3. optimizePose2D: Fine-tunes parameters using 2D keypoint constraints.
    • Output: smpl/*.json and various visualizations.
  6. Calibrate intrinsic parameters

    master

    Once chessboard corners are extracted and verified, run the intrinsic calibration. This step may take a significant amount of time.

    python3 apps/calibration/calib_intri.py ${data} --step 5

    Output: An intri.yml file will be generated in ${data}/output.

    python3 apps/calibration/calib_intri.py ${data} --step 5
  7. Preprocess your own dataset with OpenPose

    master

    Use the extract_video.py script to preprocess your videos and integrate OpenPose for keypoint detection. You can specify the OpenPose path and enable hand/face detection.

    data=path/to/data
    out=path/to/output
    python3 scripts/preprocess/extract_video.py ${data} --openpose <openpose_path> --handface
  8. Explicitly convert non-UTF-8 C++ strings to Python strings

    master

    If a C++ std::string contains data using a different encoding (e.g., Latin-1), you must perform an explicit conversion to a py::str object to avoid UnicodeDecodeError in Python. You can use the Python C API (e.g., PyUnicode_DecodeLatin1) or a third-party library like libiconv to transcode to UTF-8.

    // This uses the Python C API to convert Latin-1 to Unicode
    m.def("str_output",
        []() {
            std::string s = "Send your r\xe9sum\xe9 to Alice in HR"; // Latin-1
            py::str py_s = PyUnicode_DecodeLatin1(s.data(), s.length());
            return py_s;
        }
    );
  9. Generate pybind11 binding code automatically with Binder

    master

    If you need to generate pybind11 binding code automatically, you can use the Binder project. It introspects existing C++ codebases using LLVM/Clang to automate the process. Refer to the official Binder documentation for detailed usage instructions.

    http://cppbinder.readthedocs.io/en/latest/about.html
  10. Redirect C++ `std::cout` and `std::cerr` to Python streams

    master

    If a C++ library uses std::cout or std::cerr, its output won't automatically appear in Python's sys.stdout or sys.stderr. You can use py::scoped_ostream_redirect or py::scoped_estream_redirect to redirect these streams. These guards respect flushes and allow real-time redirection (e.g., to a Jupyter notebook).

    Note: These methods do not redirect C-level output like fprintf. For that, you must redirect file descriptors using os.dup2 or OS-specific C calls.

    #include <pybind11/iostream.h>
    
    // Add a scoped redirect for your noisy code
    m.def("noisy_func", []() {
        py::scoped_ostream_redirect stream(
            std::cout,                               // std::ostream&
            py::module::import("sys").attr("stdout") // Python output
        );
        call_noisy_func();
    });
  11. Recover SMPL body model from keypoints

    master

    Fit the SMPL body model to the tracked 3D keypoints. This uses the tracked keypoints generated by auto_track.py to produce the final SMPL model output.

    python3 apps/demo/smpl_from_keypoints.py ${data} --skel ${data}/output-track/keypoints3d --out ${data}/output-track/smpl --verbose --opts smooth_poses 1e1
  12. Prepare your own dataset for EasyMocap

    master

    To use your own dataset, organize your files into the following directory structure:

    <seq>
    ├── intri.yml
    ├── extri.yml
    └── videos
        ├── 1.mp4
        ├── 2.mp4
        └── ...
    • videos/: Contains the input video files.
    • intri.yml: Stores camera intrinsic parameters.
    • extri.yml: Stores camera extrinsic parameters.

    For instructions on camera calibration and the specific format for camera parameters, refer to the apps/calibration documentation.