March 2019
Intermediate to advanced
532 pages
13h 2m
English
The svm_introduction.py script carries out a simple example in order to see how to use SVMs in OpenCV. First of all, we create the training data and the labels:
# Set up training data:labels = np.array([1, 1, -1, -1, -1])data = np.matrix([[500, 10], [550, 100], [300, 10], [500, 300], [10, 600]], dtype=np.float32)
As you can see, five points are created. The first two points are assigned the 1 class, while the other three points are assigned the -1 class. The next step is to initialize the SVM model using the svm_init() function:
# Initialize the SVM model:svm_model = svm_init(C=12.5, gamma=0.50625)
The svm_init() function creates an empty model and assigns the main parameters and returns the model:
def svm_init(C=12.5, ...