Skip to content

SVD performance issue #7917

@crep4ever

Description

@crep4ever
System information (version)
  • OpenCV => 3.1
  • Operating System / Platform => Ubuntu 16.10 64 Bit
  • Compiler => gcc 6.2
Detailed description

On some particular dataset, the method cv::SVD::compute() can take hours where the equivalent eigen method takes only seconds. The enclosed program + data can reproduce the problem.

Note that the performance does not seem to be related to the data volume as I can't reproduce
the issue on a (500 000 x 6) matrix initialized with random values.

Steps to reproduce

Example to run OpenCV and Eigen SVD decompositions on same data.

#include <iostream>

#include "eigen3/Eigen/Core"
#include "eigen3/Eigen/SVD"

#include <opencv2/opencv.hpp>
#include <opencv2/core/eigen.hpp>

cv::Mat load(const std::string & p_filePath)
{
  cv::Mat mat;
  cv::FileStorage fs;
  if (!fs.open(p_filePath, cv::FileStorage::READ))
    {
      std::cout << "Can't open matrix file" << std::endl;
      return cv::Mat();
    }
  fs["matrix"] >> mat;
  fs.release();
  return mat;
}

int main (void)
{
  cv::Mat src = load("svd_src.xml"); // input (rows: 6 ; cols: 515 808 ; type: CV_64FC1)
  cv::Mat u; // output
  

  // Eigen implementation
  Eigen::MatrixXd m;
  cv::cv2eigen(src, m);

  std::cout << "[start] Eigen SVD decomposition" << std::endl;
  Eigen::JacobiSVD<Eigen::MatrixXd> svd(m, Eigen::ComputeThinU);
  std::cout << "[end] Eigen SVD decomposition" << std::endl;
    
  cv::eigen2cv(svd.matrixU(), u);


  // OpenCV implementation
  cv::Mat w, vt;
  std::cout << "[start] OpenCV SVD decomposition" << std::endl;
  cv::SVD::compute(src, w, u, vt);
  std::cout << "[end] OpenCV SVD decomposition" << std::endl;

  return 0;
}

svd.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions