calcBackProject
import { calcBackProject } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Calculates the back projection of a histogram.
The function cv::calcBackProject calculates the back project of the histogram. That is, similarly to #calcHist , at each location (x, y) the function collects the values from the selected channels in the input images and finds the corresponding histogram bin. But instead of incrementing it, the function reads the bin value, scales it by scale , and stores in backProject(x,y) . In terms of statistics, the function computes probability of each element value in respect with the empirical probability distribution represented by the histogram. See how, for example, you can find and track a bright-colored object in a scene:
Before tracking, show the object to the camera so that it covers almost the whole frame. Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant colors in the object.
When tracking, calculate a back projection of a hue plane of each input video frame using that pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels.
Find connected components in the resulting picture and choose, for example, the largest component.
This is an approximate algorithm of the CamShift color object tracker.
See: calcHist, compareHist
calcBackProject(images: MatVector, channels: IntVector, hist: Mat, dst: Mat, ranges: FloatVector, scale: number): void;imagesSource arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same size. Each of them can have an arbitrary number of channels.
channelsThe list of channels used to compute the back projection. The number of channels must match the histogram dimensionality. The first array channels are numerated from 0 to images[0].channels()-1 , the second array channels are counted from images[0].channels() to images[0].channels() + images[1].channels()-1, and so on.
histInput histogram that can be dense or sparse.
dstOutput destination, filled by the native operation. dst argument (Mat).
rangesArray of arrays of the histogram bin boundaries in each dimension. See #calcHist .
scaleOptional scale factor for the output back projection.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.