How to start practicing OpenCV on VC++? Configurations of the VC++ project with OpenCV

In this post, we only take a look at how to config the VC++ project, in order to use the OpenCV. Suppose we have already successfully installed the OpenCV2.3.1. Version name may be different, but the steps are almost the same.


We need 3 steps:
  1. Create a new project.
  2. Make the configurations.
  3. Testing.





1. Create a new project.


    Note. You will need to make the configurations every time create a new project. Make the configurations.
   
Just press  File-->New-->Project, and choose the win32 console application and input a project name,     to create a new project.

2. Make the configurations.

    (1) Open project properties.
          


(2)   Add paths

In the VC++ Directories--Include Direstories
Add "C:\OpenCV2.3.1\build\include\;C:\OpenCV2.3.1\build\include\opencv;C:\OpenCV2.3.1\build\include\opencv2"  

In the VC++ Directories--Include Direstories
Add  "C:\OpenCV2.3.1\build\x86\vc10\lib"


In the C/C++--Additional Include Directories
Add C:\OpenCV2.3.1\build\include\;C:\OpenCV2.3.1\build\include\opencv;C:\OpenCV2.3.1\build\include\opencv2


In the  --Linker--Input--Additional Dependencies, choose Debug and Release then add respectively:


Debug :

opencv_calib3d231d.lib; opencv_contrib231d.lib; opencv_core231d.lib; opencv_features2d231d.lib; opencv_flann231d.lib; opencv_gpu231d.lib; opencv_highgui231d.lib; opencv_imgproc231d.lib; opencv_legacy231d.lib; opencv_ml231d.lib; opencv_objdetect231d.lib; opencv_ts231d.lib; opencv_video231d.lib  

Release:

opencv_calib3d231d.lib; opencv_contrib231d.lib; opencv_core231d.lib; opencv_features2d231d.lib; opencv_flann231d.lib; opencv_gpu231d.lib; opencv_highgui231d.lib; opencv_imgproc231d.lib; opencv_legacy231d.lib; opencv_ml231d.lib; opencv_objdetect231d.lib; opencv_ts231d.lib; opencv_video231d.lib;



       



3. Testing

    Copy this code and run the program, see if the opencv is right configured.


01 #include "stdafx.h"
02 
03 #include <opencv2/opencv.hpp>
04 
05 using namespace std;
06 using namespace cv;
07 
08 int main(int argc, char* argv[])
09 {
10    const char* imagename = "Lena.jpg";
11 
12    //Read an image
13    Mat img = imread(imagename);
14 
15    //If read failed
16    if(img.empty())
17    {
18        fprintf(stderr, "Can not load image %s\n", imagename);
19        return -1;
20    }
21 
22    //Show Image
23    imshow("image", img);
24 
25    //wait a key to return
26    waitKey();
27 
28    return 0;
29 }

No comments:

Post a Comment