perspective-n-point
v1.0.0
Published
Perspective N Point utilities for Node.js
Downloads
9
Maintainers
Readme
perspective-n-point
Node.js utilities for perspective-n-point
Install
npm install perspective-n-point
solvePnP simple usage
const {solvePnP, getCamera, project} = require('perspective-n-point');
const camera = getCamera({resolution: [1920, 1080]})
const out = solvePnP({
camera,
worldCoordinates: [ // a cube
[0,0,0],
[1,0,0],
[0,1,0],
[0,0,1],
[1,1,0],
[1,0,1],
[0,1,1],
[1,1,1],
],
imageCoordinates: [ // a cube drawing
[0,1],
[0,4],
[1,0],
[3,1],
[1,3],
[3,4],
[4,0],
[4,3]
]
})
const projected = project({
worldCoordinates: [
[0,0,0]
],
camera,
extrinsic
})
console.log(projected)
Warning, there are often multiple different solution for the same solvePnP
, please check init
option to help this algorithm
solvePnP advanced usage
const {solvePnP} = require('perspective-n-point');
const camera = getCamera({
resolution: [1920, 1080],
horizontalFov: 5 / 180 * Math.PI, // default is 5 / 180 * Math.PI
distCoeffs: [0,0,0,0] // default is [0,0,0,0]
})
const extrinsic = getExtrinsic({
camera,
cameraPosition : [-10, -10, 5],
target3dPoint: [0, 0, 0],
target2dPoint: [960, 540]
})
const out = solvePnP({
camera,
worldCoordinates: [ // a cube
[0,0,0],
[1,0,0],
[0,1,0],
[0,0,1],
[1,1,0],
[1,0,1],
[0,1,1],
[1,1,1],
],
imageCoordinates: [ // a cube drawing
[0,1],
[0,4],
[1,0],
[3,1],
[1,3],
[3,4],
[4,0],
[4,3]
],
extrinsincGuess: extrinsic
})
console.log(out)