OPENCV Learning: opencv2.4.8+vs2010 Development Environment Configuration

Source: Internet
Author: User
Tags unpack visual studio 2010

Beginner OpenCV, about OPENCV environment configuration, search on the Internet a lot of methods, finally own finally fix, commemorate a bit ...

The process of configuration is affected by a blog post, the blog is very clear, hereby reproduced, and share with you!!!!!

This series of articles is written by zhmxy555 (Mao), please specify the source.

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

Mao (Light ink) e-mail: [email protected]

When writing the current blog post, use OPENCV version: 2.4.8

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. For the current download and installation of the latest OPENCV version 2.4.8 (February 24, 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 the file OpenCV 2.4.8, 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. Want to see the full source code needs to use CMake to "unpack", How to "unpack" everyone Baidu can, or the next light ink to speak specifically.   There's not much to say here first. 2. Configure Environment variables

Oddly enough, the three versions of the OpenCV are stored in different directories of the hard drive when the OpenCV 2.4.6,OPENCV 2.4.7,OPENCV 2.4.8 three versions. But I haven't moved the environment variables in this step, perhaps the new version of OPENCV has weakened the configuration of environment variables. So, you can skip this step, if the final configuration out of the error, you can consider the actual situation to add this step configuration.

This step is configured as follows:

(Double-click), environment variable, advanced system settings, computer---(right) properties (user, path in system), add the appropriate path to the variable value.

For 32-bit systems, add:

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

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:\programfiles\opencv\build\x86\vc10\bin

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. When the variable is added, you need to log off the system before it takes effect.

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.

Look at my previous DirectX configuration of the relevant blog friends should know that there is a trick called the property manager, click into the

< View >--< Property manager >

In the newly-emerged 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).

Once you've opened the familiar Properties page, it's a configuration. The first is in

"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 the 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| You can open the Properties page by Win32->microsoft.cpp.win32.userdirectories (the inverse key attribute, or double-click). "Common Properties", "VC + + Directory", "Library directory".

Add the path to the D:\ProgramFiles\opencv\build\x86\vc10\lib.

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.

5. Configuration of the link library

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

Add the following content:

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_ml248d.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_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

Note that the pasted content will be the name of all Lib library files under 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 and Opencv_ts248.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: According to the above way to configure, may appear under the debug can run but the release cannot run the situation (the tablets are not loaded, reported memory error), this is OpenCV since 2.4.1 a bug. If this occurs, 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".

—————— Light Ink March 17, 2014 note

Similar errors

6. Add OpenCV dynamic link library under Windows folder

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 Plaincopy
  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. Cvnamedwindow ("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:

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


Well, that's probably the OpenCV configuration.

See the following article:)

(GO) OpenCV Learning: opencv2.4.8+vs2010 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.