simple-homography
Version:
Calculates a homography matrix using exact point correspondences
33 lines (32 loc) • 1.19 kB
JavaScript
;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("../index");
var Math = __importStar(require("mathjs"));
function test() {
var correspondances = [
[[0, 0], [1, 1]],
[[1, 0], [4, 0.2]],
[[1, 1], [2, 2]],
[[0, 1], [1, 2]],
];
var c = correspondances;
var h = index_1.calculateHomography(c[0][0], c[0][1], c[1][0], c[1][1], c[2][0], c[2][1], c[3][0], c[3][1]);
console.log(h);
correspondances.forEach(function (corr) {
var test = Math.multiply(h, [corr[0][0], corr[0][1], 1]).toArray();
test[0] = test[0] / test[2];
test[1] = test[1] / test[2];
test[2] = 1;
if (test[0] != corr[1][0] && test[1] != corr[1][1])
throw new Error("It didn't work! - " + corr[0] + " -> " + test + " instead of " + corr[1]);
});
console.log("it worked!");
}
test();