"Go" under Windows using VS2008 compile OPENCV 2.1 add Intel TBB and Python support

Source: Internet
Author: User
Tags vc9 delete cache

Add Intel TBB and Python support under Windows using VS2008 compilation OpenCV2.1

Steps:

1. Read the installguide:http://opencv.willowgarage.com/wiki/installguide on the OPENCV website carefully

2. In the "2" Install prerequisite Libraries and Tools, it is mentioned that Python 2.6 or 2.7 is required if you want to support Python calls, and you also need numpy and scipy libraries. To upgrade Python to 2.7, refer to the article "Upgrading Python 2.5 to Python 2.7 under Windows." NumPy and scipy: Http://www.scipy.org/Download, Installation Guide: Http://www.scipy.org/Installing_SciPy/Windows. For users who already have Python installed, download the binary installation package that corresponds to the Python version directly.

3. If you need Intel TBB support, go to Intel TBB homepage to download TBB (note Choosing Windows version). After download, unzip to a directory (do not need to install, assuming the path is the D packing directory), and then the header file path: D:\tbb40_233oss\include,lib file path: D:\tbb40_233oss\lib\ia32\ Vc9 and Bin file path: D:\tbb40_233oss\bin\ia32\vc9 added to the system environment variable. (Note your corresponding platform and version, 64-bit please select INTEL64,VS2005->VC8,VS2010->VC10)

4. Open the CMake GUI (I am using the version CMake2.8), where is the source code and where to build binaries fill in as follows:


Then click on the Configure button, select VS2008 VC9 compiler, CMake will produce a basic configuration, will not be ticked for you with_tbb, so you have to yourself in the middle of the list window to find the WITH_TBB option, and then tick on. If you also want to generate some other project configuration files, such as the example provided by OPENCV, then you also need to tick the corresponding options. Finally click on the Generate button, you will be generated VS2008 corresponding project files. If all goes well, the output in the following text box is as follows:

General configuration for OpenCV 2.1.0 =====================================
Built as Dynamic libs?: On
Compiler:
C + + flags (Release):/dwin32/d_windows/w4/zm1000/ehsc-/gr/d _crt_secure_no_deprecate/d _crt_nonstdc_no_deprecate/d _SCL_SECURE_NO_WARNINGS/GY/MD/O2/OB2/D ndebug/zi
C + + flags (Debug):/dwin32/d_windows/w4/zm1000/ehsc-/gr/d _crt_secure_no_deprecate/d _crt_nonstdc_no_deprecate/d _ Scl_secure_no_warnings/gy/d_debug/mdd/zi/ob0/od/rtc1
Linker flags (Release):/stack:10000000/machine:x86/incremental:no/debug
Linker flags (Debug):/stack:10000000/machine:x86/debug/incremental:yes
Image I/o:
Jpeg:build
Png:build
Tiff:build
JPEG 2000:build
Interfaces:
Old python:0
Python:on
Python Interpreter:d:/python27/python.exe
Python numpy:1
Use Ipp:no
Use Tbb:yes
Build Documentation 0
Install path:d:/opencv2.1
Cvconfig.h is in:d:/opencv2.1
-----------------------------------------------------------------
Configuring done

Note that if you have previously used cmake to compile OpenCV, click Delete Cache under the File menu to remove the cached file so that you do not configure the update. I encountered in the installation process, obviously has modified the path of Python 2.7 path, but the result of configure is still pointing to the original Python2.5 path of the problem.

5. Open VS2008, and then open the OpenCV.sln solution file that you just generated (under the Where to build binaries path) to generate the debug and release versions, respectively.
Note: During the build of the debug version of the Cvpy project, you are prompted not to find the Python27_d.lib import library. To view the additional dependencies, input, and so on for the Cvpy project properties, we will find that the imported libraries you have filled in are D:\Python27\libs\python27.lib (paths may be different). In other words, CMake already knew that we did not provide the debug version of Python27.lib in the Python2.7 installation package, so we chose the release version of Python27.lib (note that the release repository of the third party can be linked during the debug build process. Just the corresponding library does not provide debugging information, why still can not find Python27_d.lib error? The reason is that the source file cv.cpp of the Cvpy project contains the Python.h file, and the Python.h file contains the Pyconfig.h file, and in the Pyconfig.h file there is a selection code for the import library specifically for the VS platform:

/* For a MSVC DLL, we can nominate the. lib files used by extensions */
#ifdef Ms_coredll
# ifndef py_build_core/* Not building the Core-must is an ext */
# if defined (_msc_ver)
/* MSVC users need not specify the. lib file in
Their Makefile (other compilers is generally
Taken care of by Distutils.) */
# ifdef _DEBUG
# pragma comment (lib, "Python27_d.lib")
# Else
# pragma comment (lib, "Python27.lib")
# endif/* _DEBUG * *
# endif/* _msc_ver * *
# endif/* py_build_core * *
#endif/* Ms_coredll */

So in the process of generating the debug version, the linker will look for the Python27_d.lib file.
The solution:
1) Modify the Pyconfig.h file to change the pragma comment (lib, "Python27_d.lib") to pragma comment (lib, "Python27.lib")
2) Download the Python27_d.lib and Python27_d.dll files. Put the Python27_d.lib file in the D:\Python27\libs\ directory and place the Python27_d.dll under the C:\Windows\System32 path. Then modify the additional dependencies in the project properties: D:\Python27\libs\python27.lib is D:\Python27\libs\python27_d.lib. (It is recommended that you compile the Python debug library or use the first method, because it is possible because of the platform or Python version, the library provided above does not work properly, there are mismatch and other error conditions)

6. Add the path to the generated Cv.pyd file (D:\OpenCV2.1\lib\Release or D:\OpenCV2.1\lib\Debug, depending on the version you need to use) to the Python library path.

7. Test, open cmd (command line), run under D:\OpenCV2.1\samples\python path: Python delaunay.py, you will see the result as shown in the run:)

"Go" under Windows using VS2008 compile OPENCV 2.1 add Intel TBB and Python support

Related Article

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.