Win 7 下扩展opencv_contrib的OpenCV3.1.0+VS2012的开发配置

上一篇记录中介绍了Windows平台下编译OpenCV扩展的opencv_contrib,本篇接着上一篇进行进一步的开发配置:

1、设置环境变量

(1)右键单击我的电脑属性高级环境变量

①用户变量

设置PATH,添加值D:\Programming\opencv_contrib\install\x86\vc11\bin。(其中D:\Programming\opencv_contrib为上篇中cmake时设置的OpenCV.sln的项目路径;install\x86\vc11\bin为上篇中编译完成后,仅生成INSTALL”后生成的目录与相关文件

单击新建,在弹出的对话框中,将变量名和变量值分别设置为OpenCV和D:\Programming\opencv_contrib\install

系统变量

选中PATH,单击编辑。在PATH的末尾添加以下路径:D:\Programming\opencv_contrib\install\x86\vc11\bin

说明:

①设置完环境变量,需要重启电脑,才能生效。

②如果是直接利用OpenCV2.4.x + VS2012进行开发,环境变量则与OpenCV的解压路径相关,如解压在D:\Programming\opencv,那么环境变量的值分别为D:\Programming\opencv\build\x86\vc11\bin、D:\Programming\opencv\build、D:\Programming\opencv\build\x86\vc11\bin


2、配置Visual Studio 2012

为了以后便于利用OpenCV做开发,在此设置成可以继承的全局设置。

打开VS2012,新建项目win32控制台项目完成。


点击视图其他窗口属性管理器从左侧项目中打开“Debug| Win32”“Microsoft.Cpp.Win32.user”,双击“Microsoft.Cpp.Win32.user”。


点击左侧VC++目录,编辑右侧的可执行文件目录、包含目录与库目录,分别添加对应的路径。

对应的路径如下:

1)可执行文件目录

D:\Programming\opencv_contrib\install\x86\vc11\bin

说明:若直接利用OpenCV2.4.x + VS2012进行开发,则设置为:

D:\Programming\opencv\build\x86\vc11\bin

2)包含目录

D:\Programming\opencv_contrib\install\include

D:\Programming\opencv_contrib\install\include\opencv

D:\Programming\opencv_contrib\install\include\opencv2

说明:①若直接利用OpenCV2.4.x + VS2012进行开发,则设置为:

D:\Programming\opencv\build\include

D:\Programming\opencv\build\include\opencv

D:\Programming\opencv\build\include\opencv2

      ②这里的include目录为build文件夹下的include目录,不要选成与build文件夹在同一个根目录下的那个include文件夹。

3)库目录

D:\Programming\opencv_contrib\install\x86\vc11\lib

D:\Programming\opencv_contrib\install\x86\vc11\staticlib

说明:直接利用OpenCV2.4.x + VS2012进行开发,则设置为:

D:\Programming\opencv\build\x86\vc11\lib


④附加依赖项
单击“链接器”→“输入”→“附加依赖项”,在附加依赖项里,添加\x86\vc11\lib文件夹里的lib文件名称:

opencv_aruco310.lib
opencv_bgsegm310.lib
opencv_bioinspired310.lib
opencv_calib3d310.lib
opencv_ccalib310.lib
opencv_core310.lib
opencv_datasets310.lib
opencv_dnn310.lib
opencv_dpm310.lib
opencv_face310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_fuzzy310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_line_descriptor310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_optflow310.lib
opencv_photo310.lib
opencv_plot310.lib
opencv_reg310.lib
opencv_rgbd310.lib
opencv_saliency310.lib
opencv_shape310.lib
opencv_stereo310.lib
opencv_stitching310.lib
opencv_structured_light310.lib
opencv_superres310.lib
opencv_surface_matching310.lib
opencv_text310.lib
opencv_tracking310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
opencv_xfeatures2d310.lib
opencv_ximgproc310.lib
opencv_xobjdetect310.lib
opencv_xphoto310.lib
ippicvmt.lib

说明:上面的库为\x86\vc11\lib里面的库文件,文件名后面有小写字母“d”的为Debug库(调试模式库),没有“d”的为Release库(发布模式库)。末尾的310

是版本号,和你lib里面的文件一致的。比如,OpenCV2.4.13的lib文件的末尾数字为2413。如果版本不一样,要改正,使其一致。


⑤测试程序:

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat image; // create an empty image
    std::cout << "This image is " << image.rows << " x " << image.cols << std::endl;
    // read the input image as a gray-scale image
    image=  cv::imread("D:\\test_images\\puppy.bmp", CV_LOAD_IMAGE_GRAYSCALE); 
    if (image.empty()) {  // error handling
        // no image has been created...
// possibly display an error message and quit the application 
std::cout << "Error reading image..." << std::endl;
return 0;
    }
    std::cout << "This image is " << image.rows << " x " << image.cols << std::endl;
    std::cout << "This image has " << image.channels() << " channel(s)" << std::endl; 


    // create image window named "My Image"
    cv::namedWindow("Original Image"); // define the window (optional)
    cv::imshow("Original Image", image); // show the image

    cvWaitKey(0);
    return 0;
}

测试结果:


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值