foreword
The compilation and installation of OpenCV under the previous Windows platform_Mega_Li's blog-CSDN blog introduced the process of using CMake to compile OpenCV on the Windows platform. Among them, several .cmake files are generated in the install directory, and their function is to introduce the OpenCV library in the construction project using CMake. This article briefly introduces how to use CMake to build a VS project and import the previously compiled OpenCV library.
Write code
Here is a simple test function to print the version information of OpenCV, the content is as follows.
#include <iostream>
#include <opencv2/opencv.hpp>
int main(int argc, char** argv)
{
printf("OpenCV version: %s\n", CV_VERSION);
return 0;
}
Write CMakeLists.txt
After writing CMakeLists.txt, you need to tell CMake project information, compilation target information and dependent libraries and header file information.
cmake_minimum_required(VERSION 3.14)
project(OpenCVTest)
set(CMAKE_PREFIX_PATH D:/SDK/opencv3.4.7/build/vs2017_x64/install)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executab