Install OPENCV:OPENCV 2.4.8 or OpenCV 2.4.9 +VS development environment Configuration

Source: Internet
Author: User
Tags visual studio 2010

Because the research direction during the study is the image processing, so the light ink this period of time closed-door study of a lot of OPENCV and image processing related knowledge and content. See oneself accumulated to a certain extent, so decided to start to open this OPENCV series column, summed up their learning, also share knowledge to everyone.

Well, this article as a OPENCV of the start of the article, naturally, we first systematically introduce the configuration of the OPENCV development environment. Light ink before and after experienced OpenCV 2.4.6,OPENCV 2.4.7,OPENCV 2.4.8 These three versions of the configuration, and sometimes involves the conversion between three versions, so still have a certain understanding of the configuration of OpenCV, I hope I can help you in a little humble opinion.  Let's just release the test diagram for later: So, let's get started. 1. Download and install the OpenCV SDK

VS2010 Needless to say, it must have been installed. Speaking of the latest OPENCV version 2.4.8 (February 24, 2014), download and installation of 2.4.9 (April 2014). Rather than installation, it is more appropriate to call decompression, because we downloaded EXE installation file is a self-extracting program just.

On the official website: http://opencv.org/found OpenCV Windows edition download down.

After downloading to get file OpenCV 2.4.X, double-click will prompt decompression to a place, recommended to D:\Program files\, such as D:\Program files, (because OpenCV project file packaging, the root directory is OPENCV, So we don't need to add a new folder called OpenCV, and then unzip it, that's superfluous thing) and then click the Extract button.

After a while, OpenCV2.4.8 nearly 3 grams of files are extracted to D:\Program files.

Where build is using OPENCV related files, if we just use OPENCV, we only use the contents of the Tube build. The following sources folder you wearies, you take up the hard disk space, can be deleted completely. However, it is important to note that the official sample set, which is the sample program in the Samples folder, is lying in the sources folder, so if you really want to delete it, still think clearly. Sources inside is the source code. can be viewed directly. How to generate a SLN solution light ink in this blog in detail: "OpenCV Introductory tutorial seven" play OpenCV source code: Generate OPENCV Engineering Solution and OPENCV source compilation 2. Configuring Environment variables

This step is configured as follows:

Computer, (right) properties, advanced system settings, Advanced (label), environment variables, double-click the path-> in the system variable to add the appropriate path to the variable value.

<1>

<2>

<3>

<4>

<5>

For 32-bit systems, add:

"; ..... opencv\build\x86\vc10\bin" (and before that there is an environment variable in English with a semicolon ";") to separate)

For 64-bit systems, you can add both:

"; ..... opencv\build\x86\vc10\bin"

and "... Opencv\build\x64\vc10\bin",

In this way, can be in the compiler Win32 and X64 to switch back and forth to eat open, comfortable ~

For example, the light ink is

D:\Program Files\opencv\build\x64\vc10\bin;d:\program Files\opencv\build\x86\vc10\bin

PS: There are children's shoes pro-Test said 64-bit system also just add "... opencv\build\x86\vc10\bin" can, everyone may wish to try.

Note: The variable value is actually the path of the Bin folder, D indicates that OPENCV is installed on the D drive, and the X64 indicates that the system environment bit 64-bit system, if installed on a 32-bit system, should be X86;VC10 to represent the compilation environment for Microsoft Visual Studio 2010. If the variable is added, it is best to log off the system before it takes effect.

(After you configure the following steps, you restart the computer so that the environment variables are valid.) Otherwise the error will occur

--Myself, 2014.07.16)

3. Configuration of the project include (include) directory

Many of the posts I've seen before say "every new project has to be reconfigured", but it doesn't have to be so troublesome.

The first is to create a new console application in Visual Studio, preferably a tick with an empty project.

(Considering that the children's shoes that look at this blog are seldom in touch with VS, the light ink will be detailed here--light ink June 11, 2014 note)

<1> Open Visual Studio, create a new Win32 console project, take a name such as Test1, then select the path and click OK.

<2> click "Next".

<3> hook above the item.

<4> then, in Solution Explorer, right-click Add-New on the source file, ready to create a new CPP source file in the project.

<5> Select C + + source file, take a name, such as "main", then click "Add", then a new CPP file is added to the project.

<6> have seen the relevant blog post for DirectX configuration before light ink friends should know that there is a trick called property manager. Once configured in the property manager, it is the equivalent of a common configuration process, and no additional reconfiguration is necessary for the new project.

In the menu bar, pastry < View >--< Property Manager, you will have one more property manager workspace in Visual Studio.

<7> in the newly-emerged Property manager workspace, click Project->debug| Win32->microsoft.cpp.win32.userdirectories (Right-click Property, or Double-tap) to open the Properties page.

<8> when the Properties page is opened, it is configured. The first is in

"Common Properties", "VC + + Directory", "Include Directories"

Tim Plus

D:\Program Files\opencv\build\include

D:\Program FILES\OPENCV\BUILD\INCLUDE\OPENCV

D:\Program FILES\OPENCV\BUILD\INCLUDE\OPENCV2 these three directories.

Of course, this is the case of OpenCV decompression to D:\Program files\. The actual path also depends on your own OPENCV extracted to which directory, according to your actual situation to adjust.

4. Configuration of the Engineering Library (LIB) directory

In fact, this step is similar to the previous step, in the Property Manager workspace, click Project->debug| Win32->microsoft.cpp.win32.userdirectories (anti-key attribute, or double-click) to open the Properties page.

Next step, in the "Common Properties", "VC + + Directory", "Library Directory",

Add the path to the D:\Program files\opencv\build\x86\vc10\lib. (It is best not to copy and paste the path given by the light ink, but to go to the preview inside the specified, this will be much more accurate)

(Thanks to small, such as the wind children's shoes, the path given before D:\Program files\opencv\build\x86\vc10\lib space, directly copy the light ink given above the path of the children's shoes will appear "Unable to open error 1 errors LNK1104: Unable to open the file "Opencv_calib3d248.lib" Similar error ", corrected now)

—————— Light ink on April 3, 2014

The question of whether to choose x86 or x64 here is a often puzzling one. Of course, for a 32-bit operating system, the x86 is definitely selected.

If it is a 64-bit operating system, many children's shoes will be taken for granted to choose x64, not actually. The correct understanding is this:

Whether you are a 32-bit or 64-bit operating system, use only the Win32 compiler or the X64 compiler.

In fact, the configuration selection is not directly related to the 64-bit or 32-bit system, but it is the compiler you use when compiling your program.


The compiler chose Win32, just use x86.

The compiler chose X64, just use X64. In general, however, the Win32 X86 compiler is used. So, whether 32 or 64-bit operating systems, the configuration file is best to choose the x86 version of the

Also, the VC10 here represents vs2010, and if it's another version of Visual Studio, tweak it a little bit.

Thank Jjbomb Children's shoes, here we add complete: Vc8 = Visual Studio 2005,VC9 = Visual Studio 2008,VC10 = Visual Studio 2010,VC11 = Visual Studio 2012 , VC12 = Visual Studio 2013.

5. Configuration of the link library

Still in the Property Manager workspace, click Project->debug| You can open the Properties page by Win32->microsoft.cpp.win32.userdirectories (the inverse key attribute, or double-click). Additional dependencies, input, common properties, linker, and more

For "OpenCV2.4.8", add the following 248 Lib (the Lib sequence is: 19 with the D version of the Lib written in front, 19 without the D release version of Lib written in the back):

Opencv_ml248d.lib
Opencv_calib3d248d.lib
Opencv_contrib248d.lib
Opencv_core248d.lib
Opencv_features2d248d.lib
Opencv_flann248d.lib
Opencv_gpu248d.lib
Opencv_highgui248d.lib
Opencv_imgproc248d.lib
Opencv_legacy248d.lib
Opencv_objdetect248d.lib
Opencv_ts248d.lib
Opencv_video248d.lib
Opencv_nonfree248d.lib
Opencv_ocl248d.lib
Opencv_photo248d.lib
Opencv_stitching248d.lib
Opencv_superres248d.lib
Opencv_videostab248d.lib

Opencv_objdetect248.lib
Opencv_ts248.lib
Opencv_video248.lib
Opencv_nonfree248.lib
Opencv_ocl248.lib
Opencv_photo248.lib
Opencv_stitching248.lib
Opencv_superres248.lib
Opencv_videostab248.lib
Opencv_calib3d248.lib
Opencv_contrib248.lib
Opencv_core248.lib
Opencv_features2d248.lib
Opencv_flann248.lib
Opencv_gpu248.lib
Opencv_highgui248.lib
Opencv_imgproc248.lib
Opencv_legacy248.lib

Opencv_ml248.lib

For "OpenCV2.4.9", add the following 249 Lib (the Lib sequence is: 19 with the D version of the Lib written in front, 19 without the D release version of Lib written in the back):

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.libopencv_ml249.lib

Note that the pasted content is the name of all Lib library files under the OpenCV directory that we unzipped before D:\opencv\build\x86\vc10\lib , of which 248 represents our OPENCV version of 2.4.8, if the other version of the configuration is to make the corresponding changes here, such as the 2.4.6 version of the OpenCV, then the opencv_calib3d248d.lib will be changed to Opencv_ It's calib3d246d.lib.

Debug file library name has D end, release not, such as Opencv_ts248d.lib (Debug version of Lib) and Opencv_ts248.lib (release version of Lib)

But I'm usually here to write everything with D and without D here, because this is the public property that will inherit when all the projects are created later.

Note: In the same way as above, it may appear that the debug can run but the release cannot run the situation (because the string reading problem caused by the chip load, the report pointer out of bounds, memory errors, etc.), this is OpenCV since 2.4.1 a bug.

Solution: To run the program results in release mode, in the project release mode, the Lib without D (all 19) is added to the "project", "Properties" (note that this opens the current project's property page, We just need to add the release version (that is, the relevant Lib without D), "Configuration Properties", "linker", "Input" and "Additional dependencies".

—————— Light Ink March 17, 2014 note &2014 June 11 update

Similar errors

6. Add OpenCV dynamic link library under Windows folder

PS: After Hellofuturecyj classmate reminds, if the configuration environment variable that step configuration is accurate, and after the configuration has been restarted, there is no need to do this step configuration. That is, to finish the fifth step of the configuration, restart once, you can jump directly to the seventh step, test, see not out of the picture.

Of course, if you need to look at the results of the configuration without restarting, you can try the method here.

—————— Light Ink June 16, 2014 note

This step is not written in any of the relevant blog posts describing OpenCV's configuration. Depending on the environment in which these posts are configured, you will often get similar results when running OPENCV-based programs:

The simplest and most brutal way to do this is to copy the associated DLLs into the directory of the Windows operating system. If your Windows is installed on drive C, then the path is C:\Windows. Following the storage environment of my OPENCV, these DLLs are stored in the

D:\Program the Files\opencv\build\x86\vc10\bin directory.

To this directory, "Alt+a" Select All, "Alt+c" copy, and then go to C:\Windows below, "alt+v" copy, simple and rough finished.

Well, the environment configuration is done, let's test the results.

7. The final Test

Just load and display a picture-to-window program for our configuration test.

Create a new console application for the empty project, create a new CPP file, and paste the following code:

[CPP]View Plaincopyprint?
    1. #include <iostream>  
    2. #include  <opencv2/core/core.hpp>   
    3. #include  <opencv2/highgui/highgui.hpp>  
    4.   
    5.   
    6. using namespace cv;  
    7.   
    8.   
    9. Int main ()   
    10. {  
    11.     //  read a picture (original picture of the game)   
    12.      mat img=imread ("pic.jpg");   
    13.     //  Create a "game art" window named     
    14.     cvnamedwindow ("Original picture of the game");   
    15.      //  display the original picture of the game in the window   
    16.     imshow ("Game Original", IMG);   
    17.     //  wait 6000 ms after the window automatically closes   
    18.     waitkey (6000 );   
    19. }  


Place a picture named pic.jpg into the project directory, then click on the "Run" button, if the configuration is successful, will not error, get the expected results of the operation:

For everyone's consideration, or send the project documents, although this time only a few simple code:

"OPENCV+VS2010 Development environment configuration test case by Light ink" download

7. Problems and solutions that may be encountered

Call, life can not be smooth sailing, our configuration process is also. Light ink in the configuration process several times, there are several typical problems, I believe you may appear, you can focus on the list here, I hope to be able to provide you with doubts:

1. Core.h not Found

The problem arises because of the carelessness of the include.

If your version is 2.4.6. Under this version, there is an include under the OpenCV root folder, but when we configure it, it will be his father.

The correct one should fill in the include in the build.

2. Unresolved external commands

The question has been explained above, whether you are a 32-bit or 64-bit operating system, just use the Win32 compiler or the X64 compiler.

In fact, the configuration selection is not directly related to the 64-bit or 32-bit system, but it is the compiler you use when compiling your program.

The compiler is Win32, just use x86

The compiler is X64, just use X64. In general, however, the Win32 X86 compiler is used. So

For both 32 and 64-bit operating systems, it is best to select the x86 version of the configuration file.

3. About the shape of--error lnk2005:xxx has been defined in Msvcrtd.lib (MSVCR90D.dll)

This problem occurs, the static library is not included on the line.

4. Application does not start properly 0xc000007b

LIB contains the issue. Perhaps you include both X86 and X64, or contain errors.

5. Clearly the picture path is right, but load not into the picture, indicating that the pointer is out of bounds, there are unhandled exceptions

Similar errors

This is a OPENCV bug, engineering properties in the case with D and the Lib file without D problem, even if the configuration of the debug and release every time you want to run a manual in the project properties Add. When you get this error, you can change the debug mode, Debug and release interchange:

or open the current project (note that the current project's property page, not the common property page) of the property page, debug or release which error, the corresponding with D or Lib without D is added to the current project properties, "linker", "Input", " Additional Dependencies ".

6. Unable to open file "Opencv_ml249d.lib" series error

About Link:fatal Error LNK1104: Unable to open the file "Opencv_ml249d.lib", in the comment area and people to light ink in the mail is a common mistake. A new solution proposed by ps:jzh258fits students is: Project-property manager->debug| Add the appropriate Lib file directory to the add-in library directory in the General connector, Properties page, Win32->microsoft.cpp.win32.userdirectories. This error is mainly due to the inclusion of the Library directory, and the inclusion of additional dependencies cannot correspond to each other. Perhaps the "Opencv_ml249d.lib" added a space, became "opencv_ml249d." Lib ", you will get an error. In this case, check three aspects: 1. Check the fourth step "4." The configuration of the Project Library (LIB) directory is the correct path in the library directory. 2. Check the fifth step "5. Link library Configuration" in the "Additional Dependencies" format there is no problem, there are no more space, version number 248,249 What there is no problem, there is no more a space, less a dot what.  3. The second step of the environment variable configuration is accurate. —————————— Light Ink April 28, 2014 update

Well, that's probably the OpenCV configuration.

(go) Install OPENCV:OPENCV 2.4.8 or OpenCV 2.4.9 +VS development environment Configuration

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.