July 2017
Intermediate to advanced
382 pages
9h 13m
English
We already know how to build an SVM in OpenCV, so there's nothing much to see here. Planning ahead, we wrap the training procedure into a function, so that it's easier to repeat the procedure in the future:
In [15]: def train_svm(X_train, y_train):... svm = cv2.ml.SVM_create()... svm.train(X_train, cv2.ml.ROW_SAMPLE, y_train)... return svm
The same can be done for the scoring function. Here we pass a feature matrix X and a label vector y, but we do not specify whether we're talking about the training or the test set. In fact, from the viewpoint of the function, it doesn't matter what set the data samples belong to, as long as they have the right format:
In [16]: def score_svm(svm, X, y):... from ...
Read now
Unlock full access