"One of the OpenCV Getting Started tutorials" Installs OPENCV:OPENCV 3.0, OpenCV 2.4.8, OpenCV 2.4.9 +VS development environment Configuration

Source: Internet
Author: User
Tags visual studio 2010

This article series is produced by the @ Light Ink _ Mao Nebula.  

Article Link: http://blog.csdn.net/poem_qianmo/article/details/19809337

1. Download and install the OpenCV SDKVS2010 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 post in detail:

"OpenCV Introductory Tutorial VII" OPENCV source code: Generate OPENCV Engineering solution with OPENCV source compilation2. Configure 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 ~

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 for Microsoft Visual Studio 2010, note Meaning VS2012 is vc11, if VS2010 is VC10; it is best to log off the system when the variable is added, before it takes effect.

3. The project includes the configuration of the catalog (include) read a lot of blog post said that "every new project to reconfigure", in fact, no such trouble.

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

<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 the "Common Properties", "VC + + Directory", "Include directory"

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

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

Add the path to the D:\Program files\opencv\build\x86\vc10\lib. (vs2012 is VC11)

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.

Complementary complete: VC8 = Visual Studio 2005,VC9 = Visual Studio 2008,VC10 = Visual Studio 2010,VC11 = Visual Studio 2012,VC12 = Visual S Tudio 2013.

5. Configuration of the link library "Common Properties", "linker", "input", "Additional Dependencies"

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.

For "OpenCV 3.0", add 3.0 version of LIB, the new version of Lib is very simple, just add a opencv_ts300d.lib (DEUBG version) or Opencv_ts300.lib (release version of the library).

In fact, for the release and the upcoming release of the new version of OpenCV, just look at the Opencv\build\x86\vc10\lib under the library is which several, added to the dependency on it.

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

Similar errors

6. Add OpenCV dynamic link library under Windows folder

If the configuration environment variable is configured correctly, 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.

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\System32. 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\System32 below, "alt+v" copy, simple and rough finished.

PS: For Windows 8, you want to place it in the SysWOW64 folder.

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:

  1. #include <iostream>
  2. #include <opencv2/core/core.hpp>
  3. #include <opencv2/highgui/highgui.hpp>
  4. Using namespace CV;
  5. int main ()
  6. {
  7. //Read in a picture (original picture of the game)
  8. Mat Img=imread ("pic.jpg");
  9. //Create a window named "Game Art"
  10. Namedwindow ("original picture of the game");
  11. //Display the game's original picture in the window
  12. Imshow ("game original Painting", IMG);
  13. //Wait for 6000 Ms after the window is automatically closed
  14. Waitkey (6000);
  15. }

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.

7. Problems and solutions that may be encountered 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.

Compiler is Win32, use x86, compiler is X64, 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 version x86.

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 have both X86 and X64, or contain errors. Or, for Windows 8 64-bit, the DLLs are placed in the SysWOW64 folder sibling to the System32 folder.

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 a classmate 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 caused primarily by the inclusion of the Library directory, and the inclusion of additional dependencies that do not 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.

"One of the OpenCV Getting Started tutorials" Installs OPENCV:OPENCV 3.0, OpenCV 2.4.8, 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.