Sunday, June 19, 2016

Open CV Installation and Configuration with Visual C++ Express Edition

Download latest version of openCV, here I am using 2.4.6 from  http://opencv.org/downloads.html and using its self-extractor software will automatically extract all files on given path, as in the following figure it says “C:\



Wait until all files get extracted. It will create a new directory C:\opencv which contains OpenCV header files, libraries, code samples, etc

Now for completing installation its need to add the path in system PATH now follow the following step.

Open Control Panel è System è Advanced system settings è Advanced Tab è Environment variables.



Go to OpenCV è build è x86 (for 32-bit OS) / x64 (for 64-bit OS) è VC10 è BIN 
Copy that path (C:\opencv\build\x86\vc10\bin)

On the System Variables section, select Path (1), Edit (2), and paste your coppied path (3), then click Ok.

Now open Visual C++ and make a new empty Project named (cvtest)



Right click on Project (cvtest) è Properties è VC++ Directories



Then click on Include Directories and add the path of Include folder of OpenCV



Now click on Library Directories enter lib path from openCV such as (C:\opencv\build\x86\vc10\lib.)



Now select Linker è Input è Additional Dependencies
Type all lib file name as written below


opencv_calib3d243d.lib
opencv_contrib243d.lib
opencv_core243d.lib
opencv_features2d243d.lib
opencv_flann243d.lib
opencv_gpu243d.lib
opencv_haartraining_engined.lib
opencv_highgui243d.lib
opencv_imgproc243d.lib
opencv_legacy243d.lib
opencv_ml243d.lib
opencv_nonfree243d.lib
opencv_objdetect243d.lib
opencv_photo243d.lib
opencv_stitching243d.lib
opencv_ts243d.lib
opencv_video243d.lib
opencv_videostab243d.lib


Keep in Mind:
          You can see the number 243 at the end of every lib file. This is basically version of openCV 2.4.3, change them as your openCV version as it ia 2.4.7 you have to write “247” instead of 243.
And the file name names “d” is for debugging purpose.


Now add C++ file in project by Add è New Item è Visual C++ è C++ file



Now copy paste the following code to check either your OpenCV work fine
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv/cv.h>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

int main()
{
       //-------------- Load Image -------------------
       IplImage* img = cvLoadImage("image.jpg");
    cvNamedWindow("image");
    cvShowImage("image", img);

    cvWaitKey(0);
    //---------- EXIT Program --------------
    cvDestroyWindow("image");

    return 0;
}
                                
For this you have to use the following image download it by right click è save as
And keep this file in your C++ project.


Output:






Share: