Chapter 7. Functors in OpenCV

Objects That “Do Stuff”

As the OpenCV library has evolved, it has become increasingly common to introduce new objects that encapsulate functionality that is too complicated to be associated with a single function and which, if implemented as a set of functions, would cause the overall function space of the library to become too cluttered.1

As a result, new functionality is often represented by an associated new object type, which can be thought of as a “machine” that does whatever this functionality is. Most of these machines have an overloaded operator(), which officially makes them function objects or functors. If you are not familiar with this programming idiom, the important idea is that unlike “normal” functions, function objects are created and can maintain state information inside them. As a result, they can be set up with whatever data or configuration they need, and they are “asked” to perform services through either common member functions, or by being called as functions themselves (usually via the overloaded operator()2).

Principal Component Analysis (cv::PCA)

Principal component analysis, illustrated in Figure 7-1, is the process of analyzing  a distribution in many dimensions and extracting from that distribution the particular subset of dimensions that carry the most information. The dimensions computed by PCA are not necessarily the basis dimensions in which the distribution was originally specified. Indeed, one of the most important ...

Get Learning OpenCV 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.