... | ... | @@ -40,8 +40,6 @@ works also on all platforms. vcpkg may be advantageous on Windows, especially wh |
|
|
|
|
|
# Build first OpenCV Projects
|
|
|
|
|
|
The easiest way to create a project using OpenCV is via cmake.
|
|
|
|
|
|
## Hello OpenCV World
|
|
|
|
|
|
see https://gitlab.com/opencv6/hello_opencv_world
|
... | ... | @@ -53,9 +51,13 @@ This example requires an installed openh264 encoder library for generating the . |
|
|
|
|
|
see https://gitlab.com/opencv6/hello_opencv_videocapture
|
|
|
|
|
|
# Building your own project
|
|
|
# Building and running your own project
|
|
|
|
|
|
The following generic `CMakeLists.txt` template from the "Hello OpenCV World" project can be used to generate the build files for any toolchain supported by cmake:
|
|
|
## Build via cmake
|
|
|
|
|
|
The easiest way to create a project using OpenCV is via cmake.
|
|
|
|
|
|
The following generic `CMakeLists.txt` template from the "Hello OpenCV World" project can be used to generate the build files for any C++ toolchain supported by cmake:
|
|
|
```
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
project( MyProject VERSION 1.0 DESCRIPTION "MyProject" LANGUAGES CXX)
|
... | ... | @@ -68,9 +70,15 @@ target_sources( MyProject PRIVATE "MyProject.cpp" ) |
|
|
target_link_libraries( MyProject PRIVATE ${OpenCV_LIBS} )
|
|
|
```
|
|
|
|
|
|
The three `set` lines are recommended for maximum portability. The OpenCV path can be overridden on the command line by using a cmake `-DOpenCV_DIR=D:/OpenCV` like option.
|
|
|
The three `set` lines are recommended for maximum portability. The OpenCV path hint can be overridden on the command line by using a cmake `-DOpenCV_DIR=D:/OpenCV` like option.
|
|
|
|
|
|
When using Visual Studio toolchain, you can open the `.sln` solution file and use the IDE for editing and building. Or, you call `cmake --build .` from a cmd shell for building your project. As a third alternative, one might configure the Visual Studio Solution manually in the IDE from scratch.
|
|
|
|
|
|
## Manually configuring a toolchain
|
|
|
|
|
|
When using Visual Studio toolchain, you can open the `.sln` solution file and use the IDE for editing and building. Or, you call `cmake --build .` from a cmd shell for building your project.
|
|
|
1. Make sure that the OpenCV include directory path is passed to the compiler
|
|
|
1. Make sure that the OpenCV library directory path is passed to the linker
|
|
|
1. Make sure that the OpenCV library file names are passed to the linker
|
|
|
|
|
|
## Running your project
|
|
|
|
... | ... | |