Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:03+00:00 2026-05-26T08:31:03+00:00

The cvInvert() method takes a flag CV_LU that does the LU factorisation to invert

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:31:04+00:00Added an answer on May 26, 2026 at 8:31 am

    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:

    #ifndef __OPENCV_CORE_EIGEN_HPP__
    #define __OPENCV_CORE_EIGEN_HPP__
    
    #ifdef __cplusplus
    
    #include "opencv/cxcore.h"
    #include <eigen3/Eigen/Dense>
    
    namespace cv
    {
    
    template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
    void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
    {
        if( !(src.Flags & Eigen::RowMajorBit) )
        {
            Mat _src(src.cols(), src.rows(), DataType<_Tp>::type,
                  (void*)src.data(), src.stride()*sizeof(_Tp));
            transpose(_src, dst);
        }
        else
        {
            Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
                     (void*)src.data(), src.stride()*sizeof(_Tp));
            _src.copyTo(dst);
        }
    }
    
    template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
    void cv2eigen( const Mat& src,
                   Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
    {
        CV_DbgAssert(src.rows == _rows && src.cols == _cols);
        if( !(dst.Flags & Eigen::RowMajorBit) )
        {
            Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            if( src.type() == _dst.type() )
                transpose(src, _dst);
            else if( src.cols == src.rows )
            {
                src.convertTo(_dst, _dst.type());
                transpose(_dst, _dst);
            }
            else
                Mat(src.t()).convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
        else
        {
            Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            src.convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
    }
    
    template<typename _Tp>
    void cv2eigen( const Mat& src,
                   Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
    {
        dst.resize(src.rows, src.cols);
        if( !(dst.Flags & Eigen::RowMajorBit) )
        {
            Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            if( src.type() == _dst.type() )
                transpose(src, _dst);
            else if( src.cols == src.rows )
            {
                src.convertTo(_dst, _dst.type());
                transpose(_dst, _dst);
            }
            else
                Mat(src.t()).convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
        else
        {
            Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            src.convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
    }
    
    
    template<typename _Tp>
    void cv2eigen( const Mat& src,
                   Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
    {
        CV_Assert(src.cols == 1);
        dst.resize(src.rows);
    
        if( !(dst.Flags & Eigen::RowMajorBit) )
        {
            Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            if( src.type() == _dst.type() )
                transpose(src, _dst);
            else
                Mat(src.t()).convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
        else
        {
            Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            src.convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
    }
    
    
    template<typename _Tp>
    void cv2eigen( const Mat& src,
                   Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
    {
        CV_Assert(src.rows == 1);
        dst.resize(src.cols);
        if( !(dst.Flags & Eigen::RowMajorBit) )
        {
            Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            if( src.type() == _dst.type() )
                transpose(src, _dst);
            else
                Mat(src.t()).convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
        else
        {
            Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
                     dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
            src.convertTo(_dst, _dst.type());
            CV_DbgAssert(_dst.data == (uchar*)dst.data());
        }
    }
    
    }
    
    #endif
    
    #endif
    

    Hopefully that is helpful to you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a CvSeq of Cvpoint and it is created by cvApproxPoly. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.