The OpenCV base class for algorithms
OpenCV offers many algorithms that perform various computer vision tasks. To facilitate their use, most of these algorithms have been made a subclass of a generic base class called cv::Algorithm. This one implements some of the concepts dictated by the strategy design pattern. First, all of these algorithms are created dynamically, using a specialized static method that makes sure that the algorithm is always created in a valid state (that is, with valid default values for the unspecified parameters). Let's consider, for example, one of these subclasses, cv::ORB; this one is an interest point operator that will be discussed in the Detecting FAST features at multiple scales recipe, in Chapter 8, Detecting Interest Points. Here, we simply use it as an illustrative example of an algorithm.
An instance of this algorithm is therefore created as follows:
cv::Ptr<cv::ORB> ptrORB = cv::ORB::create(); // default state
Once it's created, the algorithm can be used. For example, the generic methods read and write can be used to load or store the state of the algorithm. The algorithms also have specialized methods (in the case of ORB, for example, the methods detect and compute can be used to trigger its main computational units). Algorithms also have specialized setter methods that allow for the specifying of their internal parameters. Note that we could have declared the pointer as cv::Ptr<cv::Algorithm>, but in this case, we would not be able to use its specialized methods.