VS2010平台下OpenCV 248编译和安装

这次安装OpenCV算是对windows下的系统路径设置有了更深的了解,还用CMake编译了OpenCV源码。OpenCV官方的系统路径设置方法:

Set the OpenCV enviroment variable and add it to the systems path
First we set an enviroment variable to make easier our work. This will hold the build directory of our OpenCV library
that we use in our projects. Start up a command window and enter:
setx -m OPENCV_DIR D:\OpenCV\Build\x86\vc10 (suggested for Visual Studio 2010 - 32 bit Windows)
setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc10 (suggested for Visual Studio 2010 - 64 bit Windows)
setx -m OPENCV_DIR D:\OpenCV\Build\x86\vc11 (suggested for Visual Studio 2012 - 32 bit Windows)
setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc11 (suggested for Visual Studio 2012 - 64 bit Windows)
Here the directory is where you have your OpenCV binaries (extracted or built). You can have different platform (e.g.
x64 instead of x86) or compiler type, so substitute appropriate value. Inside this you should have two folders called
lib and bin. The -m should be added if you wish to make the settings computer wise, instead of user wise.


If you built static libraries then you are done. Otherwise, you need to add the bin folders path to the systems path. This
is cause you will use the OpenCV library in form of “Dynamic-link libraries” (also known as DLL). Inside these are
stored all the algorithms and information the OpenCV library contains. The operating system will load them only on
demand, during runtime. However, to do this he needs to know where they are. The systems PATH contains a list of
folders where DLLs can be found. Add the OpenCV library path to this and the OS will know where to look if he ever
needs the OpenCV binaries. Otherwise, you will need to copy the used DLLs right beside the applications executable
file (exe) for the OS to find it, which is highly unpleasent if you work on many projects. To do this start up again the
Path Editor and add the following new entry (right click in the application to bring up the menu):
%OPENCV_DIR%\bin

Save it to the registry and you are done. If you ever change the location of your build directories or want to try out your
applicaton with a different build all you will need to do is to update the OPENCV_DIR variable via the setx command
inside a command window.


这样比打开windows管理-》高级系统设置-》环境变量 再设置方便不到哪去,但是这样直接写到注册表,不用再重启电脑了是不是很爽啊。里面还推荐了一个软件,Path Editor,http://patheditor2.codeplex.com/ 


附加依赖项:

在VS2010中建立一个新项目fitting,在项目上右键属性,配置项目属性。

                 (1)Debug/Win32

                  配置属性-->VC++目录 需要编辑增加路径如下(先新建路径,再找到相应目录,点击应用)

                                      可执行文件目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\bin

                                      包含目录:D:\Program Files\opencv-2.4.8\install\include;

                                                        D:\Program Files\opencv-2.4.8\install\include\opencv;

                                                        D:\Program Files\opencv-2.4.8\install\include;

                                      引用目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\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_ml248d.lib
                                       opencv_nonfree248d.lib
                                       opencv_objdetect248d.lib
                                       opencv_photo248d.lib
                                       opencv_stitching248d.lib
                                       opencv_ts248d.lib
                                       opencv_video248d.lib
                                       opencv_videostab248d.lib

                (2)Release/Win32

                  配置属性-->VC++目录 需要编辑增加路径如下(先新建路径,再找到相应目录,点击应用)

                                      可执行文件目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\bin

                                      包含目录:D:\Program Files\opencv-2.4.8\install\include;

                                                        D:\Program Files\opencv-2.4.8\install\include\opencv;

                                                        D:\Program Files\opencv-2.4.8\install\include;

                                      引用目录:D:\Program Files\opencv-2.4.8\install\x86\vc10\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
                                       opencv_nonfree248.lib
                                       opencv_objdetect248.lib
                                       opencv_photo248.lib
                                       opencv_stitching248.lib
                                       opencv_video248.lib
                                       opencv_video248.lib
                                       opencv_videostab248.lib



参考:

http://blog.csdn.net/wlq19910603/article/details/19824655

http://www.cnblogs.com/jhzhu/p/3216840.html



要点:
           1) XP+ Visual Stuio 2010 + OpenCV-2.4.2.exe + cmake-2.8.8-win32-x86.exe 
           2) 如何CMake OpenCV源代码得到可编译的VS2010项目
           3) 如何使用VS2010编译OpenCV源码
           4) 如何配置OpenCV工程

1. 下载OpenCV 安装包

2. 解压安装包
    双击OpenCV-2.4.2.exe 解压,比如解压安装到C:\openCV_extract
    【这里面是OpenCV自带的dll库,无法用来在VS中调试OpenCV,所以需要使用CMake重新编译】

3.  安装CMake
     cmake-2.8.8-win32-x86.exe ( http://www.cmake.org/cmake/resources/software.html

4. CMake OpenCV
    源代码选择OpenCV安装目录C:/openCV_extract/opencv
    Build目录可以设置为C:/openCV-extract/opencv_build
    点击Configure
    完成后,出现红色背景,
    勾选 BUILD_SHARED_LIBS,BUILD_TESTS,OPENCV_BUILD_3DPARTY_LIBS,以及下面的WITH_JASPER,WITH_JPEG,WITH_PNG, WITH_TBB(一般这个没默认选上), 和WITH_TIFF选项
    点击Generate
    

5.  编译CMake出来的工程
    (1)打开C:/openCV-extract/opencv_build目录下的VS2010工程文件OpenV.sln
    (2)分别使用Debug和Release模式,编译生成。
    (3) 复制opencv_build目录下的bin和lib文件夹,到C:\openCV_extract\opencv目录下
              复制opencv\build\include 目录下的两个文件夹,到opencv\include 下,覆盖。
             
    这样得到的库文件,就可以被VS2010调用了。
      
6.  配置系统环境变量
    在PATH变量中添加:
    C:\openCV_extract\opencv\build\x86\vc10\bin;C:\ openCV_extract \opencv\bin\Debug\;C:\ openCV_extract \opencv\bin\Release\

7.  新建Win32工程,配置工程属性
     (1)VC++ Directories 下的Include Directories 
        (bin\debug可以不用加)
        
      (2)VC++ Directories 下的Library Directories 
             Debug模式为:lib\Debug
             Release模式为:lib\Release
         
     
      (3)添加库文件  Linker --> Input --> Additional Dependencies  (注意:lib文件名根据不同的opencv版本而定)
        Debug模式添加:
             opencv_calib3d242d.lib
opencv_contrib242d.lib
opencv_core242d.lib
opencv_features2d242d.lib
opencv_flann242d.lib
opencv_gpu242d.lib
opencv_haartraining_engined.lib
opencv_highgui242d.lib
opencv_imgproc242d.lib
opencv_legacy242d.lib
opencv_ml242d.lib
opencv_objdetect242d.lib
opencv_ts242d.lib
opencv_video242d.lib
       Release模式添加:    
          opencv_calib3d242.lib
opencv_contrib242.lib
opencv_core242.lib
opencv_features2d242.lib
opencv_flann242.lib
opencv_gpu242.lib
opencv_haartraining_engine.lib
opencv_highgui242.lib
opencv_imgproc242.lib
opencv_legacy242.lib
opencv_ml242.lib
opencv_objdetect242.lib
opencv_ts242.lib
opencv_video242.lib

8. 编码运行
    
[cpp]  view plain copy
  1. #include "stdafx.h"  
  2. #include "highgui.h"  
  3. //using namespace cv;  
  4.  int _tmain(int argc, _TCHAR* argv[])  
  5. {    const char* imagename = "D:/Images/jc.jpg";  
  6.     cv::Mat img = cv::imread(imagename);  
  7.     if(img.empty())  
  8.     {  fprintf(stderr, "Can not load image %s\n", imagename);  
  9.         return -1;  
  10.     }  
  11.     if( !img.data )  
  12.         return -1;  
  13.     cv::namedWindow("image", CV_WINDOW_AUTOSIZE);  
  14.     cv::imshow("image", img);  
  15.     cv::waitKey();  
  16.     return 0;  
  17. //(代码来自http://blog.sina.com.cn/s/blog_68ed8b21010163uc.html)  
     运行效果如下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译安装OpenCV 3.2和OpenCV_contrib的步骤如下: 1. 首先,下载OpenCV 3.2的源代码和OpenCV_contrib的扩展模块源代码。可以从OpenCV的官方网站或GitHub上获取这些源代码。 2. 解压下载的OpenCV 3.2源代码文件和OpenCV_contrib源代码文件,并将它们分别放置在不同的目录中。 3. 在终端中打开一个新的命令窗口,并导航到OpenCV的源代码目录。 4. 创建一个新的目录,用于保存编译后的OpenCV库文件。建议在源代码目录之外的某个位置创建此目录。 5. 在终端中输入以下命令来设置编译选项和安装路径: ``` cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/path/to/opencv_libs \ -D OPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib/modules \ /path/to/opencv_source ``` 其中,`/path/to/opencv_libs`是你创建的用于保存库文件的目录路径,`/path/to/opencv_contrib/modules`是OpenCV_contrib源代码的路径,`/path/to/opencv_source`是OpenCV源代码的路径。 6. 输入以下命令编译安装OpenCV库文件: ``` make -j4 sudo make install ``` 这将会使用4个线程(可根据你的机器性能进行调整)进行编译,并将编译后的文件安装在指定的安装路径中。 7. 安装完成后,可以在指定的安装路径中找到生成的OpenCV库文件。在你的项目中,应该设置正确的头文件和库文件路径来使用OpenCV。 这些是基本的步骤来编译安装OpenCV 3.2和OpenCV_contrib。请注意,在编译安装过程中,可能会遇到依赖问题或其他错误,这可能需要进一步的配置和处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值