Skip to content

Random forests

Algorithm atlasMachine learning

Combine decisions from trees that split feature space into regions.

Try it on your image ↓

VISUAL WALKTHROUGHMachine learning
REFERENCE INPUTSeveral decision trees

Each tree uses feature tests to route a sample to a prediction.

RESULTAggregate the predictions

Two illustrative trees vote mint and one votes orange. Classification aggregates votes; regression aggregates numeric responses.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

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.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Classify or regress from engineered visual features without requiring a linear boundary.

How it works

  1. 01Train trees using feature tests at internal nodes.
  2. 02Follow the query’s feature values through each tree.
  3. 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.