The goal of this tutorial is a simple step by step compilation of Opencv 4.2 with contribution extra modules with GStreamer as a bonus. The environment is Windows 10, Visual Studio 2019 C++ application. This took me almost one day of correcting of CMake setting. The goal of this tutorial is: compiled a set of OpenCV libraries with GStreamer and FFmpeg on Windows. I focus mainly on GStreamer. It is a little bit more tricky. You will reach the following information about your Opencv environment by compile and run this simple code. The Opencv GStreamer is turned as YES. GStreamer gives you a great opportunity to stream OpenCV output video outside of your program, for example, web application.
I recently compiled with opencv 4.4. The update at the end of the post.
using namespace cv;
std::cout << "Hello World!\n";
std::cout << cv::getBuildInformation() << std::endl;
Environment for opencv under windows compiled with extra modules and GStreamer
1) Get Opencv source. I would like to reccomand to take released version. I took Opencv 4.2 source code zip on the left and released opencv_contrib 4.2 zip on the right.
2) Get Cmake, I will recommend downloading the 3.17 release candidate 3 for 64-bit Windows. I failed with 3.16.5.
3) Extract OpenCV source into opencv-4.2.0
4) Extract OpenCV source into opencv_contrib-4.2.0
5) Extract Cmake for example into the same root folder https://cmake.org/download/
6) Create the empty build folder as you can see on the image with directories.
7) Download and install GStreamer from https://gstreamer.freedesktop.org/download/MSVC 64-bit (VS 2019), You can download and install both, but the1.16.2 development installer for MSVC 64-bit (VS 2019) is important.
The result of the installation is this directory structure. It will be linked with our Cmake configuration later on.
8) Make sure you have Visual Studio 2019 with all C++ functionality
Configure Cmake to compile Opencv with GStreamer on windows
I have a problem with this for a long time. I installed OpenCV with FFmpeg and GStreamer on Linux Debian and on Ubuntu for many times. I installed OpenCV with contribution and FFmpeg libraries on windows as well many times. The Opencv GStreamer took me almost whole weekend to let this works. It is not so difficult at all.
9) Open cmake/bin folder and start cmake-gui.exe
10)Add "where is the source code" as main /opencv-4.2.0 folder
11)Add "where to build the binaries" as new created /build folder
12) Hit configure button and select Visual Studio 2019
13) Wait for the end of configuration and ADD OENCV_EXTRA_MODULES_PATH
to point into /opencv_contrib-master/modules
14) Lesson learned Correct the path of extra modules with this /
If you use path c:\opencv_contrib-master\modules the error message when parsing string problem will occur.
15) Set all GStreamer path as follows:
Note: Some points directly to xx.lib which is important!! Some points into the header include directory.
16) Hit Configure
17) Hit Generate if the configuration is OK
18) Open project if 16- 17 are DONE
Build a Visual Studio Opencv project with GStreamer on windows
19) Change project to Release and x64
20) Right-click on whole solution and select build solution
22) installation is done, The ready to use libraries and headers are located under build/install
Visual Studio 2019 Opencv with GStreamer configuration
24) Create a new C++ console application in Visual Studio 2019
25) Change the project to x64, I am using Release configuration.
26) Open property of your project and set Additional include directory. This variable points into the include directory under install folder. (picture above)
28) Under Linker-Input -Set Additional dependencies variable- Set names of OpenCV libraries as opencv_core420.lib
29) Copy opencv_core420.dll into your project next to testOpencvGstreamer.exe or set environment variables to find your OpenCV dlls.
30) Compile the project and with the expected result
The next tutorial will be about the OpenCV GStreamer program example.
UPDATE OPENCV GStreamer
To use GStreamer you need to add path system environment variables to access GStreamer runtime as follows.