使用CMake和VS2017在Windows10系统上配置OpenCV4.2和OpenCV_Contrib

1 Tools Download

1.1 CMake Download

Download the right version according to your System Platform(X86和X64),for easy installation and using, binary installation is a good choice. It is:

Windows win64-X64 ZIP

1.2 OpenCV4.2 and Contrib Download

OpenCV is a open source librairy for machine version, but contrib is not for free due to the nonfree algorithm, such as SIFT, SURF etc, so they are not in one box.
Another attention, it is asked to download the concide version with the OpenCV, otherswise, there will be some unexpected issues. For an example:

If the OpenCV4.2
     the OpenCV_Contrib should be 4.2 version also

More, when you use the cmake to compile them, the switch should be enable. It will show how to set in the following installation step.

OPENCV_ENABLE_NONFREE=ON

1.3 VS2017 Download

Be sure, the X64 platform is installed. If you not sure, choose all the items, but this will consume your disk and time more.

2.Compile Using CMake

2.1 CMake Configuration

Open cmake-gui.exe, choose the opencv source code in red edit 1 and define where to output the cmake output in red edit 2. please see follows picture, then click button 3 and pop a setting dialog, choose the itme like figure 2.
Figure1 CMake_1
Figure 1
Firue2 CMake_2
Figure 2
click the Finish Button, then waiting the configuration finished. We got the figure 3 as follows:
Figure 3
Figur 3
There are some issues, only there is no red mark line, the configuration is done with OK. So we should modify some setting and do Configure again.

  • Add the opencv_contrib source code
    Figure 4

  • Enable The OPENCV_ENABLE_NONFREE
    Figure 5

  • ENABLE The OpenCV World. This is for easy using and deployment in VS2017.
    Figure 6

  • Disable BUILD_DOCS, BUILD_TESTS. So as to save the time.
    OK. Then click the Configure button of figure 4 again. Once finished, click the Generate Button. The follows picture is got:
    Figure 7
    But, there some cmake errors, it can be seen what are these errors through the CMakeDownloadLog.txt in your output folder(my folder is build_X64_ebug).

One word. There are some files that can not be download due to the server address can’t reach. Here I summerise all the files:

  • vgg_generated_*.i files(4)
  • boostdesc_*.i files(7)
  • opencv_videoio_ffmpeg.dll
  • opencv_videoio_ffmpeg_64.dll
  • ffmpeg_version.cmake
  • ippcv_2019_ia32_20180703_general.zip

Solution:Download all these files from other place. Then place all the files to the .cach folder’s sub folder in opencv source code.

[If you can't find download link, I will provide the down link in the end:)]

Figure 8

  • opencv_videoio_ffmpeg_64.dll, opencv_videoio_ffmpeg.dll and ffmpeg_version.cmake to ffmpeg folder.
  • vgg_generated_.i files(4) and boostdesc_.i files(7) to the xfeatures2d folder
  • ippcv_2019_ia32_20180703_general.zip to the ippicv folder

Then repeat the Configurate and Generate process.

3.Build Using VS2017

3.1 Libraries Generation

Open the OpenCV.sln in the cmake output folder. And some configuraton. Becasue this time we just to compile the debug libraries.
So, the configuration like this:
Figure 9
After this. Then you just click the Build command and waiting the building finished.

3.2 Libraries Usage

The finall lib and dll in my computer is:

F:\OpenCV4.2\build_x64\install\x64\vc15

3.2.1 Add Environment Vairable

add

F:\OpenCV4.2\build_x64\install\x64\vc15\bin

to you computer’s system environment vairable path.

3.2.2 Add Lib Path and Include Path

add

F:\OpenCV4.2\build_x64_debug\install\include
F:\OpenCV4.2\build_x64_debug\install\include\opencv2

to your VS include path.

add

F:\OpenCV4.2\build_x64_debug\install\x64\vc15\lib

to your VS lib path.

add

opencv_world420.lib

to your VS dependecny library in Link Page.

Last, copy the opencv_world420.dll to the exe generation folder.

4. Lost Files Download Link

some people asked me, why these files are separated. Becasue I had the vgg and boostdesc issue in Ubuntu16.04 before. Now, I change to windows to do development, I encounter new issues. So the ffmjpeg and ippicv files are uploaded latest.

猜你喜欢

转载自blog.csdn.net/jiaken2660/article/details/105620268