RidgeRun Video Stabilization Library/API Reference/Adding Stabilization Algorithm: Difference between revisions

From RidgeRun Developer Wiki
m (change title)
Tag: Manual revert
Line 3: Line 3:
</noinclude>
</noinclude>


{{DISPLAYTITLE:API Reference / Adding Stabilization Algorithm|noerror}}
{{DISPLAYTITLE:API Reference / Adding Stabilization Algorithms|noerror}}


== Introduction ==
== Introduction ==

Revision as of 23:50, 27 June 2024








Introduction

The stabilization algorithms dictate how will the interpolated orientations for each frame will be smoothed out and readjusted. Generally each algorithm can be understood as a filter that takes a vector of quaternion-timestamp value pairs and delivers a vector of corrected orientations whose correction an be tuned by certain given parameters. The steps to implement a new stabilization algorithm are:

  • Define the new stabilization algorithm.
  • Define the stabilizer parameters for the algorithm.

Next, we will showcase how to implement any algorithm following the previous steps.

Define the Stabilization Algorithm

The RidgeRun Video Stabilization Library is extensible and can adopt different stabilization algorithms. The IStabilizer interface describes how to implement new algorithms with the following methods:

  • The Apply method that implements the core of the algorithm.
  • The Reset method that updates the stabilization algorithm parameters.

Define the Apply Method

This method needs to receive a input vector of quaterion-timestamp value pairs as the first parameter. The quaternions must be in double format and the timestamps need to be 64 bit unsigned integer in microsecond units. The second parameter corresponds to the framerate of the video stream to correct and its generally required by stabilization algorithms.

Moreover, the element with index 1 of the resulting quaternion vector must correspond to the current frame orientation; this is because the overloaded declaration of the Apply method which returns just the desired quaternion instead of the complete vector.

RuntimeError ExampleStabilizer::Apply(
    std::vector<Quaternion<double>>& correction,
    const std::vector<std::pair<Quaternion<double>, uint64_t>>& interpolated,
    const double rate) {
  RuntimeError ret{};
  /* Algorithm here */
  return ret;
}

Define the Reset Method

This method only needs to specify how to dynamically cast the parameters shared pointer into the stabilizer algorithm class.

RuntimeError ExampleStabilizer::Reset(
    const std::shared_ptr<StabilizerParams> params) {
  RuntimeError ret{};
  std::shared_ptr<ExampleParams> casted =
      std::dynamic_pointer_cast<ExampleParams>(params);
  if (casted == nullptr) {
    throw RuntimeError{RuntimeError::IncompatibleParameters,
                       "The runtime settings are incompatible. Use "
                       "ExampleParams"};
  } else {
    params_ = casted;
    return ret;
  }
}

Define the Stabilization Parameters