OpenCV configuration with Visual Studio

Today i'll show you the how can you manually configure OpenCV 2.4.11 with Visual Studio 2013.

Open the visual studio File > New > New Project > Installed > Template > Visual C++ > CLR then click on CLR Console Application and named the project as TestOpenCV then hit OK.




Go to Link and download opencv 2.4.11, you can choose any latest version of opencv, process will be same as following.
Create a new folder in Drive C named as cv2411 and extract in it. Your directory should be like following image.


First of all you need to set System Environment Variable in windows. Open Control panel > System and Security > System > Advance system settings > Advanced click on Environment Variables button. Select Path from System variables then click Edit and paste bin path as following then click OK OK and OK :).

  • C:\cv2411\opencv\build\x86\vc12\bin





Go back to Visual Studio, right click on project and select properties. I'm building opencv for x86 platform in visual studio but you can also use x64. For this you just need to change path as x64. In properties panel go to Configuration Properties > VC++ Directories > Include Directories then click drop down edit button and add following path.

  • C:\cv2411\opencv\build\include

In Libraries Directories add following path
  • C:\cv2411\opencv\build\x86\vc12\lib



Go to C/C++ > Additional Include Directories and paste following directory

  • C:\cv2411\opencv\build\include

Go to Linker > Additional Library Directories and paste following directory

  • C:\cv2411\opencv\build\x86\vc12\lib
Go to Linker > Input >Additional Dependencies and paste following libraries name 
  • opencv_calib3d2411d.lib
  • opencv_contrib2411d.lib
  • opencv_core2411d.lib
  • opencv_features2d2411d.lib
  • opencv_flann2411d.lib
  • opencv_gpu2411d.lib
  • opencv_highgui2411d.lib
  • opencv_imgproc2411d.lib
  • opencv_legacy2411d.lib
  • opencv_ml2411d.lib
  • opencv_nonfree2411d.lib
  • opencv_objdetect2411d.lib
  • opencv_photo2411d.lib
  • opencv_stitching2411d.lib
  • opencv_superres2411d.lib
  • opencv_ts2411d.lib
  • opencv_video2411d.lib
  • opencv_videostab2411d.lib
If you want to configure opencv in Release mode the simply remove d from above libraries names.
Then click on Apply button then OK. Your opencv has been configured. Now let's run some lines of code to test OpenCV, just copy following code and paste in TestOpenCV.cpp file.
  • #include "stdafx.h"
    #include <iostream>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>
    #include <opencv2/core/core.hpp>
    #include <opencv2/opencv.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/highgui/highgui.hpp>

    using namespace std;
    using namespace cv;

    int main()
    {
      Mat image;
      image = cv::imread("C:\\test.png");
      namedWindow("Display window", 1);
      imshow("Display window", image);
      waitKey(0);
      return 0;
    }
Build the project and run.
If you are facing dll missing errors then simply go to following path and copy all dll files and paste them with project .exe file. You can find project exe file in Project directory. it will be in Debug or Release folder.

  • C:\cv2411\opencv\build\x86\vc12\bin
If you have any issue or suggestion please comment below.
, , ,

How to configure opencv in Eclipse IDE

Firstly, I'm assuming that you have installed OpenCV on Ubuntu. If not, then follow the link. Secondly You need to install Eclipse + JDK7. Following command will install eclipse for c++ developer with JDK7. Just Run following command.

  • sudo apt-get install eclipse eclipse-cdt g++

Open Eclipse and right click or Go to File > new project > C/C++ > C++ Project > Next

Name the project as TestOpenCV and select Hello World C++ Project then click next. Write Author name whatever you want then click next next and finish.


Before to run project expand src directory and add following lines of code in TestOpenCV.cpp



  • #include "stdfix.h"#include <iostream>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>
    #include <opencv2/core.hpp>

    #include <opencv2/opencv.hpp>

    #include <opencv2/imgproc/imgproc.hpp>

    #include <opencv2/highgui/highgui.hpp>


    using namespace std;
    using namespace cv;

    int main()
    {
            Mat image;
            image  = cv::imread("/home/test.png");
            namedWindow("Display window", 1);
            imshow("Display window",image);
            waitKey(0);
            return 0;
    }
Now Right on project > properties > C/C++ Build > Settings > Cross G++ Compiler > Includes

Run following commands to get includes paths
  • pkg-config --cflags opencv
Copy all include paths and add into include paths (-I) tab like following
Run following command in terminal to get all libraries paths and lib files
  • pkg-config --libs opencv
Now Click on Cross G++ Linker > Liberalities
and add lib path in Library search path (-L) tab and all OpenCV libs in Libraries(-I) tab
  • Path: /usr/local/lib
  • Libs: opencv_calib3d opencv_contrib opencv_core opencv_features2d opencv_flann opencv_gpu opencv_highgui opencv_imgproc opencv_legacy opencv_ml opencv_nonfree opencv_objdetect opencv_ocl opencv_photo opencv_stitching opencv_superres opencv_ts opencv_video opencv_videostab
It may be different if you installed different version.
Click OK and build the project the project and run.

, , , ,

How to install Opencv on Ubuntu Desktop/Ubuntu Server

To install OpenCV on your system run the following commands in terminal. You should have Ubuntu/Server 12 or 14 LTS to install it.


  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install libtiff5-dev
  • sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff5-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant libvtk5-qt4-dev
You can change OpenCV version in following command, just go to link and change the version in following OpenCV URL, like I'm using 2.4.11 here.
  • cd~
    wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.11/opencv-2.4.11.zip
    unzip opencv-2.4.11.zip
    cd opencv-2.4.11
  • mkdir build
    cd build
    cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..
Now, you are ready to compile and install OpenCV 2.4.11:

  • make
  • sudo make install
Now, you have to configure OpenCV first. Open the opencv.conf file with the following command if you are using Ubuntu desktop

  • sudo gedit /etc/ld.so.conf.d/opencv.conf
If you are using Ubuntu Server then open file with following command

  • sudo nano /etc/ld.so.conf.d/opencv.conf
Add following lines at the end of the file (it may be an empty file, that is ok) and then save it:

  • /usr/local/lib
To save file use CTRL+X then press y then hit enter.
Run the following command to configure the library

  • sudo ldconfig
Now you have to open another file:

  • if you are using Ubuntu Desktop then use this command
    • sudo gedit /etc/bash.bashrc
  • if you are using Ubuntu Server then use this command
    • sudo nano /etc/bash.bashrc
Add these two lines at the end of the file and save it:

  • PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
    export PKG_CONFIG_PATH
Finally, close the terminal and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.

To see where opencv installed use following command

  • pkg-config --cflags opencv
To see lib files directory use following command

  • pkg-config --libs opencv
Let run simple c++ code with opencv code using g++ compiler. Create new file and named it as test.cpp and add following code in it

  • #include "stdfix.h"#include <iostream>
    #include <opencv/cv.h>
    #include <opencv/highgui.h>
    #include <opencv2/core.hpp>

    #include <opencv2/opencv.hpp>

    #include <opencv2/imgproc/imgproc.hpp>

    #include <opencv2/highgui/highgui.hpp>


    using namespace std;
    using namespace cv;

    int main()
    {
            Mat image;
            image  = cv::imread("/home/test.png");
            namedWindow("Display window", 1);
            imshow("Display window",image);
            waitKey(0);
            return 0;
    }
Save the file, open terminal cd to directory where you save test.cpp file and write following command in terminal

  • g++ `pkg-config --cflags opencv` text.cpp `pkg-config --libs opencv` -o test
Your file is build with opencv, just write following command to run test file


  • ./test
Thanks :)