Support vector machines
Learn a decision boundary that balances class separation against margin violations.
A linear decision boundary separates these two illustrative classes.
Different separating lines can fit the training labels with different margins.
The dashed lines illustrate the margin on either side of a linear separator.
The side of the boundary determines the predicted class in this linear example. Kernel models can produce nonlinear boundaries.
Optimize the margin objective and predict labels or scores for new samples.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Train a colour classifier: samples inside the rectangle are foreground, image-border samples are background. Apply it to every pixel. This demonstrates supervised training, not semantic segmentation.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Classify image descriptors or build small supervised vision models.
How it works
- 01Arrange labelled feature vectors consistently.
- 02Select a linear or kernel-based decision model.
- 03Optimize the margin objective and predict labels or scores for new samples.
decision boundary with a margin around supported samples
What to tune
C controls violation cost; kernel parameters set similarity; choose the correct SVM type for classification, regression or one-class learning.
Where it breaks down
Training accuracy does not estimate generalization. Scaling, validation splits and hyperparameter selection matter.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
K-means clustering
Partition feature vectors around a fixed number of learned centres.
K-nearest-neighbour classification
Predict a sample from the labels or values of nearby training examples.
Random forests
Combine decisions from trees that split feature space into regions.
Principal component analysis
Find orthogonal directions that explain the greatest variance in centred data.