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

no edit summary
No edit summary
No edit summary
Line 25: Line 25:
* softgyro: This is the input data containing a vector of orientation values (Quaternions) along with their corresponding timestamps. It is used by the interpolation algorithm.
* softgyro: This is the input data containing a vector of orientation values (Quaternions) along with their corresponding timestamps. It is used by the interpolation algorithm.
* interpolated: This contains a vector of interpolated orientation values with their corresponding interpolation timestamps.
* interpolated: This contains a vector of interpolated orientation values with their corresponding interpolation timestamps.
The user must take into account that the method uses the IInterpolator start time member to perform the interpolation.
The user must take into account that the method uses the IInterpolator start time member to perform the interpolation and that the time must be set on microseconds.


<syntaxhighlight lang=c++>
<syntaxhighlight lang=c++>
Line 51: Line 51:
}
}
</syntaxhighlight>
</syntaxhighlight>
=== Add the Interpolator Algorithm to IInterpolator ===
In order to add the new interpolator algorithm class to the interpolator interface follow these steps:
* Add the constructor method to the interpolator algorithm header file.
* Extend the Interpolator Algorithms enumeration with the new interpolation algorithm.
* Add the interpolator algorithm to the IInterpolator Build method.
==== Add the constructor method ====
The constructor method receives the interpolator settings parameter. These settings include the interpolation interval, which is a constant time (in microseconds) that updates the initial time after each interpolation.
<syntaxhighlight lang=c++>
class ExampleInterpolator : public IInterpolator {
public:
  explicit ExampleInterpolator(
      const std::shared_ptr<InterpolatorSettings> settings);
  /* Rest of class */
}
</syntaxhighlight>
==== Extend the Interpolator Algorithms enumeration ====
To enable the IInterpolator interface to create an instance of the new sensor, it must be added to the InterpolatorAlgorithms enumeration.
<syntaxhighlight lang=c++>
enum class InterpolatorAlgorithms {
  kSlerp = 0,
  /* Add new interpolator algorithm */
  kExampleInterpolator
};
</syntaxhighlight>
==== Add Interpolation Algorithm to IInterpolator Build method ====
Finally, the new interpolator case must be added to the IInterpolator build method to allow the interface to instantiate the interpolator algorithm.
<syntaxhighlight lang=c++>
std::shared_ptr<IInterpolator> IInterpolator::Build(
    const InterpolatorAlgorithms impl,
    const std::shared_ptr<InterpolatorSettings> settings) {
  switch (impl) {
    case InterpolatorAlgorithms::kSlerp:
      return std::make_shared<SlerpInterpolator>(settings);
    /* Add new interpolation algorithm case */
    case InterpolatorAlgorithms::kExampleInterpolator:
      return std::make_shared<ExampleInterpolator>(settings);
    default:
      return nullptr;
  }
}
</syntaxhighlight>


<noinclude>
<noinclude>
{{RidgeRun Video Stabilization Library/Foot|API Reference/Adding New Sensors|API Reference/Adding Stabilization Algorithm}}
{{RidgeRun Video Stabilization Library/Foot|API Reference/Adding New Sensors|API Reference/Adding Stabilization Algorithm}}
</noinclude>
</noinclude>
102

edits