Skip to Content
Mastering OpenCV 4 with Python
book

Mastering OpenCV 4 with Python

by Alberto Fernández Villán
March 2019
Intermediate to advanced
532 pages
13h 2m
English
Packt Publishing
Content preview from Mastering OpenCV 4 with Python

Understanding SVM

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,  ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

OpenCV 4 with Python Blueprints - Second Edition

OpenCV 4 with Python Blueprints - Second Edition

Dr. Menua Gevorgyan, Michael Beyeler (USD), Arsen Mamikonyan, Michael Beyeler
Learning OpenCV 3

Learning OpenCV 3

Adrian Kaehler, Gary Bradski
Machine Learning for OpenCV 4 - Second Edition

Machine Learning for OpenCV 4 - Second Edition

Aditya Sharma, Michael Beyeler (USD), Vishwesh Ravi Shrimali, Michael Beyeler

Publisher Resources

ISBN: 9781789344912Supplemental Content