OpenCV下使用Cmake

OpenCV下使用Cmake

20161015

18:25

 

最近在依照毛新云的OpenCV3编程入门,在Windows下用CMake编译OpenCV3.1.0的源代码,由于是第一次接触这些,在学习编译过程中遇到了很多问题,也耗费了大量的时间,现在将其中一个问题记录下来,希望可以帮组别人少走弯路。首先在CMake官网https://cmake.org/下载了cmake-3.6.2-win64-x64

在编译过程中,估计是因为CMake的服务器在外国的原因,跨越不了GREATWALL,一直出现下面错误提示:

Downloadingopencv_ffmpeg_64.dll...

CMake Error at cmake/OpenCVUtils.cmake:895 (file):

file DOWNLOAD HASH mismatch

 

for file: [D:/Program Files(x86)/opencv/sources/3rdparty/ffmpeg/downloads/35fe6ccdda6d7a04e9056b0d73b98e76/opencv_ffmpeg_64.dll]

expected hash: [35fe6ccdda6d7a04e9056b0d73b98e76]

actual hash: [f112aef8bcfad76757e2ebf06c7cf6e5]

status: [28;"Timeout was reached"]

 

Call Stack (most recent call first):

3rdparty/ffmpeg/ffmpeg.cmake:15 (ocv_download)

cmake/OpenCVFindLibsVideo.cmake:206 (include)

CMakeLists.txt:536 (include)

 

CMake Error at cmake/OpenCVUtils.cmake:899 (message):

Failed to download opencv_ffmpeg_64.dll. Status=28;"Timeout wasreached"

Call Stack (most recent call first):

3rdparty/ffmpeg/ffmpeg.cmake:15 (ocv_download)

cmake/OpenCVFindLibsVideo.cmake:206 (include)

CMakeLists.txt:536 (include)

 

读一下这几行,可以大致了解如下,在编译过程中,程序下载了一个文件,它的hash值与所期待的不一致,所以导致了错误,接下来到CMakeLists.txt文件(在…...\opencv\sources)中去定位,然而看不懂。。。。。。于是去网上搜索opencv_ffmpeg_64.dll下载至....../opencv/sources/3rdparty/ffmpeg/downloads/35fe6ccdda6d7a04e9056b0d73b98e76/  下载链接:http://pan.baidu.com/s/1gfE3gHl

还是错误,不过错误提示变了:

Downloadingopencv_ffmpeg.dll...

CMake Error at cmake/OpenCVUtils.cmake:895 (file):

file DOWNLOAD HASH mismatch

 

for file: [D:/Program Files(x86)/opencv/sources/3rdparty/ffmpeg/downloads/89c783eee1c47bfc733f08334ec2e31c/opencv_ffmpeg.dll]

expected hash: [89c783eee1c47bfc733f08334ec2e31c]

actual hash: [3de6314883587d538b4864070e0a749d]

status: [28;"Timeout was reached"]

 

Call Stack (most recent call first):

3rdparty/ffmpeg/ffmpeg.cmake:10 (ocv_download)

cmake/OpenCVFindLibsVideo.cmake:206 (include)

CMakeLists.txt:536 (include)

 

CMake Error at cmake/OpenCVUtils.cmake:899 (message):

Failed to download opencv_ffmpeg.dll. Status=28;"Timeout wasreached"

Call Stack (most recent call first):

3rdparty/ffmpeg/ffmpeg.cmake:10 (ocv_download)

cmake/OpenCVFindLibsVideo.cmake:206 (include)

CMakeLists.txt:536 (include)

 

继续下载了一个opencv_ffmpeg.dll,替换至.../opencv/sources/3rdparty/ffmpeg/downloads/89c783eee1c47bfc733f08334ec2e31c/下载链接:http://pan.baidu.com/s/1dEAnopN

然后开始Downloading ippicv_windows_20151201.zip我知道肯定下载不了,继续自己下载,http://pan.baidu.com/s/1c27hCT6

放到/opencv/sources/3rdparty/ippicv/downloads/windows-04e81ce5d0e329c3fbc606ae32cad44d/ 继续configure。。。。。。如下图,Configuring done

A CMake 3.6.2 - D:/Program Files (x86)/OpencvBuild  File Tools Options Help  Where is the source code:  Where to build the binaries:  D: / Program  D: / Program  Files (x86) / opencv/sources  Files (x86) /OpencvBui1d  Value  Grouped  Advanced  Add Entry  x  Browse Source.  Browse Build..  Remove Entry  Search:  Name  UILD  UILD  UILD  UILD  UILD  UILD  UILD  UILD  opencv  opencv  opencv  opencv  opencv  opencv  opencv  opencv  calib3d  core  features2d  flann  highgui  imgcodecs  Imgproc  ml  Press Configure to update and display new values in red,  Generate Current Generator: Visual Studio 14 2015 Win64  then press Generate to generate selected build files.  Confi gure  Python 2 :  Interpreter :  Python 3 :  Interpreter :  Python (for bu  Java :  Java wrappers :  Java tests:  Mat I :  Document at I on :  Doxygen :  PlantUML:  Tests and samples:  Tests:  Performance tests :  C/C++ Examples :  Install path :  cvconfig.h is In:  Conf done  Mat lab not found or implicitly disabled  D: / program Files  D: / program Files  (x86) /OpencvBuiId/instaII  (x86) / OpencvBuiId

 

然后进行第二次Configure(配置),直接点击Configure,几秒钟后,Configuring done

File Tools Options Help  Where is the source code:  Where to build the binaries:  Search:  Name  ANT EXECUTABLE  BUILD CUDA STUBS  BUILD EXAMPLES  BUILD JASPER  BUILD JPEG  BUILD OPENEXR  BUILD PACKAGE  BUILD PERF TESTS  BUILD  PNG  A CMake 3.6.2 - D:/Program Files (x86)/OpencvBuild  BUILD DOCS  D: / Program  D: / Program  Files (x86) / opencv/sources  Files (x86) /OpencvBui1d  Value  ANT EXECUTABLE-NOTFOUND  Grouped  Advanced  Add  x  Browse Source.  Browse Build.  Remove Entry  Entry  files.  Press Configure to update and display new values in red,  Generate Current Generator: Visual Studio 14 2015 Win64  then press Generate to generate selected build  Confi gure  Python 2 :  Interpreter :  Python 3 :  Interpreter :  Python (for bu  Java :  Java wrappers :  Java tests:  Mat I :  Document at I on :  Doxygen :  PlantUML:  Tests and samples:  Tests:  Performance tests :  C/C++ Examples :  Mat lab not found or implicitly disabled  Instal I  path :  D: / program Files  D: / program Files  (x86) /OpencvBuiId/instaII  (x86) / OpencvBuiId  cvconfig.h is In:  Conf done

 

最后,单机Generate,成功生成项目,几秒钟完成,显示Generating done。大功告成也!

CMake是自己设定build的路径下,可以打开OpenCV.sln工程,按F5启动调试,5分钟编译完成,

tes t _ operati ons. cpp  test_ptr. cpp  test _ rand. cpp  test_rotatedrect. cpp  test_u_mat. cpp  test_utils. cpp  test_ari thin. cpp  — > D: \Program Files (x86) \OpencvBui1d\bin\Debug\opencv_test_cored. exe  opencv_test_core. vcxproj  - ALL_BUILD, Debug -  Building Custom Rule D: / Program Files (x86) / opencv/sources/CMakeLists. txt  CMake does not need to re—rum because D: \Program Files (x86) \OpencvBui1d\CMakeFi1es\generate. stamp is up—to—date.  = 55 4, o -T, o -T, o -T =

但提示如下错误:

Microsoft Visual Studio  Files  BUILD',  x

 

原因是OpenCV的源代码工程默认将“ALL_BUILD”这个项目设置为了启动项,编译后就会默认运行它。而“ALL_BUILD”是一个项目生成周边的杂项,不是exe文件,本生不可以运行,所以自然就会弹出这样的错误提示。若想让此报错的对话框不像是,指定一个另外的启动项即可。我们在解决方案资源管理器里,对需要设置为启动项的那个项目右键点击,在弹出的菜单项中单击【设为启动项(J)】进行设定。如下图:

FEFÜ(E)  Efiß(D)  NuGet  iQhEi.fiIäS (A)  )encv perf tests  )encv tests  'les  libraries  accuracy  performance  Ctrl+Shift+X  Ctrl+X

总结解决办法是:自己根据上述地址手动下载该文件,然后将编译时下载的文件替换掉。根据上述代码可知,如果该文件存在,就不会再去下载。



你可能感兴趣的:(Open,CV)