3

역함수와 많은 함수로 이미지를 처리하고 싶습니다. 코드를 빠르게 실행하려면 3 가지 변환 방법 중 빠른 방법을 제안 할 수 있습니까? 최적의 피벗 요소행렬의 역행렬에서 가장 빠른 방법

double cvInvert(const CvArr* src, CvArr* dst, int method=CV_LU) 
  • CV_LU 가우스 제거는 양 대칭 정의 행렬
  • CV_SVD 특이 값 분해 (SVD)에있어서
  • CV_SVD_SYM의 SVD 방법을 선택.

답변

7

는 OpenCV2.x에서, 행렬의 역행렬을 계산 Mat::inv(int method) 불리는 새로운 인터페이스가있다. reference을 참조하십시오.

C++ : MatExpr 매트 :: INV (INT 방법 = DECOMP_LU) CONST

파라미터 : 방법 -

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. 

제가 방법의 각각 시험했다, 그것은 도시 DECOMP_CHOLESKY가 테스트 케이스에서 가장 빠르며 LU는 유사한 결과를 제공합니다.

LU : 0.000423759

DECOMP_SVD : 0.0583525

DECOMP_CHOLESKY : 9.3453e-05

여기
#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <iostream> 

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 << "LU:" << t2 << std::endl; 

    t1 = (double)cv::getTickCount(); 
    cv::Mat m5 = img.inv(cv::DECOMP_SVD); 
    t2 = (cv::getTickCount()-t1)/freq; 
    std::cout << "DECOMP_SVD:" << t2 << std::endl; 

    t1 = (double)cv::getTickCount(); 
    cv::Mat m6 = img.inv(cv::DECOMP_CHOLESKY); 
    t2 = (cv::getTickCount()-t1)/freq; 
    std::cout << "DECOMP_CHOLESKY:" << t2 << std::endl; 

    cv::waitKey(0); 
} 

가 실행 resutls이고