OpenCV provides SVD decomposition, but I cannot find general QR decomposition in its library. Is there any alternative to achieve this?
3 Answers
This is an old question, but for the sake of completeness (and because google took me here), here's the answer using OpenCV --
OpenCV has the solve() function, which can be invoked with a flag specifying the matrix inversion method to be used. Use the flag DECOMP_QR
to perform a QR decomposition.

- 4,123
- 3
- 24
- 23
-
1Well you can't get the Q and R out of `solve()`, so it doesn't work in that case. If you only want to solve a linear system / least squares problem, of course then `solve()` will help you. – Ela782 Jul 26 '15 at 16:39
As someone mentioned 3 years ago, this is an old question (lolz)
But QR decomposition is very much possible in OpenCV. In 3.2 it can be done using cv::decomposeProjectionMatrix, as documented here: http://docs.opencv.org/trunk/d9/d0c/group__calib3d.html#gaaae5a7899faa1ffdf268cd9088940248
Note: I recognize I'm really answering for a specific case of QR decomposition (that on a projection matrix), but that doc page says that this function is based on RQDecomp3x3, which could be used for the generic RQ decomposition.
I'm answering this now as all of the answers that pop up when googling this are wrong in saying that it's not possible.

- 11
- 2
-
Only if by "generic" you mean 3x3 matrices, I'd posit the answer is still "you can't", unless you want to roll your own. – nbubis Jan 16 '21 at 18:35
You can use a matrix library like Newmat11 http://www.robertnz.net/nm11.htm#qr

- 7,815
- 1
- 29
- 34