Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In OpenCV2.x, there's a new interface called <code>Mat::inv(int method)</code> to compute the inverse of a matrix. See <a href="http://opencv.itseez.com/modules/core/doc/basic_structures.html">reference</a>.</p> <blockquote> <p>C++: MatExpr Mat::inv(int method=DECOMP_LU) const</p> <p>Parameters: method –</p> <pre><code> Matrix inversion method. Possible values are the following: DECOMP_LU is the LU decomposition. The matrix must be non-singular. DECOMP_CHOLESKY is the Cholesky LL^T decomposition for symmetrical positively defined matrices only. This type is about twice faster than LU on big matrices. DECOMP_SVD is the SVD decomposition. If the matrix is singular or even non-square, the pseudo inversion is computed. </code></pre> </blockquote> <p>I made a test with each of the method, it shows that DECOMP_CHOLESKY is the fastest for the test case, and LU gives the similar result.</p> <pre><code>#include &lt;opencv2/core/core.hpp&gt; #include &lt;opencv2/highgui/highgui.hpp&gt; #include &lt;opencv2/imgproc/imgproc.hpp&gt; #include &lt;iostream&gt; int main(void) { cv::Mat img1 = cv::imread("2.png"); cv::Mat img2, img3, img; cv::cvtColor(img1, img2, CV_BGR2GRAY); img2.convertTo(img3, CV_32FC1); cv::resize(img3, img, cv::Size(200,200)); double freq = cv::getTickFrequency(); double t1 = 0.0, t2 = 0.0; t1 = (double)cv::getTickCount(); cv::Mat m4 = img.inv(cv::DECOMP_LU); t2 = (cv::getTickCount()-t1)/freq; std::cout &lt;&lt; "LU:" &lt;&lt; t2 &lt;&lt; std::endl; t1 = (double)cv::getTickCount(); cv::Mat m5 = img.inv(cv::DECOMP_SVD); t2 = (cv::getTickCount()-t1)/freq; std::cout &lt;&lt; "DECOMP_SVD:" &lt;&lt; t2 &lt;&lt; std::endl; t1 = (double)cv::getTickCount(); cv::Mat m6 = img.inv(cv::DECOMP_CHOLESKY); t2 = (cv::getTickCount()-t1)/freq; std::cout &lt;&lt; "DECOMP_CHOLESKY:" &lt;&lt; t2 &lt;&lt; std::endl; cv::waitKey(0); } </code></pre> <p>Here is the running resutls:</p> <blockquote> <p>LU:0.000423759</p> <p>DECOMP_SVD:0.0583525</p> <p>DECOMP_CHOLESKY:9.3453e-05</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload