我想从perspectiveTransform
的OpenCV重新创建JavaScript
函数。我需要这样做的原因是因为an issue encountered here。我发现此功能here和C++
的实际getPerspectiveTransform
实现方式,似乎here的工作方式完全不同。它们似乎都包含一堆我不太了解的指针,JavaScript
中没有类似的指针,因此我不确定如何编写类似的东西。
我认为这只是矩阵数学的一种,肯定有一种简单的数学方法。如果有人对这样的矩阵/转换有所了解,我将不胜感激一些建议/伪代码/代码。
示例数据是我在C++
上运行有效版本所获得的
输入1(3x3)矩阵
[0.4709243769447963,-0.1089570231317744,289.4386175367417;
-0.05915378097999304,0.3816064687798928,503.5397702666958;
-9.054861751225341e-05,-0.0001637295648326533,1]
输入2(2x4)矩阵
[0,0] [1000,0] [1000,740] [0,740]
所需的输出
[289.439,503.54] [836.068,488.631] [862.289,921.962] [237.598, 894.279]
功能的详细信息
我用JavaScript调用的位置
var H = new cv.Mat();
H = cv.findHomographyEasy(obj, scene, cv.FM_RANSAC);
var obj_corners = new cv.Point2fVector();
obj_corners[0] = new cv.Point(0,0);
obj_corners[1] = new cv.Point(img1Raw.cols,0);
obj_corners[2] = new cv.Point(img1Raw.cols, img1Raw.rows);
obj_corners[3] = new cv.Point(0, img1Raw.rows);
var scene_corners = new cv.Point2fVector();
scene_corners[0] = new cv.Point(0,0);
scene_corners[1] = new cv.Point(0,0);
scene_corners[2] = new cv.Point(0,0);
scene_corners[3] = new cv.Point(0,0);
// NEED TO REMAKE THIS FUNCTION WHICH DOESN'T WORK IN OPENCV.js
cv.perspectiveTransformEasy(obj_corners, scene_corners, H);