[技术| 编程·课件·Linux] [数字图像处理]在VS2008下安装openCV

admin · 发布于 2012-12-10 14:12 · 3001 次阅读
1
注意点: @admin 补充
下面这篇installation guide是针对vs2008和openCV 2.2版本进行的编译和配置,以前admin在安装2.2的时候没遇到问题,但是今天admin在opencv2.4.3进行实际编译和配置过程中遇到了几个问题
1.利用cmake编译opencv所在的文件夹的时候,以前生成部分全在目标文件夹中的,本次却有一部分在待编译的文件夹中。或者此次直接将目标文件放在已经存在的build文件夹中
2.添加系统环境变量Path,记得不要覆盖或者直接用Path名字,会覆盖掉,而是要在后面加分号”;”,追加新的环境变量值。例如指定系统环境变量path的bin文件夹,以前位于编译指定的文件夹中,此次却是D:\OpenCV\opencv2.4.3\build\x86\vc10\bin,注意!
3.无论是下面的这份中文文档还是英文文档,对于安装和配置的说明都没有更新到2.4.3最新。基本是2.2为蓝本进行说明的,但是实际上,2.4.3个某些lib文件夹的位置已经变更了。如果opencv的根目录下的lib文件夹已经不存在,而在相应的编译文件夹中或者build文件夹中,如果不确定是哪个,那么就把两个的lib或者include都给追加上。基本就可以调试成功。


最后,如果有哪位opencv大虾对这块配置搞的比较清楚的话,欢迎指教。
尤其是在用cmake-gui进行编译的时候,生成的文件夹是利用现有的build文件夹呢,还是自己建立一个,例如vs2008呢。如果利用现在的build文件夹的时候,那么在对生成的opencv.sln文件的中opencv工程进行rebuild的时候,其中有失败的选项(1失败,debug模式下)。但是,如果是新建的文件夹,那么55个全部编译成功。
不过,新建编译目标文件夹vs2008后,虽然可以编译成功,但是其中也有点问题,例如include文件中无opencv及opencv2文件夹。

2012.12.11 更新
=======================
【原创】在VS2008下安装openCV



今天终于把openCV安装好了,安装的是最新版本openCV2.2,使用的是VS2008。安装流程如下:准备软件:
在安装openCV之前,首先要保证机器中安装了以下软件:
1,C/C++编译器。我使用的是visual-Studio2008 Professional,当然使用VC++2008也是可以的。
2,安装CMake2.6或者最新版本。下载地址: http://www.cmake.org/cmake/resources/software.html 下载 Windows (Win32 Installer) 安装。
3,安装OpenCV2.2. 下载地址: http://www.opencv.org.cn/index.php/Download,要记住你自己的安装路径,我的安装路径是:D:/study/openCV/OpenCV2.2.

使用CMake编译openCV:
安装了以上3个软件后,就需要使用CMake编译openCV了
1,  运行cmake-gui,在where is the source code中填入你的openCV路径:D:/openCV/OpenCV2.2;where to build the binaries中填入你要存放编译结果的路径:D:/openCV/OpenCV2.2/vs2008。
2, 点configure,在弹出的对话框中选择Visual Studio 9 2008 。
3,如果有红色框显示,继续点击configure。
4,configure完成之后,点击generate。
上述步骤完成之后,在vs2008文件夹中,就会看到有OpenCV.sln文件。

编译OpenCV Debug和Release版本库:
使用VS2008打开OpenCV.sln文件,在Debug下,选择OpenCV.sln文件,然后进行如下操作:
在Debug下,选择Solution Explorer里的 Solution OpenCV,点右键,运行"Rebuild Solution";如编译无错误,再选择INSTALL项目,运行"Build"。

配置Windows环境变量:
将D:\openCV\OpenCV2.2\vs2008\bin加入到系统环境变量Path中。这个应该都会的吧。
右键我的电脑->属性->详细设定标签里设置
注意:opencv2.4.3则是将D:\OpenCV\opencv2.4.3\build\x86\vc10\bin添加到环境变量中,请注意!!!

add <cmake_binary_dir>\bin\Release, <cmake_binary_dir>\bin\Debug (containing "opencv_core*.dll" and "opencv_core*d.dll", respectively) to the system path (My Computer--[Right button click]-->Properties->Advanced->Environment Variables->Path)

为VS2008 配置openCV环境:
1 打开VS 2008,菜单 Tools -> Options -> Projects and Solutions -> VC++ Directories
2 在Show directories for中,选择include files,加入目录 D:\openCV\OpenCV2.2\ include\opencv,和D:\openCV\OpenCV2.2\ include
3 在show directories for中,选择library files,加入目录 D:\openCV\OpenCV2.2\ lib
openCV使用:
1 打开VS 2008 Express,创建一个Win32控制台程序openCVhello;
2 选择Solution Explorer里的openCVhello项目,点击鼠标右键,选择Properties,选择Linker中Input。
3 在Additional Dependencies 中添加如下目录:
D:\openCV\OpenCV2.2\vs2008\lib\opencv_core220d.lib D:\openCV\OpenCV2.2\vs2008\lib\opencv_highgui220d.lib D:\openCV\OpenCV2.2\vs2008\lib\opencv_video220d.lib D:\openCV\OpenCV2.2\vs2008\lib\opencv_ml220d.lib D:\openCV\OpenCV2.2\vs2008\lib\opencv_legacy220d.lib D:\openCV\OpenCV2.2\vs2008\lib\opencv_imgproc220d.lib
4 openCVhello的程序如下:
// openCVhello.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
     // open the file
     IplImage *img = cvLoadImage("ant1.jpg");
     if (!img)
     {
         printf("Error: could not open the image file.\n");
         return 1;
     }
     // display the image
     cvNamedWindow("Image:",CV_WINDOW_AUTOSIZE);
     cvShowImage("Image:",img);

     // wait for the user to press a key in the GUI window
     cvWaitKey(0);

     // Free the resourse
     cvDestroyWindow("Image:");
     cvReleaseImage(&img);

     return 0;
}
这样,就可以成功运行~祝大家好运~

如果有不清楚的,可以参看官方网站:http://opencv.willowgarage.com/wiki/VisualC%2B%2B
一般,按照上述步骤就可以安装成功的,我在xp上可以成功安装,但在win7上遇到了问题,出现mscvp100d.dll不存在,出现异常,试论很多方法后都不能解决,最后一个很简单的方法搞定了:将vs2008中的bin文件夹中所有的.dll文件和lib文件夹中的所有.lib文件拷到OpenCV2.2对应的文件夹中,覆盖其相同文件,就可以了成功运行了~遇到同样问题的可以试一下~

出处:http://renguangmei868.blog.163.com/blog/static/3702126620101123103344478/
==========
配置环境之英文官方文档:
Building your own projects using OpenCV 2.2 in Visual Studio
After you have compiled the OpenCV 2.2 library using CMake, you should configure your Visual Studio projects to use OpenCV.
For the below instructions its assume that you installed OpenCV to the default location C:\OpenCV2.2 - if you selected something different (e.g. C:\Program Files\OpenCV2.2) then please adjust accordingly.
First of all create your new (full or empty) C/C++ project.
For an application project (*.exe) add this to your project properties:
  • Go to VC++ Directories
  • Add 2 new Include Directories (it's the path where you installed OpenCV, include folder):
    • C:\Program Files\OpenCV2.2\include
    • C:\Program Files\OpenCV2.2\include\opencv
  • Add 1 new Library Directory (it's the path where you installed OpenCV, lib folder):
    • C:\Program Files\OpenCV2.2\lib
  • Go to Linker in the left menu and select Input option
  • Add these entries on Additional Dependencies option:
    • C:\Program Files\OpenCV2.2\lib\opencv_core220d.lib
    • C:\Program Files\OpenCV2.2\lib\opencv_highgui220d.lib
    • C:\Program Files\OpenCV2.2\lib\opencv_video220d.lib
    • C:\Program Files\OpenCV2.2\lib\opencv_ml220d.lib
    • C:\Program Files\OpenCV2.2\lib\opencv_legacy220d.lib
    • C:\Program Files\OpenCV2.2\lib\opencv_imgproc220d.lib
  • Make the content of 'OpenCV_Helloworld.cpp' as such:
For a shared dynamically loadable library project (DLLs) add this to your project properties:
  • C/C++ - General - Additional include Directories:
    • C:\OpenCV2.2\include\opencv;C:\OpenCV2.2\include
  • Linker - General - Additional library Directories:
    • C:\OpenCV2.2\lib
  • Linker - Input - Additonal Dependencies (debug):
    • opencv_core220d.lib opencv_highgui220d.lib opencv_video220d.lib opencv_ml220d.lib opencv_legacy220d.lib opencv_imgproc220d.lib
  • Linker - Input - Additonal Dependencies (release):
    • opencv_core220.lib opencv_highgui220.lib opencv_video220.lib opencv_ml220.lib opencv_legacy220.lib opencv_imgproc220.lib

==================================

英文官方安装文档如下:

OpenCV Installation Guide
Overview:
  • 1) If you want the stable 2.4.0 release of OpenCV, get it here for Windows, Linux or Mac and Android.

    • (Or if you want the latest code being developed each day, get it from our SVN server)

  • 2) Install CMake and some prerequisite libraries.

    • (You can skip this if you just use the pre-built Visual Studio 2008/2010 binaries for Windows).
  • 3) Use CMake to build OpenCV binaries (such as "opencv_core240.dll" or "libopencv_core.so.2.4.0") from the source code.

    • (You can skip this if you use the pre-built Visual Studio 2008/2010 binaries for Windows).
  • 4) Finally you must configure your C/C++ compiler so it knows where to find OpenCV for your projects.

    • (Installation guides for popular compilers are given below).


1) Get the current stable OpenCV version (updated yearly)
  • Windows: run the Windows EXE and tell it where to install OpenCV. Note that prebuilt v2.3 or older packages were only 32-bit and didn't include TBB support (thus you couldn't use multiple cores unless you multithreaded your own application). So it is recommended to rebuild old versions from source code using CMake with the same compiler that you use to build your applications.
  • Linux/MacOSX/other operating systems: download the source tarball (OpenCV-x.y.z.tar.bz2) for building with CMake.
  • Android: visit the Android Wiki page and then follow the tutorial.


Or get the cutting-edge OpenCV from the SVN repository (updated daily)
2) Install Prerequisite Libraries and Tools
Common Prerequisites
  • C/C++ compiler (OpenCV 2.3 is known to work with latest versions of Visual Studio (such as VS2008, VS2010, including Express Editions) and MinGW on Windows, Xcode 3.2 or later on MacOSX, GCC 4.3 or later on Linux and other Unix-like systems). In the case of older compilers you may prefer OpenCV 1.1 instead.
  • CMake 2.6 or later. CMake is now the only method of building OpenCV SVN snapshots.
  • (Optional) Subversion client (e.g. command-line svn tool, SmartSVN, Tortoise SVN)
  • (Optional) Python 2.6.x or 2.7.x (Python 3.x support status is unknown) and Numpy, including the development files: Python.h, ndarrayobject.h etc. in order to build Python wrappers. (Make sure you install Numpy into the same installed version of Python that the OpenCV build uses i.e. run Numpy's setup.py with that Python binary. By default the OpenCV build system will choose the most recent version of Python that it can find, or you can force it to use a specific version using the PYTHON_EXECUTABLE variable when you invoke cmake.)
  • (Optional) Intel TBB to enable parallel code in OpenCV. We do not use OpenMP any longer. Important note: Only TBB 2.2 or later will work. For Ubuntu 9.10 users - you can take libtbb2 and libtbb-dev packages from Ubuntu 10.04 (Lucid Lynx), they are known to install and work flawlessly on 9.10.
  • (Optional) Qt 4.6 or later. You can use Qt as HighGUI backend on any platforms (Windows, Linux, Mac) by passing WITH_QT=ON to CMake when configuring OpenCV. See Qt-OpenCV-Multithreaded for required steps.
  • (Optional) IPP 5.1 to 6.1 (OpenCV 2.3 should also work fine with IPP 7). OpenCV does not require IPP, but can be configured to use IPP to make color conversion, Haar training and DFT functions run faster.
  • (Optional) LiveTeX distribution (or MiKTeX on Windows, MacTeX on Mac) and Sphinx (http://sphinx.pocoo.org) to build the up-to-date OpenCV documentation in PDF or HTML formats.
  • (Optional) The latest CUDA Toolkit to build with GPU support (only available for NVidia GPUs).


Extra Prerequisites (Linux/BSD/other Unix-like OSes)
  • pkg-config. It is used at the configuration stage and also simplifies the further use of OpenCV itself.
  • (Optional) gtk+ 2.x (libgtk2.0-dev) and perhaps the related packages (glib, gthread etc.).

    • This is the default GUI backend for highgui on OSes other than Windows and MacOSX.
  • (Optional) libjpeg, libtiff, libjasper, libpng and zlib, openexr. Install any of those with the associated

    • development packages (libjpeg-dev etc. on Debian/Ubuntu) if you want to use those stock libraries to read and write images in the respective formats, instead of using the versions supplied with OpenCV (openexr is not supplied)
  • (Optional) ffmpeg, libgstreamer, libv4l, libxine, unicap, libdc1394 2.x.

    • You should have some/all of these packages installed (together with associated development packages) to add video capturing, video decoding and video encoding capabilities to highgui. The output of the cmake will show you, which of the packages have been detected and will be used in highgui. (Enable full video support with FFMPEG). For example, on Ubuntu 9.10 all the necessary ffmpeg files can be installed using the following command:

      • sudo apt-get install libavformat-dev libswscale-dev



Extra Prerequisites (MacOSX)
  • Xcode 3.2 or later. It does not only include the required C++ compiler, but also Cocoa, QTKit and other frameworks that make highgui on MacOSX functional. Besides, CMake can generate Xcode projects by the command "cmake -G Xcode", so you can build OpenCV conveniently from within the IDE. Additional information can be found on the Mac_OS_X_OpenCV_Port page.


Extra Prerequisites (Android)
  • See the Android build page for details.


3) Build the OpenCV library from source using CMake and your C++ Compiler
Configure using CMake
  • In general you should:
    • Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, Visual Studio, Xcode or Eclipse etc. project files as well the object files and output binaries. You can do it using CMake GUI.
    • If you use CMake GUI, execute "Configure" to do the initial configuration, then adjust any options, then press "Configure" again and then press "Generate". If you have them installed, turn on TBB and IPP support in order to get a better performance. Also, if you want to build Python wrappers, samples or the reference manual in PDF, you should explicitly turn them on. (It might be wise to try first with all options turned off, and make sure that works first.)
    • If you are using command line, enter the <cmake_binary_dir> and type
    •     cmake [<some optional parameters...>] <path to the OpenCV source directory>
      • You may want instead to use cmake's GUI as follows:
      •      cmake-gui [<some optional parameters...>] <path to the OpenCV source directory>
    • For example, if you downloaded the project to ~/projects/opencv, you can do the following:
    •    cd ~/projects/opencv # the directory containing INSTALL, CMakeLists.txt etc.   mkdir release   cd release   cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
    • That will generate makefiles for the Release configuration and will put them in ~/projects/opencv/release directory.
    • . ~ Note for newbie linux users:
    • Do the cmake step from inside the folder where you want to build OpenCV. It is a good practice to keep your source and build files (the files that are going to be generated after the cmake step) separately. Remember to specify the source folder while invoking cmake as the last argument. Otherwise cmake will scan for CMakeLists.txt file in the usual standard location /usr/local/src and will throw an error. Unzipping all OpenCV directories from the source files to the src folder is not an elegant way of doing things in linux.
    • . If you have a gui version of cmake installed, just do this from inside the build folder, $ ccmake <OpenCV source folder>
    • Another example for Windows users (assuming the .exe extracted files to C:\OpenCV2.4\)
    •    cd C:\OpenCV2.4 # the directory containing INSTALL, CMakeLists.txt etc.   mkdir release   cd release   cmake -D:CMAKE_BUILD_TYPE=RELEASE C:\OpenCV2.4
    • Note that the use of the colon after the -D is required on Windows Vista (include if cmake is giving errors on other Windows distro's as well). If you are using MS Visual Studio cmake exits with an error message "error PRJ0003: Error spawning 'cmd.exe', make sure that you have the correct VC++ Executable Directories set (see here).
    • Using TBB (Optional). If you have TBB installed (see the Prerequisites), turn on WITH_TBB option, adjust the TBB include and library paths if needed. You should see the following message in the CMake output:
    •    USE TBB:  YES
    • Using IPP (Optional). If you have IPP installed on your machine and want to build OpenCV with IPP support, check if IPP is turned on in CMake configuration options and if it was detected. First, look at the CMake output. If it prints
    •    USE IPP:   NO
    • It means that IPP was not turned on or it was not detected. In this case turn it on (USE_IPP=ON) and pass the correct path to IPP shared libraries (IPP_PATH=<...>), like in the example below. While OpenCV currently uses staticIPP libraries, it derives their path from the supplied path to the shared/dynamic IPP libraries.
    •    cmake -D:CMAKE_BUILD_TYPE=RELEASE -D:USE_IPP=ON -D:IPP_PATH="C:\Program Files\Intel\IPP\6.1.031\ia32\bin" C:\OpenCV2.4
    • (It's also easy to do the same using CMake GUI)
    • If you did everything right, you will see the following in the CMake output:   USE IPP:   <ipp_path>
    • If there are multiple IPP versions installed on the machine (not necessarily all of them are in the system path) and you want to use the particular one, different from what CMake has found, just specify the correct IPP_PATH.
    • Using CUDA (Optional). If you have the latest CUDA Toolkit installed (see the Prerequisites), turn on WITH_CUDA option, and verify that all paths and libraries were detected correctly. You should see the following message in the CMake output:
    •    USE CUDA:  YES
    • More information about GPU support in OpenCV can be found here: OpenCV_GPU



Compile using GCC from command line
  • Generate makefiles using CMake (choose "MinGW Makefiles" generator on Windows, "Unix Makefiles" on other OSes) as described above.
  • Enter the output CMake directory (denoted as <cmake_binary_dir> further) and type "mingw32-make" on Windows, "make -j [optional_number_of_threads]" on Unix. Windows users can also run parallel build of OpenCV. To do that, please, define "SHELL" environment variable (My Computer--[Right button click]-->Properties->Advanced->Environment Variables->Path) and set it to "cmd.exe" (without quotes). Then you can run "mingw32-make -j" (note that "-j" must go without any numerical parameter).
  • [Linux, MacOSX] Then you can optionally run "sudo make install" (on Linux or MacOSX). Note, that if you are using CMake (and, therefore, OpenCVConfig.cmake) for your projects, it is not necessary to run "make install". Just use OpenCV from where you built it. And actually this is recommended approach, since it does not pollute system directories with potentially conflicting OpenCV versions.
  • [Windows] If you built OpenCV as dynamic libraries (DLLs), you may want to add <cmake_binary_dir>\bin to the system path (My Computer--[Right button click]-->Properties->Advanced->Environment Variables->Path) to let Windows find "opencv_core240.dll" etc.)


Compile using Visual Studio
  • generate solutions using CMake, as described above. Make sure, you chose the proper generator (32-bit or 64-bit)
  • launch Visual Studio, locate and open the "OpenCV.sln" solution file in your generated build folder (eg: "C:\OpenCV\build\OpenCV.sln"). Select "Debug" configuration, build the solution (Ctrl-Shift-B), and/or select "Release" and build it.
  • add <cmake_binary_dir>\bin\Release, <cmake_binary_dir>\bin\Debug (containing "opencv_core*.dll" and "opencv_core*d.dll", respectively) to the system path (My Computer--[Right button click]-->Properties->Advanced->Environment Variables->Path)


Compile using Xcode
  • generate Xcode project using CMake, as described above.
  • launch Xcode, locate and open OpenCV.xcodeproj. Select "Debug", build the BUILD_ALL target (Cmd-B), select "Release" and build it too.

Building the HTML Documentation
  • Go to the opencv build directory (where cmake will put the library and built sample files etc).
  • Type make html_docs


Testing OpenCV
  • You may turn on "BUILD_EXAMPLES" in CMake GUI or run cmake with "-D BUILD_EXAMPLES=ON" option, then it will include short demo samples to the build. Note that some of them need image files from the original source directory, you may just copy them to the bin directory.
    You can also run correctness tests <cmake_binary_dir>/bin[/debug|/release]/cxcoretest and cvtest.


Testing Python wrappers
  • As long as you build Python wrappers and installed them, you can just enter opencv/samples/python and run the samples, e.g.
  •     python delaunay.py
  • If you want to try Python samples without installing OpenCV, put cv.so and cv2.so (called cv.pyd and cv2.pyd on Windows) to opencv/samples/python directory, or rather add the directory containing cv.so/cv.pyd to PYTHONPATH, e.g.
  •     export PYTHONPATH=~/projects/opencv/release/lib:$PYTHONPATH

4) Configure your own projects to use OpenCV
  • Installation guides are available for:
  • You can use CMake for your own projects, by looking at the Getting_started and FindOpenCV.cmake pages.
  • Or you can add opencv 'include', 'lib' and 'bin' subdirectories to your IDE settings.
  • Or for hand-written Makefiles you can specify the necessary paths and options manually, e.g.:
    •     g++ -o my_example my_example.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy
      • Note that if you build OpenCV statically, you also need to link all the OpenCV dependencies

  • Or you can use pkg-config and the provided "opencv.pc".
    • Make sure that opencv.pc is found by pkg-config:    pkg-config opencv --libs  # should print something like -lopencv_core -lopencv_imgproc ...
    • You can now use it in your Makefiles or build scripts, e.g.:    g++ -o my_example my_example.cpp `pkg-config opencv --cflags --libs`

5) Use OpenCV for state-of-the-art projects!
  • If you are new to OpenCV, you should first read the Beginners FAQ.
  • There are also some info on topics (such as Blob Detection and Face Recognition) in the FAQ Guide.
  • There are some tutorials (such as POSIT 3D Pose Estimation) in Tutorials.
  • There are many sample programs that come with OpenCV in the "samples\c\" folder.
  • The best way to learn how to use OpenCV is to read the O'Reilly book "Learning OpenCV: Computer Vision with the OpenCV Library", that explains many important concepts such as Image Processing, Histogram Matching, Object Tracking, 3D Pose Estimation, Stereo Camera Calibration, Machine Learning, etc.




[size=0.7em]OpenCVWiki: InstallGuide (最終更新日時 2012-05-18 13:16:17 更新者 ShervinEmami


Original URL: http://opencv.willowgarage.com/wiki/InstallGuide
共收到 0 条回复
暂无回复。
回帖
B Color Image Link Quote Code Smilies
Command + Enter
快速回复 返回顶部 返回列表