OpenCV作为一个十分优秀的跨平台计算机视觉库,我们不仅可以使用其提供的工具,有时更希望能了解其实现机制,然后修改它,进化它。因此构建一个能够方便Goto Source的平台十分必要的。本文提供了在32位Win7下,基于VS2013的平台搭建的方式,仅供参考。

工具

Cmake:官网

OpenCV:官网

VS2008:下载地址

VS2013:下载地址

配置过程(以Opencv3.1为例)

1. 使用Cmake编译源码

先将从opencv官网下载的3.1的包解压到磁盘C:\Opencv\3.1下,里面包含build和source文件夹及两个txt文件;

1

打开Cmake,配置如下

2

3

文件路径配置完成后,点击Configure按钮,此时会读取Cmake文件中的配置信息,如下图:

4

5

6

7

2. 利用VS重新编译工程,生成库文件

在之前配置的工程路径下,找到OpenCV.sln,双击打开工程

8

9

这里我将这些lib文件拷贝到工程目录下新建的lib310文件夹下,方便配置路径时,少点几步。

3. 新建工程,配置环境

如果顺利的到这步,已经离成功不远了,新建一个win32的console工程;

10

11

12

13

OpenCV3.1 Debug 库文件名:

opencv_ts310d.lib
IlmImfd.lib
libjasperd.lib
libjpegd.lib
libpngd.lib
libtiffd.lib
libwebpd.lib
opencv_calib3d310d.lib
opencv_core310d.lib
opencv_features2d310d.lib
opencv_flann310d.lib
opencv_highgui310d.lib
opencv_imgcodecs310d.lib
opencv_imgproc310d.lib
opencv_ml310d.lib
opencv_objdetect310d.lib
opencv_photo310d.lib
opencv_shape310d.lib
opencv_stitching310d.lib
opencv_superres310d.lib
opencv_video310d.lib
opencv_videoio310d.lib
opencv_videostab310d.lib
zlibd.lib
ippicvmt.lib 

OpenCV3.1 Release库文件名:

opencv_ts310.lib
IlmImf.lib
ippicvmt.lib
libjasper.lib
libjpeg.lib
libpng.lib
libtiff.lib
libwebp.lib
opencv_calib3d310.lib
opencv_core310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_photo310.lib
opencv_shape310.lib
opencv_stitching310.lib
opencv_superres310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
zlib.lib

这里ippicvmt.lib这个在两边都要配,而且Debug下没有加d,如果不配置编译时回报LNK2019的错误,如果是OpenCV2.x版本好像两边都没有看到这个lib

保存配置文件,这样以后只要直接引用你保存的配置文件即可,不需要重新配置了;到此,配置工作就完成了;可以开始写代码测试了;

4. 测试

下个断点,单步执行就能跟进源码了

14

15

5. 总结

在成功之前尝试了无数次都没有成功,归结起来就是配置新建工程时库的路径选择不对,还有就是第三方的库一定要选择,如果没有重新编译INSTALL那个工程的话,第三方库存放在..\3rdparty\lib下;还有,库文件不要在添加opencv已经编译好的了,那样同样是跟不进源码的。

PS: VS2008+OpenCV2.x的配置方法跟这一样,就是lib的文件名不同,这里给出2.4.8的,大家只要把248改为对应的版本号即可; 这里给出2.4.8版本的库文件名。

Debug库文件名:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 IlmImfd.lib  
 libjasperd.lib  
 libjpegd.lib  
 libpngd.lib  
 libtiffd.lib  
 zlibd.lib  
 opencv_ml248d.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_objdetect248d.lib  
 opencv_ts248d.lib  
 opencv_video248d.lib  
 opencv_nonfree248d.lib  
 opencv_ocl248d.lib  
 opencv_photo248d.lib  
 opencv_stitching248d.lib  
 opencv_superres248d.lib  
 opencv_videostab248d.lib  

Release库文件名:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
IlmImf.lib
libjasper.lib
libjpeg.lib
libpng.lib
libtiff.lib
zlib.lib
opencv_calib3d248.lib
opencv_contrib248.lib
opencv_core248.lib
opencv_features2d248.lib
opencv_flann248.lib
opencv_gpu248.lib
opencv_haartraining_engine.lib
opencv_highgui248.lib
opencv_imgproc248.lib
opencv_legacy248.lib
opencv_ml248.lib
opencv_nonfree248.lib
opencv_objdetect248.lib
opencv_ocl248.lib
opencv_photo248.lib
opencv_stitching248.lib
opencv_superres248.lib
opencv_ts248.lib
opencv_video248.lib
opencv_videostab248.lib