What is OpenCV? OpenCV vs. MATLAB — An insight

What is OpenCV?

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. It is developed by Willow Garage, which is also the organization behind the famous Robot Operating System (ROS). Now you’d say MATLAB also can do Image Processing, then why OpenCV? Stated below are some diferences between both. Once you go through them, you can decide for yourself.

Advantages of OpenCV over MATLAB (Collected from various blogs/forums. See references below)

  • Speed: Matlab is built on Java, and Java is built upon C. So when you run a Matlab program, your computer is busy trying to interpret all that Matlab code. Then it turns it into Java, and then finally executes the code. OpenCV, on the other hand,  is basically a library of functions written in C/C++.  You are closer to directly provide machine language code to the computer to get executed. So ultimately you get more image processing done for your computers processing cycles, and not more interpreting. As a result of this, programs written in OpenCV run much faster than similar programs written in Matlab. So, conclusion? OpenCV is damn fast when it comes to speed of execution. For example, we might write a small program to detect peoples smiles in a sequence of video frames. In Matlab, we would typically get 3-4 frames analysed per second. In OpenCV, we would get at least 30 frames per second, resulting in real-time detection.
  • Resources needed: Due to the high level nature of Matlab, it uses a lot of your systems resources. And I mean A LOT! Matlab code requires over a gig of RAM to run through video. In comparison, typical OpenCV programs only require ~70mb of RAM to run in real-time. The difference as you can easily see is HUGE!
  • Cost: List price for the base (no toolboxes) MATLAB (commercial, single user License) is around USD 2150.  OpenCV (BSD license) is free! Now, how do you beat that? Huh? huh? huh?
  • Portability: MATLAB and OpenCV run equally well on Windows, Linux and MacOS. However, when it comes to OpenCV, any device that can run C, can, in all probability, run OpenCV.


Despite all these amazing features, OpenCV does lose out over MATLAB on some points:

  • Ease of useMatlab is a relatively easy language to get to grips with. Matlab is a pretty high-level scripting language, meaning that you don’t have to worry about libraries, declaring variables, memory management or other lower-level programming issues. As such, it can be very easy to throw together some code to prototype your image processing idea. Say for example I want to read in an image from file and display it. In Matlab, you could write this as:
    I = imread('someImage.jpg');
    imshow(I)
    

    Easy, right? Now, if you wanted to do the same using OpenCV, it would look like:

    #include "cv.h" //main OpenCV header
    #include "highgui.h" //GUI header
    
    int main()
    {
    
    // declare a new IplImage pointer
    IplImage* myimage;
    
    // load an image
    myimage = cvLoadImage("someImage.jpg",1); //change the file name to your own image
    
    //create a new window & display the image
    cvNamedWindow("Smile", 1);
    cvShowImage("Smile", myimage);
    
    //wait for key to close the window
    cvWaitKey(0);
    cvDestroyWindow("Smile");
    cvReleaseImage(&myimage);
    return 0;
    
    }
    
  • Memory Management: OpenCV is based on C. As such, every time you allocate a chunk of memory you will have to release it again. If you have a loop in your code where you allocate a chunk of memory in that loop and forget release it afterwards, you will get what is called a “leak”. This is where the program will use a growing amount of memory until it crashes from no remaining memory. Due to the high-level nature of Matlab, it is “smart” enough to automatically allocate and release memory in the background.
  • Development Environment: Matlab comes with its own development environment. For OpenCV, there is no particular IDE that you have to use. Instead, you have a choice of any C programming IDE depending on whether you are using Windows, Linux, or OS X. For Windows, Microsoft Visual Studio or NetBeans is the typical IDE used for OpenCV. In Linux, its Eclipse or NetBeans, and in OSX, we use Apple’s Xcode.

Phew! Okay. now that we are done with the basic differences, you can start with the installation here.

References:

1. http://blog.fixational.com/post/19177752599/opencv-vs-matlab

2. http://www.aishack.in/2010/02/why-opencv/

3. A few interesting stackoverflow answers:

4. http://opencv-users.1802565.n2.nabble.com/OpenCv-vs-Matlab-td2426918.html

click tracking

6 thoughts on “What is OpenCV? OpenCV vs. MATLAB — An insight

  1. oh my goodness!! you are God sent! thank you very much for this very vital info. My project is about crowd size estimation using image processing techniques on a still image and I was considering using either Matlab or OpenCv . Now am pretty clear its Open Cv I should use. Since I am in the baby stages of my project am quite green on this stuff so please expect some (okay.a million) questions coming your way lol! A few (okay many!) pointers to help me get started would be very much appreciated, haha! Thank you so much once again, really waiting for those (many!) pointers lol.

  2. Gautam says:

    hi karan,
    this post was very helpful.
    can u plz guide me regarding the basics of image processing.. i mean how to identify shapes.when made infront of a camera

Comments anyone? Huh? huh? huh?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s