前言
jsfeat作为一个js库,支持诸多计算机视觉中要用到的功能,尤其是在SLAM方面。因为最近在搞WebAR的相关项目,所以频繁的用到。
虽然 ,jsfeat的作者无疑是位大佬,但是其提供的Matrix Math提供的接口存在一个很奇葩的问题。
正文
在Matrix Math中的矩阵乘法函数jsfeat.matmath.multiply中,在nxn与nxn的矩阵相乘时一切正常,但是如果你要想实现nxm乘mxh矩阵时,你需要让nxm乘一个hxm的矩阵。就像下面这样:
U=new jsfeat.matrix_t(3,3,jsfeat.F32C1_t);
tp=new jsfeat.matrix_t(1,3,jsfeat.F32C1_t);
Utp=new jsfeat.matrix_t(3,3,jsfeat.F32C1_t);
jsfeat.matmath.multiply(Utp, U ,tp);
如果不这样做,乘出来的结果会是NaN。
另外,jsfet还有个问题,就是其svd_decompose函数。其文档中是这样说的:
This routine decomposes an rows x cols matrix A, into a product of the three matrices U, W, and V’, i.e. A = UWV’, where U is an rows x rows matrix whose columns are orthogonal, W is a 1 x cols matrix, and V is an cols x cols orthogonal matrix.
// U - the left orthogonal matrix
// W - vector of singular values
// V - the right orthogonal matrix
// options - jsfeat.SVD_U_T and/or jsfeat.SVD_V_T to return transposed U and/or V
jsfeat.linalg.svd_decompose(A:matrix_t, W:matrix_t, U:matrix_t, V:matrix_t, options);
参见https://inspirit.github.io/jsfeat/#linalg
然而,这个函数最后求出来的V(也就是第四个参数),其实是V’。我直接抓狂。