The goal of this tutorial is a simple step-by-step compilation of Opencv 4.2 with the contribution of extra modules with GStreamer as a bonus. The environment is Windows 10, Visual Studio 2019 C++ application. This took me almost one day to correct of CMake setting. The goal of this tutorial is: to compile 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 find the following information about your Opencv environment by compiling and running 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, a web application.

I recently compiled with OpenCV 4.4. The update at the end of the post.

It is working!! wow, The working app and configuration in future tutorials.

opencv on web video stream

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main()
{
    std::cout << "Hello World!\n";
    std::cout << cv::getBuildInformation() << std::endl;
    std::getchar();
}

Visual studio opencv gstreamer

Environment for opencv under Windows compiled with extra modules and GStreamer

1) Get Opencv source. I would like to recommend taking the released version. I took the Opencv 4.2 source code zip on the left and released opencv_contrib 4.2 zip on the right.

https://github.com/opencv/opencv_contrib/releases

https://github.com/opencv/opencv/releases

GitHub release pages for OpenCV 4.2.0 and opencv_contrib, showing the source archives and downloadable assets

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/

CMake download page with the Windows win64-x64 ZIP of release candidate 3.17.0-rc3 circled in red

6) Create the empty build folder as you can see on the image with directories.

Windows folder listing with build, cmake-3.17.0-rc3-win64-x64, opencv_contrib-4.2.0 and opencv-4.2.0 extracted side by side

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.

The installed GStreamer folder at C:/gstreamer/1.0/x86_64, containing bin, etc, include, lib, libexec and share

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 many times. I installed OpenCV with contribution and FFmpeg libraries on Windows as well many times. The Opencv GStreamer took me almost a whole weekend to let this work. 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

CMake GUI with the OpenCV source folder and the empty build folder filled in, arrows pointing from the Explorer window, before pressing Configure

12) Hit configure button and select Visual Studio 2019

CMake generator dialog with Visual Studio 16 2019 selected and Use default native compilers checked

13) Wait for the end of configuration and ADD OENCV_EXTRA_MODULES_PATH

to point into /opencv_contrib-master/modules

OPENCV_EXTRA_MODULES_PATH highlighted in the CMake variable list, pointing at the opencv_contrib-master modules folder

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.

CMake reporting a 'when parsing string' error because OPENCV_EXTRA_MODULES_PATH was entered with backslashes instead of forward slashes

15) Set all GStreamer paths as follows:

Note: Some points directly to xx.lib which is important!! Some points in the header include the directory.

CMake variables filtered by 'gst', showing every GSTREAMER library and include path resolved under C:/gstreamer/1.0/x86_64 and WITH_GSTREAMER ticked

CMake output with GStreamer YES (1.16.2) circled under Video I/O, next to a File Explorer window showing the GStreamer lib folder

16) Hit Configure 17) Hit Generate if the configuration is OK 18) Open project if 16- 17 are DONE

CMake finishing with Configuring done and Generating done, and the Configure, Generate and Open Project buttons marked 16, 17 and 18

Build a Visual Studio Opencv project with GStreamer on Windows

19) Change project to Release and x64

The generated OpenCV solution open in Visual Studio 2019, with Release and x64 circled in the toolbar

20) Right-click on whole solution and select build solution

Visual Studio build output ending in Build: 153 succeeded, 0 failed after building the whole OpenCV solution

21) After the solution is successfully built, install the solution by build just INSTALL in the solution

The INSTALL target selected under CMakeTargets in Visual Studio's Solution Explorer

Visual Studio installing OpenCV headers, DLLs and the haarcascade and lbpcascade XML files into build3/install

22) installation is done, The ready to use libraries and headers are located under build/install The finished build/install folder containing bin, etc, include and x64

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)

Visual Studio project properties with the OpenCV install/include folder added to Additional Include Directories

27) Under Linker- General- Additional Library Directories set- path to your install lib directory example c:\xxx\xxx\build3\install\x64\vc16\lib Visual Studio linker settings with install/x64/vc16/lib added to Additional Library Directories 28) Under Linker-Input -Set Additional dependencies variable- Set names of OpenCV libraries as opencv_core420.lib opencv_core420.lib typed into the linker's Additional Dependencies field 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 finished test program printing cv::getBuildInformation(), with GStreamer YES (1.16.2) listed under Video I/O

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.

gstreamer windows 10 opencv

Opencv GStreamer YouTube tutorial for Visual Studio

YouTube tutorial build OpenCV from source with Gstreamer on Windows

This will be a future tutorial on how to build the Opencv Gstreamer app on Windows.

Thanks for sharing: How to compile OpenCV with GStreamer on Windows Visual Studio

Opencv 4.4 Gstreamer

https://funvision.blogspot.com/2020/08/compile-opencv-4-with-cuda-and.html

gstreamer opencv 4.4