Training a basic ANN in OpenCV

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 ...

Get Learning OpenCV 4 Computer Vision with Python 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.