Skip to content
cascade256 edited this page Oct 22, 2015 · 8 revisions

Matrix

The matrix is the most useful base data structure in OpenCV. Things like images are just matrices of pixels.

Creating:

Matrix(rows, cols)

Creates a matrix with the specified number of rows and columns.

rows: number, cols: number

output: Matrix


Matrix.Eye(rows, cols)

Creates an identity matrix.

rows: number, cols: number

output: Matrix


Example:

var image = new Matrix(256, 256);
var identity = new Matrix.Eye(512,512);

##Accessing Data get(row, col)

Gets the number at that point in the matrix.

row: number, col: number

output: number


row(i)

Returns the array of numbers for row i.

i: number

output: array


col(i)

Returns the array of numbers for column i.

i: number

output: array


toBuffer()

Returns the matrix as a NodeJS buffer.

output: Buffer


Example:

var pixel = image.get(0,0);
var row = image.row(0);
var col = image.col(0);
var buff = image.toBuffer();
Clone this wiki locally