Create an opencv2.4.0 Development Environment on Windows

Source: Internet
Author: User
Tags visual studio 2010

1. download the latest opencv version ,:

Http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.0/

Download opencv-2.4.0.exe from the blockchain.

2. Install opencv. Create a Directory D: \ opencv2.4(, and then double-click opencv-2.4.0.exe to install it on D: \ opencv2.4.

OpenCV-2.4.0.exe is actually a self-decompressed package, this process is actually to extract the files related to opencv to the d: \ opencv2.4 directory. After completion:

Figure 1

Note:

Decompress the package to the D: \ opencv2.4 directory. In fact, there is only one subdirectory such as opencv. You can see the various folders and files listed on the right under the opencv subdirectory. For convenience, all the content in opencv is directly moved to the Directory D: \ opencv2.4 and the opencv subdirectory is deleted. Of course, you do not need to create the D: \ opencv2.4directory, but directly decompress opencv-2.4.0.exe to the root directory of drive D. After that, an opencv subdirectory will be added to the root directory of drive D, in this case, you can modify the directory name of opencv as needed. For example, you can change it to opencv2.4.

3. Install the C ++ development environment. On Windows, many c ++ development environments can be used, such as QT and eclipse. Of course, Microsoft's Visual Studio is the most commonly used one. We may wish to use the new visual Studio 2010, for details about the installation process, see:

Install and crack vs2010 professional

4. Environment configuration. It is important to do some work in this step.

A) create the environment variable opencv_dir

Figure 2

D: \ opencv2.4 is the directory where opencv is installed.

B) set the PATH environment variable

Figure 3

At the end of the path environment variable, the following content is added:

; % Opencv_dir % \ build \ x86 \ VC10 \ bin; % opencv_dir % \ build \ common \ TBB \ ia32 \ VC10

C) Start vs2010 and create a project. This article aims to illustrate how to build the development environment of opencv. Therefore, you are prepared to create a relatively simple project. If you are familiar with the Visual Studio environment, select to create another project. Select File/New/project as follows:

 

Figure 4

Select Win32 consoleapplication, and then give:

Project name (name): firstopencvapp

Location: e: \ workspace \ CPP

Solution name: opencv

The above content can be modified as needed. Accept the default values for other items, and click OK:

Figure 5

Select leleapplication for applicationtype and emptyproject for additionaloptions. Precompledheader is related to the Windows platform. Because we are going to create code that complies with the ansic ++ standard, we do not need to select it. Click Finish to complete solution and Project Creation.

D) So far, Visual Studio does not know where the library and header files related to opencv are. Of course, every time we create a project, specify the header file and the directory of the library of opencv for it, but this is obviously a cool thing. For this reason, we can create propertysheet so that we can reuse it for future projects. Choose View/other Windows/property manager:

Figure 6

Select debug | Win32, right-click, and select addnew project property sheet from the pop-up menu:

Figure 7

For example, name the newly created propertysheet: opencvprojectpropertiesd. The last letter D in the name indicates the debug version, and save it in solution root directory e: \ workspace \ CPP \ opencv \, and then click the Add button to get:

Figure 8

Right-click opencvprojectpropertiesd and select Properties from the pop-up menu:

Figure 9

Select VC ++ directories on the left, then select includedirectories on the right, and click the rightmost small button to edit it,

Figure 10

For example, add the D: \ opencv2.4 \ build \ include directory and click OK.

 

Similar to the above, in Figure 9, select librarydirectories on the right and click the rightmost small button to edit it,

Figure 11

Select "D: \ opencv2.4 \ build \ x86 \ VC10 \ Lib" and click "OK:

Figure 12

E) Add a library file. Click the linker on the left, click input under it, and select additionaldependencies on the right,

Figure 13

Click the button on the rightmost side to edit it:

Figure 14

We need to add the library file name ("D" before. Lib) in the Directory D: \ opencv2.4 \ build \ x86 \ VC10 \ Lib, as shown in. Click OK and click OK to complete the configuration of the propertysheet opencvprojectpropertiesd. The following is the case after completion:

Figure 15

F) Select release | Win32 in figure 8. You can create a propertysheet for the release version in a similar way. The other steps are similar, but when adding the library file in E), remember to add the release version of the library file (. Lib does not have the letter "D" before ")

Figure 16

G) after completing the preceding steps, two propertysheet files will be generated under the E: \ workspace \ CPP \ opencv Directory, which can be reused later.

Figure 17

5. write the code. After the previous steps, even if the development environment has been installed, we can write a piece of code to verify it.

Right-click the project firstopencvapp and select Add/new item in the pop-up menu.

Figure 18

Select C ++ file, enter the name of the C ++ file main in the Name field, and click the Add button to generate the file main. cpp. The content of the Main. cpp file is as follows:

# Include <opencv2/CORE. HPP>

# Include <opencv2/highgui. HPP>

 

Intmain (INT argc, char ** argv)

{

// Read animage

CV: mat image = CV: imread ("D:/lady.jpg ");

// Createimage window named "lady"

CV: namedwindow ("lady ");

// Show theimage on window

CV: imshow ("lady", image );

// Wait keyfor 5000 Ms

CV: waitkey (5000 );

 

Return0;

}

 

6. Press F5 to run the task. The result is correct. This indicates that the environment is successfully set up.

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.