Use VS2017 to compile OpenCV3.4.2+OpenCV_Contrib3.4.2+Python3.6.2 on Windows10 operation steps plus VS2017 configuration opencv summary

  1. Environment: win10 64bit
  2. Software: OpenCV3.4.2 source code, OpenCV3.4.2 contrib (the version must be the same)
  3. cmake:3.12.1 vs2017
  4. Process:
    Open cmake-gui.exe, add source path and build path, configure, select visual studio 15 2017 win64 in the pop-up dialog box, this is the compiled 64-bit version, if you choose visual studio 15 2017, it is the 32-bit version Yes, click finish, there will be red after finishing, find the OPENCV_EXTRA_MODULES_PATH option, and give here the modules path in the OpenCV contrib directory. Note: The path to be copied directly is \, but / is required. I tried and did not change it, but the compilation was not successful. What was the process of the error reported? I deleted the error log. ! ! After here, you still need configure. After you finish, there should be no red ones. If you have any, you should check CMakeDownloadLog.txt. When you encounter errors, you should first think of looking up the log to accurately find the cause of the error and reduce unnecessary time loss. If this part is not red, click generate

Find OpenCV.sln in the build path, select INSTALL under CMakeTargets, right-click INSTALL-generate, and start generating the file. It is also possible to select regenerate

The OpenCV3.4.2.exe downloaded from the official website is decompressed and it is the compiled OpenCV dll file. Baidu cloud link:
link: https://pan.baidu.com/s/1YWkCLEZrpYxh9ci_ch_BSQ
extraction code: pa0x

The complete process reference link: https://blog.csdn.net/fengbingchun/article/details/84030309

The OpenCV dynamic library generated by this link is correct and verified

Update some notes on August 22, 2020:

  1. If you want to compile OpenCV through cmake, you need to check cmake-related components in a single component when installing vs. I checked two
  2. The opencv_contrib installation fails to open the include file: "opencv2/xfeatures2d/cuda.hpp":
    Solution:
    Add the following content to CMakeLists.txt (I used the absolute path, and then pay attention to the path using'/', I tried not to change it without success ):
    INCLUDE_DIRECTORIES("opencv-3.4.2/opencv_contrib-3.4.2/modules/xfeatures2d/include")
    CMakeLists.txt is in the following path:
    opencv-3.4.2/modules/stitching/CMakeLists.txt
  3. Error data: Download failed: 28; "Timeout was reached"...
    Face: Can't get model file for face alignment.
    Solution:
    View log file:
    View CMakeDownloadLog.txt in the generated path, and the problem can be located without success Download, download according to the given browser path, and put it in this path as opencv-3.4.2/.cache/data/
  4. Error message error C2440: "Initialization": Cannot convert from "const char *" to "char *".
    There are many solutions. I double-clicked the error message, then located the line where the error was reported, and replaced char * with const char *. Problem

The next step is to configure the OpenCV environment in vs. This part also needs to be recorded:
I am vs Xiaobai, I originally thought that the OpenCV compiled by myself was already configured, and there is no need to configure it again, so the time spent here is compared Many, until I realized that OpenCV is an open source visual library, vs is an IDE, I felt that I just compiled the library, did not establish a connection between vs and OpenCV, I realized that I need to configure another wave of OpenCV

Start of text:

  1. Add the compiled D:\vs2017\opencv\vs2017\install\x64\vc15\bin current local path to the environment variable
  2. Copy the opencv_world342.dll and opencv_world342d.dll files in the bin directory to the folder C:\Windows\SysWOW64. I also put these two files into the folder C:\Windows\System32, because I think Usually put in this folder
  3. Copy opencv_ffmpeg342_64.dll in the bin directory to the folder C:\Windows\System32
  4. Create an empty project in vs
  5. Enter the attribute manager, menu bar -> view -> other windows -> attribute manager to configure Debug|X64, right-click Microsoft.Cpp.x64.user, click
    the VC++ directory in the attribute pair -> include directory and VC++ Add the relevant path to the directory -> library directory, and add the relevant path to the linker -> input -> additional dependencies
  6. Add the path of include, OpenCV, OpenCV2 in the include directory
  7. Add the lib directory to the library directory, which is at the same level as the bin directory above
  8. Linker -> Input -> Additional Dependencies added
    opencv_world342d.lib
    opencv_world342.lib
    the tutorial just added a lib, I have added to the list, because I think by the conjunction, but added no error
  9. Configure Release|X64, right-click Microsoft.Cpp.x64.user, click Properties Linker->Input->Additional Dependencies and add opencv_world342.lib opencv_world342d.lib. Also here I have configured
  10. So far the configuration is complete, the next step is to read the picture to test whether OpenCV is successful

The complete process reference link: https://blog.csdn.net/qq_41175905/article/details/80560429

Follow this link to configure successfully, you can successfully read the picture, display, etc.

  1. Remaining problems:
    "Project1.exe" (Win32): "C:\Windows\System32\WinTypes.dll" has been uninstalled "
    Project1.exe" (Win32): "C:\Windows\System32\clbcatq.dll" has been loaded. Unable to find or open the PDB file.
    Critical error detected c0000374
    Project1.exe has triggered a breakpoint.
    The program "[4836] Project1.exe" has exited and the return value is 0 (0x0).

It is said on the Internet that this kind of problem can be skipped. It is not an error or a warning. This problem will not occur if you execute it directly without debugging! ! ! Check back to find out this part of the content! ! !
2. Test Procedure

#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    
    
	const char* imagename = "E:\\test\\06.jpg";//此处为你自己的图片路径

	//从文件中读入图像
	Mat img = imread(imagename, 1);

	//如果读入图像失败
	if (img.empty())
	{
    
    
		fprintf(stderr, "Can not load image %s\n", imagename);
		return -1;
	}
	//显示图像
	imshow("image", img);

	//此函数等待按键,按键盘任意键就返回
	waitKey();
	return 0;
}

After matching it on my computer on August 22, 2020, I felt a little bit:

  1. I have cuda installed on my computer. During the cmake process, I need to tick off the cuda which is used, just don’t compile this
  2. Don't use blind efforts to replace the original thinking! ! !

Guess you like

Origin blog.csdn.net/weixin_43868576/article/details/107567431