opencv3.2下载地址:https://opencv.org/opencv-3-2/
contrib下载地址:https://github.com/opencv/opencv_contrib/releases?after=3.3.1
cmake下载,注意版本,3.6.1,3.9,3.12都可用,但高版本例如3.20不能用。官网下载即可
https://cmake.org/files/v3.12/
1.1 点击Browse Source,选择opencv3.2.0源码文件夹,例如E:/opencv/opencv/sources。点击Browse Build,选择你要保存编译结果的文件夹,例如新建一个E:/opencv/opencv32并选择。
1.2 点击Configure,生成工具选择Visual Studio 14 2015,这个最后生成的是Win32,根据需求选择。下面那四个选项不用动,默认第一个即可。之后点击Finish。
添加contrib
找到OPENCV_EXTRA_MODULES_PATH
这一项,把自己对应的目录填进去,例如:opencv_contrib-3.2.0/modules
,再点击configure
在编译的时候可能会因为下载卡住报错,需要手动下载一些附加库
ffmpeg库的下载地址为
https://github.com/opencv/opencv_3rdparty/branches/all,
opencv320要求的ffmpeg和ippicv的版本如下图所示
在 “path to your OpenCV\opencv\sources\3rdparty\ffmpeg” 中打开文件 ffmpeg.cmake ,将其内容修改为:
message(STATUS "FFMPEG: Package successfully downloaded")
include(${CMAKE_CURRENT_LIST_DIR}/ffmpeg_version.cmake)
1.2.2 ippicv
下载地址:https://github.com/opencv/opencv_3rdparty/branches/all或https://blog.csdn.net/goodmoon2007/article/details/84062459
在 “path to your OpenCV \opencv\sources\3rdparty\ippicv” 中创建文件夹unpack,将解压得到的ippicv_win 复制到新创建的unpack 中
编辑 downloader.cmake,将downloader.cmake 的内容修改为:
#
# The script downloads ICV package
#
# On return this will define:
# OPENCV_ICV_PATH - path to unpacked downloaded package
#
function(_icv_downloader)
# Commit SHA in the opencv_3rdparty repo
set(IPPICV_BINARIES_COMMIT "81a676001ca8075ada498583e4166079e5744668")
# Define actual ICV versions
if(APPLE)
set(OPENCV_ICV_PACKAGE_NAME "ippicv_macosx_20151201.tgz")
set(OPENCV_ICV_PACKAGE_HASH "4ff1fde9a7cfdfe7250bfcd8334e0f2f")
set(OPENCV_ICV_PLATFORM "macosx")
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_osx")
elseif(UNIX)
if(ANDROID AND NOT (ANDROID_ABI STREQUAL x86 OR ANDROID_ABI STREQUAL x86_64))
return()
endif()
set(OPENCV_ICV_PACKAGE_NAME "ippicv_linux_20151201.tgz")
set(OPENCV_ICV_PACKAGE_HASH "808b791a6eac9ed78d32a7666804320e")
set(OPENCV_ICV_PLATFORM "linux")
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx")
elseif(WIN32 AND NOT ARM)
set(OPENCV_ICV_PACKAGE_NAME "ippicv_windows_20151201.zip")
set(OPENCV_ICV_PACKAGE_HASH "04e81ce5d0e329c3fbc606ae32cad44d")
set(OPENCV_ICV_PLATFORM "windows")
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_win")
else()
return() # Not supported
endif()
set(OPENCV_ICV_UNPACK_PATH "${CMAKE_CURRENT_LIST_DIR}/unpack")
set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}")
message(STATUS "ICV: Package successfully downloaded")
set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
endfunction()
_icv_downloader()
1.2.3 xxx.i文件下载失败
下载并复制到opencv_contrib/modules/xfeatures2d/src/
下载地址:https://pan.baidu.com/s/1BeYF8kqEZLAJYQj-MvxpmA
提取码:e1wc
1.2.4 可能再次报错
虽然问题3中把下载的xx.i文件放进opencv_contrib/modules/xfeatures2d/src/,可仍然会报错,多运行几次configure
1.2.5 protobuf
下载地址:https://github.com/google/protobuf/releases?after=v3.2.1
进入D:\OpenCV\opencv320\opencv-3.2.0\build,使用VS2015运行OpenCV.sln,生成——批生成,勾选中INSTALL的Debug以及Release,再点击生成,经过非常漫长的等待就生成所需要的动态库或者静态库。
生成成功如下:
install文件夹下找到x86即代表编译成功
3.2.3 附加依赖项
在链接器-输入-附加依赖项
中,添加install\x86\vc14\lib
生成的lib文件名
添加内容(以自己生成的lib文件目录为准!!!不然会出现报错)
opencv_aruco320d.lib
opencv_bgsegm320d.lib
opencv_bioinspired320d.lib
opencv_calib3d320d.lib
opencv_ccalib320d.lib
opencv_core320d.lib
opencv_datasets320d.lib
opencv_dnn320d.lib
opencv_dpm320d.lib
opencv_face320d.lib
opencv_features2d320d.lib
opencv_flann320d.lib
opencv_fuzzy320d.lib
opencv_hdf320d.lib
opencv_highgui320d.lib
opencv_imgcodecs320d.lib
opencv_imgproc320d.lib
opencv_line_descriptor320d.lib
opencv_ml320d.lib
opencv_objdetect320d.lib
opencv_optflow320d.lib
opencv_phase_unwrapping320d.lib
opencv_photo320d.lib
opencv_plot320d.lib
opencv_reg320d.lib
opencv_rgbd320d.lib
opencv_saliency320d.lib
opencv_shape320d.lib
opencv_stereo320d.lib
opencv_stitching320d.lib
opencv_structured_light320d.lib
opencv_superres320d.lib
opencv_surface_matching320d.lib
opencv_text320d.lib
opencv_tracking320d.lib
opencv_video320d.lib
opencv_videoio320d.lib
opencv_videostab320d.lib
opencv_xfeatures2d320d.lib
opencv_ximgproc320d.lib
opencv_xobjdetect320d.lib
opencv_xphoto320d.lib
#include
int main()
{
cv::Mat src = cv::imread("dog.png");
cv::imshow("src", src);
cv::waitKey(0);
return 0;
}
出现这个问题的原因主要是因为我在链接器-输入-附加依赖项
中添加的lib文件和我自己D:\OpenCV\opencv320\opencv-3.2.0\build\install\x86\vc14\lib
生成lib文件不匹配造成的
解决方法
打开cmd,进入D:\OpenCV\opencv320\opencv-3.2.0\build\install\x86\vc14\lib
文件夹底下,随便新建一个xx.txt文件,在cmd中输入dir /b *.lib >0.txt
回车,打开xx.txt即可得到对应的lib文件,将它输到附加依赖项即可
注意:
xxd.lib是Debug模式调用
xx.lib是Release模式调用
不要同时添加至附加依赖项,不然可能会报内存访问出错之类的问题