Opencv2.4.3 在win7(64位)下vs2010的配置

时间:2022-09-08 09:42:10

环境:Win7旗舰版64位 + VS2010 + opencv2.4.3

步骤1:首先下载Opencv2.4.3,下载地址:http://www.opencv.org.cn/index.php/Download,要是下不了就FQ下吧,我的是FQ下的,其他地方也应该有下载。

步骤2:下载下来了一个名为OpenCV-2.4.3.exe的文件,进行解压,我的解压放置为D:\Program Files (x86)\opencv2.4.3

步骤3:设置环境变量:右键计算机-》属性-》高级系统设置-》高级-》环境变量,在用户变量与系统变量下都新建Path,输入D:\Program Files (x86)\opencv2.4.3\opencv\build\x86\vc10\bin,需要重启生效。

        注意:在这里有一点需要说明,无论我们是64位还是32位的win7系统,我们都是按照32位的来设置,除非你需要做64位的程序,同样的,在vs2010中,我们设定解决方案平台为Win32,尽管我们的系统是64位的。

步骤4:打开vs2010,新建一个空的Win32控制台应用程序test

Opencv2.4.3 在win7(64位)下vs2010的配置               Opencv2.4.3 在win7(64位)下vs2010的配置

 

右键点击解决方案“test”,找到最后一个属性,在VC++目录—>包含目录,加上以下3条路径:

D:\Program Files (x86)\opencv2.4.3\opencv\build\include

D:\Program Files (x86)\opencv2.4.3\opencv\build\include\opencv

D:\Program Files (x86)\opencv2.4.3\opencv\build\include\opencv2

再在VC++目录—>库目录加入一条路径:

D:\Program Files (x86)\opencv2.4.3\opencv\build\x86\vc10\lib

步骤5:在test属性-》链接器-》输入-》附加依赖项中加入

Debug中(看左上角有个配置选项,进行Debug与Release切换)

opencv_calib3d243d.lib
opencv_contrib243d.lib
opencv_core243d.lib
opencv_features2d243d.lib
opencv_flann243d.lib
opencv_gpu243d.lib
opencv_haartraining_engined.lib
opencv_highgui243d.lib
opencv_imgproc243d.lib
opencv_legacy243d.lib
opencv_ml243d.lib
opencv_nonfree243d.lib
opencv_objdetect243d.lib
opencv_photo243d.lib
opencv_stitching243d.lib
opencv_ts243d.lib
opencv_video243d.lib
opencv_videostab243d.lib

 

Release版

opencv_calib3d243.lib
opencv_contrib243.lib
opencv_core243.lib
opencv_features2d243.lib
opencv_flann243.lib
opencv_gpu243.lib
opencv_haartraining_engine.lib
opencv_highgui243.lib
opencv_imgproc243.lib
opencv_legacy243.lib
opencv_ml243.lib
opencv_nonfree243.lib
opencv_objdetect243.lib
opencv_photo243.lib
opencv_stitching243.lib
opencv_ts243.lib
opencv_video243.lib
opencv_videostab243.lib

配置完成

步骤6:测试,在test中新建main.cpp

Opencv2.4.3 在win7(64位)下vs2010的配置
 
#include <opencv2/opencv.hpp>
 
using namespace std;
using namespace cv;
 
int main(int argc, char* argv[])
{
    const char* imagename = "lena.jpg";
 
    //从文件中读入图像
    Mat img = imread(imagename);
 
    //如果读入图像失败
    if(img.empty())
    {
        fprintf(stderr, "Can not load image %s\n", imagename);
        return -1;
    }
 
    //显示图像
    imshow("image", img);
 
    //此函数等待按键,按键盘任意键就返回
    waitKey();
 
    return 0;
}
Opencv2.4.3 在win7(64位)下vs2010的配置

 

在命令行中运行test.exe后得到:

Opencv2.4.3 在win7(64位)下vs2010的配置

 

当再次新建一个项目时,只需设置一下-》链接器-》输入中的Debug与Release两种附加依赖项就好了。