Learning the learning notes series of opencv-Environment configuration 2

Source: Internet
Author: User
Tags visual studio 2010

To learn opencv well, you must first know how to configure the environment. Take your own configuration environment as an example. The steps are as follows.

Step 1 download and decompress the opencv source code

Although many third-party websites and some learning forums provide opencv source code downloads, we recommend you download them on the official website to avoid a lot of trouble! (Virus? Trojan? You know !)

The official website is as follows:

Http://opencv.org/downloads.html

You can find the latest opencv source code on this address interface. I am using version 2.4.9 updated on version (currently the latest). Select the source code version based on your system.

Because my computer is win7x64bit, select the "opencv for Windows" link to download it.

After downloading, you can see the code extraction program of this exe.


Double-click the extract program and select the extract directory. The G disk is selected here.


Click the "extract" button, and the program will automatically extract the opencv source code to the "opencv" Directory of g (this directory is generated by itself, you do not need to write it in the release program !).


Under the "G: \ opencv" directory, we can see two folders: "build" and "Source.


Step 2 configure the opencv system variable path

After installing the source code of opencv, you must configure the system path of opencv.

Right-click "computer" in the Start menu and choose "properties". On the left side of the page displayed, click "Advanced System settings". Then, select the "advanced" tab in the "System Properties" dialog box.


Click "environment variable ".


In the "System variables" area under the displayed "environment variables" dialog box, locate the "path" option, and double-click


In the displayed "Edit System variables" dialog box, add a variable in the "variable value" Column (note that adding is separated by semicolons at the end of this column) "G: \ opencv \ build \ x86 \ VC10 \ bin;" and "G: \ opencv \ build \ x64 \ VC10 \ bin;" (for 32-bit systems, you don't need to use this one ).

So far, the path of the system variables of opencv has been configured.


Step 3 configure the vs2010 Environment

Open Visual Studio 2010, create a new visual C ++ project, select "Win32 console application", and name "helloopencv". Click "OK.


In the displayed "Win32 Application Wizard" dialog box, click "Next"

On the "Additional Options" Page, select "Empty Projects" and click "finish ".


On the "helloopencv" project interface, click "View" in the menu bar, select "other window", and click "Property Manager ".


In the pop-up "Property Manager", find the "Debug | Win32" folder and double-click the "Microsoft. cpp. win32.user" option.


In the next "Microsoft. CPP. on the win32.user property page, find the "VC ++ directory" option under "general attributes" and click "edit" in "include directory" on the right ".


In the "include directory" dialog box, create three include directory paths:

1. G: \ opencv \ build \ include

2. G: \ opencv \ build \ include \ opencv

3. G: \ opencv \ build \ include \ opencv2

Click "OK ".



Then, add the directory path of the opencv static library to the "library directory.


Whether it is a 64-bit system or not, you only need to add "G: \ opencv \ build \ x86 \ VC10 \ Lib". You do not need to add "G: \ opencv \ build \ x64 \ VC10 \ Lib "unless you use a 64-bit compiler.



Next, configure the dynamic link library.


On the Microsoft. cpp. win32.user attribute page, click "input options" in "linker", click the arrow, and select "edit ".


In the "add dependency" dialog box that appears, add the following path:

Opencv_ml249d.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

Opencv_objdetect249.lib
Opencv_ts249.lib
Opencv_video249.lib
Opencv_nonfree249.lib
Opencv_ocl249.lib
Opencv_photo249.lib
Opencv_stitching249.lib
Opencv_superres249.lib
Opencv_videostab249.lib
Opencv_calib3d249.lib
Opencv_contrib249.lib
Opencv_core249.lib
Opencv_features2d249.lib
Opencv_flann249.lib
Opencv_gpu249.lib
Opencv_highgui249.lib
Opencv_imgproc249.lib
Opencv_legacy249.lib
Opencv_ml249.lib

Here, the blue is the library file in debug mode. It can be seen that the name is followed by a "d" (representing Debug), and the red is the library file in release mode, do not contain the suffix "D.

Generally, we will write all the items with and without D here, because these public attributes will be inherited when all projects are created in the future, so that you do not need to configure them for each project in the future, saving time and effort.


Step 4 Engineering Test

After completing the above steps, we 'd better restart the system to make some of our configurations take effect to avoid the following test errors.


In solution Resource Manager of the "helloopencv" project we created, right-click "source file" and add a new item.


In the "Add new project" dialog box, select and add a "C ++ file (. cpp)" file, name it "Main", and click "add ".


Add the following code to the main. cpp file:

# Include <iostream> # include <opencv2/CORE/core. HPP> # include <opencv2/highgui. HPP> using namespace CV; int main () {// read an image mat myimg = imread ("test.jpg "); // create a window named "helloopencv" namedwindow ("helloopencv"); // display the window imshow ("helloopencv", myimg ); // wait 10 seconds before closing the waitkey (10000 );}

Upload test.jpg to the project file directory, compile the file, and click debug.

The effect is as follows:



So far, all configurations have been completed and the test has passed. Next, we can enjoy the various surprises that opencv brings to us.



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.