10

I've been using OpenCV for quite a while now and was wondering if switching to MATLAB would be a good idea. As far as I know they are both the same with MATLAB built over underlying OpenCV libraries. OpenCV is open source which is a definite advantage and supported on more platforms.

I'm trying algorithms specific for Pupil Detection so I need the results to be really precise.

Does anyone know any advantages by way of speed or processing or inbuilt functions that MATLAB uses?

chappjc
  • 30,359
  • 6
  • 75
  • 132
nette
  • 575
  • 2
  • 8
  • 25
  • Stick to OpenCV and use its Python bindings for super fast development. – Pithikos Nov 29 '14 at 00:09
  • It is not too broad; a fair enough question. Some people are like retired colonels; stabbing kids' balls for no reason. – ozgur Nov 26 '18 at 08:04
  • MATLAB as interpreter is not made to be fast but gives you the opportunity to play with all the functionalities. You usually test in Matlab but then code in C to increase speed. OpenCV is as the names indicate a framework based on a dedicated library. It's difficult to compare the two... Matlab is a sandbox for "playing" and learning (and relatively slow). OpenCV is dedicated and specific (and fast). – Faisal shahzad Nov 17 '19 at 03:51

4 Answers4

14

If you already know OpenCV then stick with OpenCV. Currently OpenCV is the most comprehensive open source library for computer vision and it has large user community. OpenCV has more functions for computer vision than Matlab. Many of its functions are implemented on GPU. The library is being continuously updated (an updated version is released approximately every 3 to 4 months). In general C++ OpenCV code runs faster than Matlab code (if it's not fast enough, you can make it faster by optimizing the source code).

Matlab is useful for rapid prototyping and Matlab code is very easy to debug. It has good documentation and support. However, as others have mentioned, Matlab is not open source, its licence is pretty pricey, and its programs are not portable. Matlab is an interpreted language and it negatively affects its performance. Performance matters a lot in computer vision, especially if you are doing real time video processing. Its programs can be made fast too, however you will have to rely on high-level functions (i.e. built-in functions professionally written in C), mex functions (your own compiled C code), and you'll have to learn how to vectorize your code to achieve decent speed.

Alexey
  • 5,898
  • 9
  • 44
  • 81
3

You haven't mentioned how you are using OpenCV so I am going to assume that you are using C++; in case you are using Python, please read this page..

If you are planning to use GPU for processing, then I would suggest you stick to C++.. Of course, there are loads of other optimizations you can do to your code..

For MATLAB, there are some fairly basic things that can be done as well..

At the end of the day, I would say that the closer you are to machine level language, the better your performance is going to be. But of course, using C can be a pain since there is a HIGH chance of writing unoptimized code and memory leaks. For this reason, C++ gives the best trade-off..

HTH

scap3y
  • 1,188
  • 10
  • 27
  • Currently doing it for android thats why I thought OpenCV would be best. But may switch depending on the results. – nette Feb 05 '14 at 10:31
  • Again, you are not saying which language you are using. If you are using Android, I am guessing writing on Java would be a good way to go since that way you will be integrate into the SDK better. But I stand by what I said; for performance, you need C++. – scap3y Feb 05 '14 at 10:34
  • 1
    Don't assume that C is lower than C++ and _therefore_ faster. The classic example is sorting a list of numbers. C++ `std::sort` typically beats C `qsort` by a factor of 6. That's because the C++ sort is a template, a high-level construct which allows the optimizer access to the comparison function. – MSalters Feb 05 '14 at 10:41
  • Ah of course. I wasn't referring to some specific examples; I was just referring to most of OpenCV's functions.. Whenever I have used OpenCV in the C environment (with MinGW), it has given me better performance. – scap3y Feb 05 '14 at 10:43
3

Your question does not really make sense.

OpenCV is a C++-library for carrying out computer vision tasks. Apart from C++, there is support for other programming languages via bindings.

MATLAB is a full scientific suite that consists of a massive IDE with its own language.

If you want your code to run in MATLAB, then you write MATLAB code. But then you will also need to install a 4GB IDE, and pay for a fairly expensive license.

My personal choice is to use OpenCV with the Python language bindings, as this gives me a nice scripting interface to do matrix operations (arguably somewhat more cluttered than MATLAB's) while still having easy access to OpenCV-functions.

Hannes Ovrén
  • 21,229
  • 9
  • 65
  • 75
0

If you really understand about opencv means definitly you never think about switching from opencv to matlab.

You can use opencv with python or cpp and even java etc., also.
Actually, you should not consider opencv only to complete your whole task.
Like opencv, other libraries also exists.
For example,
numpy -> for fast numeric calculation
matplotlib -> to show figure window etc., like matlab.
scipy -> for fast scientific calculation.

If you use your_programming_language + opencv + matplotlib + numpy + scipy definitly you will wonder about opencv. And, don't worry about how to mingle these libraries together. Just mention their name and do your actual coding. Thats all.

Thamizh
  • 566
  • 3
  • 6
  • 16
  • I am aware of OpenCV just not that sure about MATLAB, hence the question. – nette Feb 06 '14 at 10:20
  • Okay Nette. No problem. If you find my answer is okay, mark it as correct. – Thamizh Feb 06 '14 at 10:34
  • 5
    The "your_programming_language + opencv + matplotlib + numpy + scipy" part does not make much sense. Numpy, matplotlib, and scipy are all **Python** packages. Why (and how) would you combine them with other languages? – Hannes Ovrén Feb 06 '14 at 12:08