OpenCV provides a class, cv2.ml_ANN_MLP, that implements an ANN as a multi-layer perceptron (MLP). This is exactly the kind of model we described earlier, in the Understanding neurons and perceptrons section.
To create an instance of cv2.ml_ANN_MLP, and to format data for this ANN's training and use, we rely on functionality in OpenCV's machine learning module, cv2.ml. As you may recall, this is the same module that we used for SVM-related functionality in Chapter 7, Building Custom Object Detectors. Moreover, cv2.ml_ANN_MLP and cv2.ml_SVM share a common base class called cv2.ml_StatModel. Therefore, you will find that OpenCV provides similar APIs for ANNs and SVMs.
Let's examine a dummy example as a gentle introduction to ANNs. This example will use completely meaningless data, but it will show us the basic API for training and...