Jump to content

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

(Page skeleton and introduction)
 
Line 14: Line 14:


== Define the Stabilization Algorithm ==
== 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.
<syntaxhighlight lang=c++>
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;
}
</syntaxhighlight>
=== Define the Reset Method ===
This method only needs to specify how to dynamically cast the parameters shared pointer into the stabilizer algorithm class.
<syntaxhighlight lang=c++>
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;
  }
}
</syntaxhighlight>


== Define the Stabilization Parameters ==  
== Define the Stabilization Parameters ==  
29

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.