4 opencv compile under visual studio 2017 and simple test

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/leon_zeng0/article/details/89038449

In fact, I do not like compiled in opencv3 when there is a good compiler, I used the direct download. Due to viausl studio 2017, also with opencv3 on the bad, the compiler library only supports vc12. I would like to compile a good opencv4, but found that compiled the only x64 version, I do not need win32 version. So no option but to download their own source code, compile. Which encountered some problems here to be a summary, you give me some help now.

1: Download and unzip opencv source code. https://opencv.org/opencv-4-0-0.html  is one of my download, I actually google opencv 4 download found. You should be able to find baidu opencv 4 download.

2: Download and install cmake, my computer already loaded it, and if you do not, you will next install it, open source free.

3: Download and install visual studio 2017 or other newer version, I was already loaded it is.

4: Run cmake, top row address input source code, the following line compiler target address, if not established well, config when you ask whether New, then yes. Well these two input lines, on the point Config, or a return to multi-point, first time, will ask you to choose a compiler, of course, choose what you want. To some time to complete. After the completion point Generate, generate compile the project. That quickly, and then open the open project.

 

 

After opening the project, of course, is compiled, you can choose Debug or Release 2 species. Translated well, you can test, to build an application.

5: encountered a problem

Test found no opencv_world400d.lib, later asking many, asked to say when the world should be on the hook cmake

I do not see this option, then hook on Advanced, enter the world in the search bar. See, I did not hook on, here comes the hook on the map.

I recompile, finally we had opencv_world400d.lib, but I found the test 

1>opencv_ts400d.lib(ts_perf.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in load3DView.obj

The original was compiled libraries generated static library, I took the test program is set to a static library, but compile time, and a lot of error.

In fact, using the static library, the need to better link library

But I can not find the dynamic version of the library. There is not cmake dll option, which failed. Is not called share it, really Yes.

I typed in the search share really have this option, and begin not on the hook. Here are the results on the hook.

Such re-compiled, there is a dynamic version of the library. Below is the directory structure of the compiled started only staticlib.

Uncertain operation. After compilation is complete, I chose to install as the preferred engineering works, compiled separately, and then run. I do not know this, but now translated well.

6: Simple Test Engineering

Create a new project, type: windows console application, and then use the following code to replace the file contents. imread the contents of the picture is the name of the file that contains the path, you need to actually modify according to your situation.

#include "pch.h"
#include "opencv2/opencv.hpp"

using namespace cv;

int main()
{
	Mat image = imread("D://study//opencv//lena.jpg", 1);
	namedWindow("Original Image", 1);
	// Show stuff
	imshow("Original Image", image);
	// Wait until user press some key
	waitKey();
	return 0;
}

Compile and run it? You do not have to set the path and libraries.

The first is the path, include the need indiscriminately .. \ install \ include, lib need to add select .. \ install \ x86 \ vc15 \ lib.

Select Dynamic Link Library project type.

Library contains the following settings, is the need linker-> input in the Additional Dependencies have added opencv_world400d.lib:

You can now successfully compiled and linked the run error, need to. \ Copy install \ x86 \ vc15 \ opencv400d.dll file in the bin directory of the program to run.

Now test run a success. You can display pictures.

Guess you like

Origin blog.csdn.net/leon_zeng0/article/details/89038449