Skip to content

sortIdx

Core and matricesfunctionOpenCV 5.0.0
import { sortIdx } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSsrc, dst, flags
FUNCTIONsortIdx
RETURN TYPEvoid
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Sorts each row or each column of a matrix.

The function cv::sortIdx sorts each matrix row or each matrix column in the ascending or descending order. So you should pass two operation flags to get desired behaviour. Instead of reordering the elements themselves, it stores the indices of sorted elements in the output array. For example:

    Mat A = Mat::eye(3,3,CV_32F), B;
    sortIdx(A, B, SORT_EVERY_ROW + SORT_ASCENDING);
    // B will probably contain
    // (because of equal elements in A some permutations are possible):
    // [[1, 2, 0], [0, 2, 1], [0, 1, 2]]

See: sort, randShuffle

sortIdx(src: Mat, dst: Mat, flags: number): void;
src

input single-channel array.

dst

Output destination, filled by the native operation. output integer array of the same size as src.

flags

operation flags that could be a combination of cv::SortFlags

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.