[OpenCV tutorial] install OpenCV: OpenCV 3.0, OpenCV 2.4.8, OpenCV 2.4.9 + VS Development Environment configuration, opencv2.4.8

Source: Internet
Author: User

[OpenCV tutorial] install OpenCV: OpenCV 3.0, OpenCV 2.4.8, OpenCV 2.4.9 + VS Development Environment configuration (to), opencv2.4.8

This series of articles is produced by @ simple ink _ Mao yunxing. Please indicate the source for reprinting. 

 

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

 

Author: Mao yunxing (Shimo)Weibo: http://weibo.com/u/1723155442

Email:Happylifemxy@163.com

Know: http://www.zhihu.com/people/mao-xing-yun

OpenCV versions used for writing current blog posts: 2.4.8, 2.4.9, and 3.0 (The configuration of OpenCV 2.4.9 was updated on April 9, April 28, 2014.Updated the configuration of OpenCV September 12, 2014 in 3.0.

September 12, 20146th revisions completed)

 

The configuration of OpenCV2.4.9 is almost the same as that of 2.4.8. The only difference is that in step 5 of the following section, you can change the configuration of the Link Library to 248.

The OpenCV 3.0 configuration is simplified. The difference from 2.4.8 and 2.4.9 is the fifth step below.

Opencv_ts300d.lib and opencv_world300d.lib (debug Library)

Or opencv_ts300.lib and opencv_world300.lib (release library.

 

---------------------------- Note on June 1, September 12, 2014

 

 

Because image processing is the research direction during the study period, during this period, simple ink studied a lot of OpenCV and image processing related knowledge and content. Seeing that I have accumulated a certain degree, I decided to open this OpenCV series column, summarize what I have learned, and share my knowledge with you. Well, this article, as the departure of OpenCV, naturally introduces the configuration of the development environment of OpenCV systematically. Simple ink has experienced the configuration of OpenCV 2.4.6, OpenCV 2.4.7, and OpenCV 2.4.8 versions, and sometimes involves the conversion between the three versions, therefore, I still have some understanding of the OpenCV configuration. I hope that you will be able to understand some of the components. Or release the test diagram later (if you want to save it as this image and use the Code provided later in the article for testing, note that the suffix should be jpg instead of jpeg or other): Then, let's get started. 1. download and install the OpenCV SDK

Not to mention VS2010, it must have been installed. Download and install the latest OpenCV version 2.4.8 (February 24, 2014) and 2.4.9 (April 2014. It is better to Extract files than install files, because the downloaded exe installation file is a self-extracting program.

 

Go to the official website: http://opencv.org/and find the opencv windows version to download it.

 

After downloading the file OpenCV 2.4.X, double-click it and you will be prompted to decompress it to a certain place. We recommend that you put it under D: \ Program Files \, for example, D: \ Program Files, (because the root directory is OpenCV when the opencv project files are packaged, we do not need to create a folder named opencv and decompress it. That's all about it) click the Extract button.

After a while, the OpenCV2.4.8 Files of more than three G types are decompressed to D: \ Program Files.

The build contains files related to OpenCV. If we only use OpenCV, we only need to manage the content in the build. The following sources folder is annoying. You can delete it if it occupies hard disk space. However, you must note that the official sample set, that is, the sample program in the samples folder, is located in the sources folder. Therefore, if you really want to delete the sample program, you can still think clearly. Source code is in sources. You can view it directly. How to generate the sln solution simple ink described in this blog: [OpenCV getting started tutorial 7] Go to OpenCV source code: Generate OpenCV engineering solution and OpenCV source code compilation 2. Configure Environment Variables

 

The configuration method in this step is as follows:

Computer> Properties> advanced system Settings> advanced) ]-> [environment variable]-> "double-click" PATH in the system variable-> Add the corresponding PATH to the variable value.

<1>

<2>

<3>

<4>

<5>

 

For 32-bit systems, add:

";...... Opencv \ build \ x86 \ vc10 \ bin "(separated from the previous environment variables with the Semicolon)

 

For 64-bit systems, you can add both:

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

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

In this way, you can easily switch back and forth between the Win32 and X64 compilers ~

 

For example

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

 

PS: Some kids shoes said that 64-bit systems only need to be added "...... Opencv \ build \ x86 \ vc10 \ bin ". You can try it.

 

Note: The variable value is actually the path of the bin folder; D indicates that OpenCV is installed on the D disk; X64 indicates that the operating system environment is 64-bit. If it is installed on a 32-bit system, it should be X86; vc10 indicates that the compiling environment is Microsoft Visual Studio 2010. You are advised to log out of the system after the variable is added.

 

 

 

 

 

3. Configure the include directory of the project

Many of the blog posts I have read mentioned that "re-configuration is required for each new project." In fact, this is not necessary.

First, create a console application in Visual Studio. It is best to leave the project blank.

(Considering that the children's shoes read this blog post seldom come into contact with vs, here I will detail the process-Note on June 11, 2014)

<1> open visual studio, create a win32 console project, and name it, for example, test1. Select the path and click OK.

<2> click "Next ".

<3> check the project above.

<4> right-click solution resource manager's source file and choose add> New to create a cpp source file in the project.

<5> select the C ++ source file and name it, for example, "main", and click "add". Then, a new cpp file is added to the project.

<6> anyone who has read the relevant blog posts on DirectX configuration before Shimo should know that there is a trick called property manager. A configuration in the property manager is equivalent to a general configuration process. You do not need to reconfigure the newly created Project.

Click <View> -- <Property Manager> in the menu bar, and an additional Property Manager workspace is displayed in visual studio.

 

<7> in the new "Property Manager" workspace, click Project> Debug | Win32> Microsoft. Cpp. Win32.userDirectories (right-click Properties or double-click Properties) to open the properties page.

 

 

 

 

<8> after the attribute page is opened, the configuration is completed. First

[General Attributes]-> [VC ++ Directory]-> [include directory]

Add

D: \ Program Files \ opencv \ build \ include

D: \ Program Files \ opencv \ build \ include \ opencv

D: \ Program Files \ opencv \ build \ include \ opencv2.

Of course, this is the case when we decompress OpenCV to D: \ Program Files. The actual path depends on the directory to which the OpenCV is extracted and adjusted according to your actual situation.

 

 

 

 

 

 

4. Configure the project 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 to open the property page.

Next, go to [general attributes]> [VC ++ Directory]> [library Directory,

Add the path D: \ Program Files \ opencv \ build \ x86 \ vc10 \ lib. (It is better not to copy and paste the PATH provided by the simple ink, but to specify it in the preview, which will be much more accurate)

 

(Thanks to Xiao ruifeng's shoes, there are only a few spaces in the previous path D: \ Program Files \ opencv \ build \ x86 \ vc10 \ lib, directly copy the shoes in the above path provided by the light ink, and the following error occurs: "cannot open error 1 error LNK1104: cannot open the file" opencv_calib3d248.lib ", which has been corrected)

------ On September 16, April 3, 2014

 

Selecting x86 or x64 is often confusing. Of course, for 32-bit operating systems, it is up to x86.

If it is a 64-bit operating system, many children's shoes will choose x64 intelligently. The correct understanding is as follows:

 

 

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

In fact, there is no direct relationship between the configuration and the 64-bit or 32-bit system, but the compiler that you use when compiling your program.


 

The compiler selects win32 and uses x86.

If the compiler selects X64, X64 is used. However, generally, the win32 X86 compiler is used. Therefore, whether it is a 32-or 64-bit operating system, it is best to select the x86 version of the configuration file.

 

In addition, vc10 indicates vs2010. If it is another version of visual studio, You need to tune it slightly.

Thanks to jbomb kids shoes. Here we provide the complete complement: vc8 = Visual Studio 2005, vc9 = Visual Studio 2008, vc10 = Visual Studio 2010, vc11 = Visual Studio 2012, vc12 = Visual Studio 2013.

 

 

 

 

 

5. Configure the Link Library

 

In the "Property Manager" workspace, click Project> Debug | Win32> Microsoft. Cpp. Win32.userDirectories to open the properties page. [General Attributes]-> [linker]-> [input]-> [additional dependencies]

 

For [OpenCV2.4.8], add the lib of the following 248 version (in this Order, the lib of 19 debug Versions with d is written in front, 19 release libraries without d are written below ):

 

 

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 lib of the following 249 version (in this Order, the lib of 19 debug Versions with d is written before, 19 release libraries without d are written below ):

 

 

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 names of all lib library files under the OpencV Directory D: \ opencv \ build \ x86 \ vc10 \ lib that we decompressed previously; 248 indicates that our OpenCV version is 2.4.8. If the configurations of other versions are changed here, for example, the opencv_calib3d248d.lib here is changed to opencv_calib3d246d.lib.

The Debug file library name ends with "d" and does not have "Release", for example, opencv_ts248d.lib (lib of the debug version) and opencv_ts248.lib (lib of the release version)

However, I usually write all the items with and without d here, because this is a public property that will be inherited when all projects are created in the future.

 

For [OpenCV 3.0], adding lib of version 3.0 is very simple. To use the debug library, add

Opencv_ts300d.lib

Opencv_world300d.lib.

To use the release library, add

Opencv_ts300.lib

Opencv_world300.lib.

 

In fact, for the new version of OpenCV that has been released and will be released in the future, you only need to check the Libraries under opencv \ build \ x86 \ vc10 \ lib and add them as dependencies.

 

 

 

 

In addition, note: according to the above configuration, it may be possible to run in debug but not in release (due to string reading problems, the parts cannot be loaded, pointer out of bounds, memory errors, etc.). This is a bug in OpenCV since 2.4.1.

Solution: If you want to run the program results in the release mode, in the project's release mode, the lib without d (19 in all) add to project> Properties (note that the property page of the current project is opened here, we only need to release version (that is, without d) -> [configuration properties]-> [linker]-> [input]-> [additional dependencies.

 

------ November March 17, 2014 Note & updated on December June 11, 2014

Similar errors

 

 

 

 

 

6. Add the OpenCV Dynamic Link Library to the Windows folder.

PS: After hellofuturecyj, you will be reminded that if you configure the environment variables accurately and the configuration is restarted, this step is not necessary. That is, after completing the configuration in step 5 above and restarting once, you can directly jump to Step 7 for testing.

Of course, if you need to check the configuration result immediately without restarting, you can try the method here.

------ June 16, 2014 note

 

This step has not been written in any blog related to the configuration of OpenCV. Based on the Environment configured in these blog posts, when running a program based on OpenCV, the following results are often obtained:

 

 

The simplest and most crude method to this problem is to copy all related dll files to the Windows operating system directory. If your Windows is installed on drive c, the path is c: \ Windows \ System32. According to the storage environment of my OpenCV, these dll files are stored in

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

 

In this directory, [Alt + A] Select All, [Alt + C] copy, then go to c: \ Windows \ System32, [Alt + V] copy, simply and roughly done.

PS: For Windows 8, it should be placed in the SysWOW64 folder.

 

 

Well, the Environment configuration is complete. Let's test the result ~

 

 

 

 

7. Final Test

 

Use the program to load and display an image to the window for our configuration test.

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

 

[Cpp]View plaincopyprint?
  1. # Include <iostream>
  2. # Include <opencv2/core. hpp>
  3. # Include <opencv2/highgui. hpp>
  4. Using namespace cv;
  5. Int main ()
  6. {
  7. // Read an image (original game image)
  8. Mat img = imread ("pic.jpg ");
  9. // Create a window named "game source image"
  10. NamedWindow ("Game Original painting ");
  11. // Display the original game image in the window
  12. Imshow ("Game Original painting", img );
  13. // Wait 6000 ms before the window is closed automatically
  14. WaitKey (1, 6000 );
  15. }


 

Place an image named pic.jpg in the project directory and click "run". If the configuration is successful, no error is reported. Expected running results are displayed:

 

For your consideration, please send the project file, although this time only has a few simple codes:

 

[OpenCV + VS2010 Development Environment configuration test case by light ink] Download

 

 

 

7. Possible Problems and Solutions

 

Call, life cannot be smooth sailing, and our configuration process is also. Several typical problems have occurred in the configuration process of simple ink. I believe you may have these problems. Let's list them here, hoping to help you solve them:

 

1. core. h not found

This problem occurs because include is careless.

If your version is 2.4.6. In this version, there is an include under the opencv root folder, but we will be confused if it is included in the configuration.

The include in the build should be entered correctly.

 

2. External commands that cannot be parsed

This problem is actually explained above. Whether you are a 32-bit or 64-bit operating system, you only need to use the win32 compiler or X64 compiler.

In fact, there is no direct relationship between the configuration and the 64-bit or 32-bit system, but the compiler that you use when compiling your program.

 

If the compiler is win32, x86 is used.

If the compiler is X64, X64 is used. However, generally, the win32 X86 compiler is used. So,

For 32-bit or 64-bit operating systems, it is best to select x86 for the configuration file.

 

3. For example, -- error LNK2005: xxx has been defined in msvcrtd. lib (MSVCR90D. dll ).

If this problem occurs, just remove the static library.

 

4. the application cannot start 0xc000007b normally.

Lib. Maybe you have both X86 and X64, or you have encountered an error. Or for windows 8 64-bit, dll should be placed in the SysWOW64 folder at the same level as the System32 folder.

 

5. When the image path is correct but cannot be loaded into the image, the system prompts that the pointer is out of bounds and there is an unhandled exception.

Similar errors

 

This is a bug in opencv. In the project attributes, there are additional dependencies on lib files with and without d, even if the configuration is complete, you have to manually add it to the Project Properties each time you want to run both debug and release. When such an error occurs, you can change the debugging method. debug and release are exchanged:

 

 

Or open the property page of the current project (note that the property page of the current project is not a general property page), debug or release which reports an error, add the corresponding lib with or without d to ["current" project properties]-> [linker]-> [input]-> [additional dependencies ]. you can.

 

Another Error in question 5: Image suffix

I used to configure the OpenCV environment as I did when I was reading this article and reported this error all afternoon. At last, I showed him the problem with the image suffix. Here I will update it to avoid having to get no results because of this problem. Make sure that the image you load is exactly the same as the imread path, name, and Suffix in the code. Error. ". Then, I will change the version 1.jpg of the student code to version 1.jpeg. "The result is immediately displayed. Maybe this is another reason why some friends cannot make the results.

----------------------- Added on June 1, September 20, 2014

 

 

 

6. The file "opencv_ml249d.lib" series cannot be opened.

 

 

LINK: fatal error LNK1104: the file "opencv_ml249d.lib" cannot be opened, which is a common error in the comment area and emails sent to shemo. PS: a new solution proposed by jzh258fits is: Project-> Property Manager-> Debug | Win32-> Microsoft. cpp. in Win32.userDirectories, choose Properties> connector> General, and add the corresponding lib file directory to the additional library directory. This error is mainly caused by the fact that the included library directory cannot correspond to the included dependencies. It may be because "opencv_ml249d.lib" adds a space and becomes "opencv_ml249d. lib", and an error is reported. When this problem occurs, check three aspects: 1. Check whether the paths in the library directory are accurate in Step 4, "4. Configure the project library (lib) directory. 2. check Step 5 "5. is there a problem in the format of "add dependencies" in the configuration of the Linked Library? Is there any problem with multiple spaces, version 248,249 or something? Is there one more space and one less point. 3. Check whether the environment variable configuration in step 2 is correct. ---------- Updated on August 1, April 28, 2014

 

Well, this is probably the configuration of OpenCV.

For the next article, see :)

 

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.