1 | initial version |
Here you go: https://www.reddit.com/r/opencv/comments/9kjm2v/creating_an_opencv_based_cmake_project_on_windows/? I made a complete tutorial with video on how to do it. If you have any questions please ask.
2 | No.2 Revision |
Here you go:
https://www.reddit.com/r/opencv/comments/9kjm2v/creating_an_opencv_based_cmake_project_on_windows/?
There are some mistakes here:
1- OpenCV_DIR should point to the "build" directory, and not to "/build/x64/vc15/lib"
2- Avoid using that set command since you are going to distribute these files. Use Windows environmental variables instead.
3- I can see that you make a "cmake .", which is a big no no. You should never ever generate the solution files inside the directory that has CmakeLists.txt. You should create a new directory like "build" inside the DisplayImage directory, get inside that directory and use the command "cmake .."
4- I always prefer the CMake GUI version since it can give you all the possible combinations of variables and it makes it much easier for you to select target compiler and framework.
5- When you did the "cmake" command without any option it automatically selected x86, while the OpenCV directory variable was set to the x64 version. You could either could either pass it as a parameter in the command line, for example: cmake -G "Visual Studio 12 2013 Win64", or simply use the GUI and select your target compiler
I made this short tutorial do demonstrate how you can we can create a complete tutorial new OpenCV based project on Windows using CMake. Using CMake for this task makes it much easier to target any platform or compiler simply by selecting it from CMake GUI, in addition to requiring no further configuration on other operating systems (Linux, MacOS, etc....). It is especially easy on Linux since CMake's find_package would pick up OpenCV directories automatically without any further configuration
Tools Used:
CMake 3.12.2
Visual Studio 2017
OpenCV 3.4.2
First, here is the demo video I've just made:
https://youtu.be/dQ0sq63l4AE
Here are the steps:
1- Go to https://github.com/opencv/opencv/releases and download the latest release. In my case I downloaded opencv-3.4.2-vc14_vc15.exe
2- Extract the archive. Prefer the root of drive because long file names can generate errors when extracted in subfolders.
3- Point the environmental variable Opencv_DIR to the opencv\build directory
4- Add the directory containing the opencv_world343.dll to your PATH environmental variable OR just copy the DLL files to your system32 directory.
5- The test code I used is based on this project:
https://github.com/blueskymonster/opencv-samples/tree/master/display-image
6- Fire CMake GUI and add the root directory of the project to "source code" and add your own build directory (NOT THE SAME ONE USED FOR SOURCE CODE!). That's where the generated Visual Studio solution files and built binaries would reside.
7- Click Configure, and choose the compiler you would use. Pay attention for x64 or 32bit version as the default release comes only with video the x64 vesion.
8- Click generate and Open Project
9- Build in Visual Studio
10- Run application. Note that to run the application from Visual Studio you would have to set DisplayImage as startup project. Otherwise you can run it from command-line or simply double click on how to do it. If you have any questions please ask.
Personally, I always build highly customized versions both for 32 and 64 versions according to my project's requirements. The same CmakeLists.txt files works for Windows x86, x64, Ubuntu, Raspbian, Android, iOS, etc....