Opencv2.4.9 & Visual Studio 2010 environment Configuration

Source: Internet
Author: User
Tags visual studio 2010

1. Preparations

1.1. to install Visual Studio 2010, you must install VC ++ functions. For more information, see du Niang.

1.2. Download opencv 2.4.9 For Windows: https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.9/opencv-2.4.9.exe/download

1.3. Double-click the Downloaded Program to install opencv, such as setting the decompression directory:

After decompression, the Directory D: \ Program Files \ opencv \ contains the build and source subdirectories.

Next, configure the environment.

 

2. opencv environment Configuration

Operating System: Windows 7x64. Configure environment system variables.

On the desktop, right-click computer and choose Properties> advanced system Settings> environment variables> system variables, for example:

2.1. Create an opencv system variable. Click "New (w)..." and set it as follows:

Variable name:Opencv,

Variable value:D: \ Program Files \ opencv \ build This is the path of the build subdirectory under the opencv decompress directory.

2.2. Edit the path system variable. Find the PATH variable in the system Variable list and click "Edit (I)...". Add the following variable values to the existing variable values:

; % Opencv % \ x64 \ VC10 \ bin; % opencv % \ x86 \ VC10 \ bin

The semicolon ";" indicates the separation of paths. Here we add two PATH variables: opencv x64 and x86, so that the two runtime environments can be applied at the same time.

2.3. opencv has been configured. To make the configuration take effect immediately, You need to log out and log on to the operating system again.

 

3. Visual Studio 2010 environment Configuration

To create an opencv C ++ project in Visual Studio 2010, follow these steps.

3.1. Create a VC ++ Project

A. Open Visual Studio 2010, and choose File> New> project. Create a VC ++ console application named"Opencvdemo", Such:

B. Click OK to create a project. In Project Settings, set it to an empty project, for example:

C. Click Finish to create a new VC ++ project. The project solution directory is as follows:

 

3.2. Configure Project Properties

In solution view 3.1, right-click the project "opencvdemo" and choose Properties to bring up the property configuration dialog box.

Set Configuration to all deployments. For example:

3.3. Directory Configuration

On the property configuration page, choose configuration Properties> VC ++ directory (VC ++ Directories) on the left, as shown in Figure 3.2. Then perform the following configuration operations:

A. Add the include directory (include directories ). Click the right side of the list containing directory (include directories) line, a drop-down button will appear, and then select "<edit...>" to edit.

Then add the following three directories:

D: \ Program Files \ opencv \ build \ include \ opencv D: \ Program Files \ opencv \ build \ include \ opencv2

The page after adding is shown in the following figure:

B. Add the library directory (library Directories ). Click the right side of the library directory (library Directories) line, a drop-down button will appear, and then select "<edit...>" to edit.

Then select Add the following directory:

D: \ Program Files \ opencv \ build \ x86 \ VC10 \ Lib

Where: VC10 indicates that Visual Studio 2010 is used, and vc12 indicates that Visual Studio 2013 is used;

X86 indicates that the platform version selected by the Project compiler is Win32, and x64 indicates that the project compiler is win64.

3.4. Add dependency

On the property configuration page, choose configuration Properties> linker> input on the left ). For example:

Click additional dependencies on the right side of the list. A drop-down button is displayed, and select <edit...> to edit the dependency.

Then select Add the following dependencies (the file is located at D: \ Program Files \ opencv \ build \ x86 \ VC10 \ Lib ):

Opencv_calib3d249d.lib
Opencv_contrib249d.lib
Opencv_core249d.lib
Opencv_features2d249d.lib
Opencv_flann249d.lib
Opencv_gpu249d.lib
Opencv_highgui249d.lib
Opencv_imgproc249d.lib
Opencv_legacy249d.lib
Opencv_objdetect249d.lib
Opencv_ts249d.lib
Opencv_video249d.lib
Opencv_nonfree249d.lib
Opencv_ocl249d.lib
Opencv_photo249d.lib
Opencv_stitching249d.lib
Opencv_superres249d.lib
Opencv_videostab249d.lib

File Name"249d",249The version of opencv is 2.4.9,DIndicates the debug library.

The difference between the release compilation configuration and the debug compilation configuration lies in the dependency here. No library file name configured for release"D"End.

3.5. The project properties have been configured. Click Apply or OK to save the configuration.

 

3.6. Test Environment

A. in the project"Opencvdemo", Add the resource file demo.jpeg.

B. In the project"Opencvdemo", Add the CPP file main. cpp;

#include<iostream>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>using namespace cv; int main() {       Mat img = imread("demo.jpg");    namedWindow("Image");    imshow("Image", img);    waitKey(0);    destroyWindow("Image");}

C. Generate the project and debug the program. The running effect is as follows:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.