Anyone knows how to perform fast matrix multiplication using opencv? Possible to include some special linear algebra Library? It is much slower than MATLAB.
You can do it the other way around: use a matrix algebra library and create wrapper cv::Mat objects when you need to use OpenCV functionality. That way you can use fast linear algebra (e.g. provided by Eigen, or Armadillo, or any other library) and still maintain the possibility to use OpenCV's functions.
The other way around is also possible, and explained here:
Or possibly look at what libraries the Numerical Algorithms Group (UK) (www.nag.co.uk) have to offer. They are sometimes willing to share libraries with academics and are very approachable. I can give you one of their contacts if you wish.
Did you compile with optimizations? As Eigen is a header-only library, how you compile your code will influence its performance (unlike OpenCV, for which the code has been compiled into a library). Be sure to check out the Eigen FAQ entry on optimization (linked) and vectorization below the former. Basically, enable optimzations and define NDEBUG, because Eigen uses this to internally switch off some runtime debug checks and asserts.
If you could put some test code up on e.g. pastebin or attach it as a file here I might be able to help debug your performance issue. Although I have not compared Eigen to OpenCV matrix math, I have compared Eigen to other matrix libraries and it is competitive to say the least.
I use mex which calls cl compiler. With OPTIMFLAGS = "/Ox" , "#define NDEBUG", Eigen nows runs about 1/2 of opencv run time, however, this is still 4 times slower than matlab.
Well, Matlab uses Intel MKL which is bound to be faster. Apart from enabling SSE2 (if not already on 64-bit) and OpenMP (see http://eigen.tuxfamily.org/dox/TopicMultiThreading.html), I'm not sure I can do much more.
I bet you could still improve on the operation itself if you don't store temporary results. Unfortunately, you're showing too little code to help with that.
If you can show a self-contained compilable example code of the full operation you are doing, I might be able to squeeze out a bit more performance.
As an alternative which may be faster, you can use Armadillo+OpenBLAS. See for a (dated) comparison on a single system for some operations these links:http://nghiaho.com/?p=936
http://nghiaho.com/?p=954
http://nghiaho.com/?p=1726
The last one seems to show Eigen at ~60% of OpenCV, and OpenBLAS at ~40% of OpenCV. Of couse it all depends what exactly you're doing.
This multiplication problem A = B*C, B is about 100*100 and C is 100*1000,000
that is quite big, especially if then you use to do the inverse
Simply, just use cv::Mat to store a matrix and multiple
Furthermore, later if you use inverse, I think you should convert to Eigen and then using some specific technicals as QR, Cholesky decomposition, or Rotation matrix technical.