Random forests
Combine decisions from trees that split feature space into regions.
Each tree uses feature tests to route a sample to a prediction.
The same query enters every tree; their thresholds and selected features differ.
The highlighted path leads to one leaf prediction in each illustrative tree.
Two illustrative trees vote mint and one votes orange. Classification aggregates votes; regression aggregates numeric responses.
Aggregate leaf predictions across the ensemble.
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 random forest on rectangle and border colour samples, then classify every pixel.
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 or regress from engineered visual features without requiring a linear boundary.
How it works
- 01Train trees using feature tests at internal nodes.
- 02Follow the query’s feature values through each tree.
- 03Aggregate leaf predictions across the ensemble.
feature tests → tree leaves → ensemble prediction
What to tune
Depth, minimum sample count and ensemble size control capacity and cost. Variable types and missing-data conventions must match training.
Where it breaks down
Random forests, individual trees and boosting use different training strategies. None removes the need for representative held-out validation.
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.
Support vector machines
Learn a decision boundary that balances class separation against margin violations.
K-nearest-neighbour classification
Predict a sample from the labels or values of nearby training examples.
Principal component analysis
Find orthogonal directions that explain the greatest variance in centred data.