Download content
opencv3.2. Download address: https://opencv.org/opencv-3-2/
Contrib download address: https://github.com/opencv/opencv_contrib/releases?after=3.3.1
cmake download. Note that versions 3.6.1, 3.9 and 3.12 are available, but higher versions such as 3.20 cannot be used. You can download it from the official website
https://cmake.org/files/v3.12/
1, Cmake compilation
Open cmake
1.1 click Browse Source and select opencv3 2.0 source folder, such as E:/opencv/opencv/sources. Click Browse Build, select the folder where you want to save the compilation results, for example, create a new E:/opencv/opencv32 and select.
1.2 click Configure and select Visual Studio 14 2015 as the generation tool. The final generation is Win32, which can be selected according to the needs. The following four options do not need to be moved. The first one can be selected by default. Then click Finish.
Add contrib
Find opencv_ EXTRA_ MODULES_ For path, fill in the corresponding directory, such as opencv_contrib-3.2.0/modules, and then click configure
Possible problems:
1,ffmpeg
During compilation, errors may be reported because the download is stuck, and some additional libraries need to be downloaded manually
The download address of ffmpeg library is
https://github.com/opencv/opencv_3rdparty/branches/all,
The versions of ffmpeg and ippicv required by opencv320 are shown in the figure below
Open the file ffmpeg in "path to your OpenCV\opencv\sourcesrdparty\ffmpeg" Cmake, change its content to:
message(STATUS "FFMPEG: Package successfully downloaded") include(${CMAKE_CURRENT_LIST_DIR}/ffmpeg_version.cmake)
2,ippicv
Download address: https://github.com/opencv/opencv_3rdparty/branches/all or https://blog.csdn.net/goodmoon2007/article/details/84062459
Create a folder unpack in "path to your OpenCV \opencv\sourcesrdparty\ippicv" to unpack the extracted ippicv_ Copy win to the newly created unpack
Edit downloader Cmake, download The content of cmake is modified as follows:
# # 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()
3,xxx.i file download failed
Download and copy to opencv_contrib/modules/xfeatures2d/src/
Download address: https://pan.baidu.com/s/1BeYF8kqEZLAJYQj-MvxpmA
Extraction code: e1wc
4. The error may be reported again
Although in question 3, the downloaded XX I file into opencv_contrib/modules/xfeatures2d/src /, but it will still report errors. Run configure several times more
The compilation is completed as follows:
2. Library generation
Enter D:\OpenCV\opencv320\opencv-3.2.0\build and run opencv with VS2015 SLN, generate - batch generate, check the Debug and Release of INSTALL, and then click generate. After a very long wait, the required dynamic library or static library will be generated.
The generation succeeded as follows:
If x86 is found in the install folder, the compilation is successful
3, vs2015 running opencv3 two
3.1 adding environment variables
3.2vs2015 configuration
Add header file path:
Add library file path:
Add the lib file name generated by install\x86\vc14\lib in the linker input attach dependency
Add content (subject to the lib file directory generated by yourself!!! Otherwise, an error will be reported)
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_highgui320d.lib opencv_hdf320d.lib opencv_imgcodecs320d.lib opencv_imgproc320d.lib opencv_line_descriptor320d.lib opencv_ml320d.lib opencv_objdetect320d.lib opencv_optflow320d.lib opencv_phase_unwrapping320d.dll 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
Test code
#include <opencv2/opencv.hpp> int main() { cv::Mat src = cv::imread("dog.png"); cv::imshow("src", src); cv::waitKey(0); return 0; }
Possible problems
The main reason for this problem is that the Lib file I added in the linker input attachment dependency does not match the Lib file generated by my own D:\OpenCV\opencv320\opencv-3.2.0\build\install\x86\vc14\lib
resolvent
Open cmd, enter D:\OpenCV\opencv320\opencv-3.2.0\build\install\x86\vc14\lib folder, and create a new XX Txt file, enter dir / b *. In cmd lib >0. Txt enter to open XX Txt to get the corresponding lib file and input it to the additional dependency