VS2010平台下OpenCV编译和安装

           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 安装包

     OpenCV-2.4.2.exe  (

 

2. 解压安装包

    双击OpenCV-2.4.2.exe 解压,比如解压安装到C:\openCV_extract

    【这里面是OpenCV自带的dll库,无法用来在VS中调试OpenCV,所以需要使用CMake重新编译】

 

3.  安装CMake

     cmake-2.8.8-win32-x86.exe (

 

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

   

VS2010平台下OpenCV编译和安装

 

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可以不用加)

       

VS2010平台下OpenCV编译和安装

VS2010平台下OpenCV编译和安装

      (2)VC++ Directories 下的Library Directories 

             Debug模式为:lib\Debug

             Release模式为:lib\Release

         

VS2010平台下OpenCV编译和安装

VS2010平台下OpenCV编译和安装

     

      (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. 编码运行

   

#include "stdafx.h" #include "highgui.h" //using namespace cv; int _tmain(int argc, _TCHAR* argv[]) { const char* imagename = "D:/Images/jc.jpg"; cv::Mat img = cv::imread(imagename); if(img.empty()) { fprintf(stderr, "Can not load image %s\n", imagename); return -1; } if( !img.data ) return -1; cv::namedWindow("image", CV_WINDOW_AUTOSIZE); cv::imshow("image", img); cv::waitKey(); return 0; } //(代码来自)

VS2010平台下OpenCV编译和安装

     运行效果如下

VS2010平台下OpenCV编译和安装

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/14767.html