VS2008 和 OpenCV2.3.1
按照http://www.opencv.org.cn/index.php/VC_2008_Express%E4%B8%8B%E5%AE%89%E8%A3%85OpenCV2.3.1
进行
出现LINK : fatal error LNK1104: 无法打开文件“opencv_calib3d231d.lib;”
网上诸多解决方案均无效
突然发现
“opencv_calib3d231d.lib;”
很可疑
去掉 ;
依赖附加项
变成
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.lib
问题解决
附原文
D:\Program Files\OpenCV2.3.1
(无需运行setup.exe,解压则可)。解压后的目录结构如下图。从 http://www.cmake.org/cmake/resources/software.html 下载 Windows (Win32 Installer) 安装。
D:\Program Files\OpenCV2.3.1
),并创建子目录D:\Program Files\OpenCV2.3.1\build\my
,并将cmake的"where to build the binaries"设置为这个目录。
|
|
|
完成上一步骤后,将在D:\Program Files\OpenCV2.3.1\build\my目录下生成OpenCV.sln的VC Solution File,请用VC++ 2008 Express打开OpenCV.sln,然后执行如下操作:
全部运行完毕后,针对你的系统的OpenCV库就生成了。
也即告诉VC去什么地方寻找OpenCV的头文件,打开VC,选择菜单“工具”->“选项”->“项目和解决方案”->“VC++目录”->“包含文件”,包含 D:\Program Files\OpenCV2.3.1\build\include;D:\Program Files\OpenCV2.3.1\build\include\opencv;D:\Program Files\OpenCV2.3.1\build\include\opencv2
如果是自己编译的则输入D:\Program Files\OpenCV2.3.1\build\my\install\include
也即告诉VC去什么地方寻找OpenCV的库文件。
在刚才下载的文件OpenCV-2.3.1-win-superpack.exe 里,已经为VC2008和VC2010预先编译好了动态库和静态库。因此我们不需要如早先版本那样,自己用cmake编译OpenCV。
D:\Program Files\OpenCV2.3.1\build\my\install\lib
D:\Program Files\OpenCV2.3.1\build\x86\vc9\lib
D:\Program Files\OpenCV2.3.1\build\x86\vc10\lib
D:\Program Files\OpenCV2.3.1\build\x64\vc9\lib
D:\Program Files\OpenCV2.3.1\build\x64\vc10\lib
请根据自己的情况四选一,将库目录输入菜单“工具”->“选项”->“项目和解决方案”->“VC++目录”->“库文件” 。如下图所示:
|
|
|
刚才设置的是动态库,因此还需要将OpenCV的dll文件所在的目录加入Path环境变量。dll文件目录如下,请根据自己情况五选一:
D:\Program Files\OpenCV2.3.1\build\my\install\bin
D:\Program Files\OpenCV2.3.1\build\x86\vc9\bin
D:\Program Files\OpenCV2.3.1\build\x86\vc10\bin
D:\Program Files\OpenCV2.3.1\build\x64\vc9\bin
D:\Program Files\OpenCV2.3.1\build\x64\vc10\bin
由于有些函数需要TBB,所以需要将tbb所在的目录也加入到环境变量Path中。TBB相关的DLL路径为:
D:\Program Files\OpenCV2.3.1\build\common\tbb\ia32\vc9
D:\Program Files\OpenCV2.3.1\build\common\tbb\ia32\vc10
D:\Program Files\OpenCV2.3.1\build\common\tbb\intel64\vc9
D:\Program Files\OpenCV2.3.1\build\common\tbb\intel64\vc10
如下图所示将OpenCV和TBB的dll文件所在的目录系统环境变量Path中。加入后可能需要注销当前Windows用户(或重启)后重新登陆才生效。
|
|
opencv_calib3d231d.lib; opencv_contrib231d.lib; opencv_core231d.lib; opencv_features2d231d.lib; opencv_flann231d.lib; opencv_gpu231d.lib; opencv_highgui231d.lib; opencv_imgproc231d.lib; opencv_legacy231d.lib; opencv_ml231d.lib; opencv_objdetect231d.lib; opencv_ts231d.lib; opencv_video231d.lib
(可根据实际需要删减)注意,请打开了新编辑窗口(即点击了“...”按钮)“附加依赖项”,并一条一条分别加入,一条一行(一个回车),(注意行末不要加";")否则会出现类似以下错误:1>LINK : fatal error LNK1104: 无法打开文件“…….lib”opencv_calib3d231.lib; opencv_contrib231.lib; opencv_core231.lib; opencv_features2d231.lib; opencv_flann231.lib; opencv_gpu231.lib; opencv_highgui231.lib; opencv_imgproc231.lib; opencv_legacy231.lib; opencv_ml231.lib; opencv_objdetect231.lib; opencv_ts231.lib; opencv_video231.lib
(可根据实际需要删减)*/***********************************************************************
* OpenCV 2.3.1 测试例程
* 于仕琪 提供
***********************************************************************/
#include "stdafx.h"
#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;
}
程序运行结果图,点击看大图