You need to enable JavaScript to run this app.Perspective Projection - GammaCV
GammaCV Logo
DocsExamplesGitHub

Perspective Projection

Description

Projects the input image to the output canvas using transformation matrix. Could be used to fix Perspective.

Params
tSrcTensorThe source image.
tTransformTensorAffine transformation matrix (3x3) but in in shape [3, 1, 4], where each 4th element is unused.
Such shape is used for more effective access to matrix values in GPU.
shapeArray.<number>Output shape
dType?stringOutput data type, default to input
Example
// Manual affine transformation matrix
 const tMatrix = new gm.Tensor('float32', [3, 1, 4], new Float32Array([
   -1, 0.5, 0, 0,
   0, 1, 0, 0,
   0, 0, 1, 0,
 ]));
 gm.perspectiveProjection(tSrc, tMatrix, [1000, 1000, 4]);
// 4 point perspective transform
 const tMatrix = new gm.Tensor('float32', [3, 1, 4]);
 gm.generateTransformMatrix(
   new gm.Rect([10, 10, 100, 15, 100, 150, 15, 150]), // Rect on original image to be projected
   [100, 100], // Output dimensions
   tMatrix, // Tensor to be filled
 );
 gm.perspectiveProjection(tSrc, tMatrix, [100, 100, 4]);