如何使用OpenCV进行LU分解?
cvInvert() 方法采用标志 CV_LU 进行 LU 分解以反转输入矩阵。但是有什么方法可以获得计算过程中形成的 L 和 U 矩阵吗? 为 LU 分解编写一个新函数似乎毫无意义,因为 OpenCV 已经为其优化了代码。
The cvInvert() method takes a flag CV_LU that does the LU factorisation to invert an input matrix. However is there any way to obtain the L and U matrices that are formed during this computation?
Is seems pointless to write a new function for LU-decomposition is OpenCV already has optimized code for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,OpenCV 似乎没有为您提供访问 L 和 U 矩阵的方法。 这里是该函数的实现方式。而且,出于性能原因,LU 分解似乎是就地完成的。因此,您可能必须自己做。
编辑:看起来,在查看了 Matlab 和 Eigen 如何进行 LU 分解之后,您实际上可以在 cvInvert 调用后检索它们。 L 矩阵是结果加上单位矩阵的严格下三角矩阵,U 矩阵是上三角矩阵。
编辑: Eigen 实际上与 OpenCV 集成得相当好。而且,他们似乎在此处实现了 LU 分解类。 Eigen 已经是 OpenCV 的依赖项,如果您自己构建它,您应该可以使用它(它完全在头文件中实现,因此非常易于使用)。还有一个 OpenCV 标头实现 Eigen 矩阵和 OpenCV 矩阵之间的转换@
#include
。然而,至少在我的 SVN 构建中,这个标头无法正常工作,所以我制作了自己的标头:
希望这对您有帮助!
Unfortunately, it doesn't look like OpenCV gives you a way to access the L and U matrices. Here is how the function is implemented. And, it looks like for performance reasons LU-decomposition is done in-place. So, you will probably have to do it on your own.
EDIT: It appears that after looking at both how Matlab and Eigen do LU-decomposition you can actually retrieve them after the cvInvert call. The L matrix is the strictly lower-triangle matrix of the result plus the Identity matrix, and the U matrix is the upper triangle matrix.
EDIT: Eigen actually integrates fairly well with OpenCV. And, it appears they have an LU decomposition class implemented here. Eigen is already a dependency for OpenCV if you built it yourself, you should have it available to use (it's completely implemented in header files, so that makes it really easy to use). There is also an OpenCV header implementing the conversion between Eigen matrices and OpenCV matrices @
#include <opencv2/core/eigen.hpp>
.However, at least on my SVN build, this header didn't work right, so I made my own:
Hopefully that is helpful to you!
可以使用OpenCV提供的函数
Cholesky()
(使用2.4.6),参见modules\stitching\src\autocalib.cpp
源代码。但它需要进行一些缩放才能获得与 Matlab 相当的结果:It is possible to use the function
Cholesky()
provided by OpenCV (using 2.4.6), see source code ofmodules\stitching\src\autocalib.cpp
. But it needs some scaling to get a comparable result with Matlab: